From 5dbaec8a9d46385ccfa2a79d4251c3963abcc7c3 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 18 Sep 2024 15:35:21 +0000 Subject: [PATCH 1/7] SDK binary support for executions --- README.md | 2 +- docs/examples/functions/create-deployment.md | 2 +- docs/examples/functions/create-execution.md | 2 +- docs/examples/storage/create-file.md | 2 +- lib/client_browser.dart | 2 +- lib/client_io.dart | 2 +- lib/dart_appwrite.dart | 6 +- lib/id.dart | 3 +- lib/models.dart | 2 + lib/payload.dart | 74 + lib/query.dart | 45 +- lib/role.dart | 106 +- lib/services/account.dart | 2243 ++++++++------- lib/services/avatars.dart | 404 ++- lib/services/databases.dart | 2367 ++++++++-------- lib/services/functions.dart | 1262 ++++----- lib/services/graphql.dart | 94 +- lib/services/health.dart | 929 ++++--- lib/services/locale.dart | 270 +- lib/services/messaging.dart | 2619 +++++++++--------- lib/services/storage.dart | 732 +++-- lib/services/teams.dart | 684 ++--- lib/services/users.dart | 2072 +++++++------- lib/src/client.dart | 7 +- lib/src/client_base.dart | 6 +- lib/src/client_browser.dart | 112 +- lib/src/client_io.dart | 120 +- lib/src/client_mixin.dart | 163 +- lib/src/client_stub.dart | 2 +- lib/src/enums/authentication_factor.dart | 18 +- lib/src/enums/authenticator_type.dart | 12 +- lib/src/enums/browser.dart | 38 +- lib/src/enums/compression.dart | 16 +- lib/src/enums/credit_card.dart | 42 +- lib/src/enums/execution_method.dart | 22 +- lib/src/enums/flag.dart | 400 +-- lib/src/enums/image_format.dart | 20 +- lib/src/enums/image_gravity.dart | 28 +- lib/src/enums/index_type.dart | 16 +- lib/src/enums/messaging_provider_type.dart | 16 +- lib/src/enums/name.dart | 34 +- lib/src/enums/o_auth_provider.dart | 88 +- lib/src/enums/password_hash.dart | 32 +- lib/src/enums/relation_mutate.dart | 16 +- lib/src/enums/relationship_type.dart | 18 +- lib/src/enums/runtime.dart | 105 +- lib/src/enums/smtp_encryption.dart | 16 +- lib/src/exception.dart | 2 +- lib/src/input_file.dart | 48 - lib/src/models/algo_argon2.dart | 66 +- lib/src/models/algo_bcrypt.dart | 30 +- lib/src/models/algo_md5.dart | 30 +- lib/src/models/algo_phpass.dart | 30 +- lib/src/models/algo_scrypt.dart | 84 +- lib/src/models/algo_scrypt_modified.dart | 63 +- lib/src/models/algo_sha.dart | 30 +- lib/src/models/attribute_boolean.dart | 102 +- lib/src/models/attribute_datetime.dart | 113 +- lib/src/models/attribute_email.dart | 113 +- lib/src/models/attribute_enum.dart | 124 +- lib/src/models/attribute_float.dart | 124 +- lib/src/models/attribute_integer.dart | 121 +- lib/src/models/attribute_ip.dart | 113 +- lib/src/models/attribute_list.dart | 42 +- lib/src/models/attribute_relationship.dart | 151 +- lib/src/models/attribute_string.dart | 114 +- lib/src/models/attribute_url.dart | 113 +- lib/src/models/bucket.dart | 152 +- lib/src/models/bucket_list.dart | 42 +- lib/src/models/build.dart | 120 +- lib/src/models/collection.dart | 129 +- lib/src/models/collection_list.dart | 43 +- lib/src/models/continent.dart | 41 +- lib/src/models/continent_list.dart | 43 +- lib/src/models/country.dart | 41 +- lib/src/models/country_list.dart | 43 +- lib/src/models/currency.dart | 103 +- lib/src/models/currency_list.dart | 43 +- lib/src/models/database.dart | 80 +- lib/src/models/database_list.dart | 43 +- lib/src/models/deployment.dart | 292 +- lib/src/models/deployment_list.dart | 43 +- lib/src/models/document.dart | 103 +- lib/src/models/document_list.dart | 47 +- lib/src/models/execution.dart | 215 +- lib/src/models/execution_list.dart | 43 +- lib/src/models/file.dart | 143 +- lib/src/models/file_list.dart | 42 +- lib/src/models/function.dart | 290 +- lib/src/models/function_list.dart | 42 +- lib/src/models/headers.dart | 41 +- lib/src/models/health_antivirus.dart | 41 +- lib/src/models/health_certificate.dart | 91 +- lib/src/models/health_queue.dart | 31 +- lib/src/models/health_status.dart | 53 +- lib/src/models/health_time.dart | 55 +- lib/src/models/identity.dart | 129 +- lib/src/models/identity_list.dart | 43 +- lib/src/models/index.dart | 91 +- lib/src/models/index_list.dart | 42 +- lib/src/models/jwt.dart | 30 +- lib/src/models/language.dart | 52 +- lib/src/models/language_list.dart | 43 +- lib/src/models/locale.dart | 102 +- lib/src/models/locale_code.dart | 41 +- lib/src/models/locale_code_list.dart | 43 +- lib/src/models/log.dart | 256 +- lib/src/models/log_list.dart | 42 +- lib/src/models/membership.dart | 168 +- lib/src/models/membership_list.dart | 43 +- lib/src/models/message.dart | 169 +- lib/src/models/message_list.dart | 43 +- lib/src/models/mfa_challenge.dart | 63 +- lib/src/models/mfa_factors.dart | 63 +- lib/src/models/mfa_recovery_codes.dart | 30 +- lib/src/models/mfa_type.dart | 41 +- lib/src/models/model.dart | 2 +- lib/src/models/phone.dart | 52 +- lib/src/models/phone_list.dart | 42 +- lib/src/models/preferences.dart | 30 +- lib/src/models/provider.dart | 124 +- lib/src/models/provider_list.dart | 43 +- lib/src/models/runtime.dart | 113 +- lib/src/models/runtime_list.dart | 43 +- lib/src/models/session.dart | 344 ++- lib/src/models/session_list.dart | 43 +- lib/src/models/specification.dart | 64 +- lib/src/models/specification_list.dart | 43 +- lib/src/models/subscriber.dart | 124 +- lib/src/models/subscriber_list.dart | 43 +- lib/src/models/target.dart | 113 +- lib/src/models/target_list.dart | 42 +- lib/src/models/team.dart | 92 +- lib/src/models/team_list.dart | 42 +- lib/src/models/token.dart | 91 +- lib/src/models/topic.dart | 116 +- lib/src/models/topic_list.dart | 42 +- lib/src/models/user.dart | 234 +- lib/src/models/user_list.dart | 42 +- lib/src/models/variable.dart | 102 +- lib/src/models/variable_list.dart | 43 +- pubspec.yaml | 7 +- test/services/functions_test.dart | 10 +- test/services/storage_test.dart | 2 +- test/src/input_file_test.dart | 47 - test/src/payload_test.dart | 23 + 146 files changed, 11364 insertions(+), 11707 deletions(-) create mode 100644 lib/payload.dart delete mode 100644 lib/src/input_file.dart delete mode 100644 test/src/input_file_test.dart create mode 100644 test/src/payload_test.dart diff --git a/README.md b/README.md index f83d6589..770c67fa 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Add this to your package's `pubspec.yaml` file: ```yml dependencies: - dart_appwrite: ^12.1.0 + dart_appwrite: ^13.0.0-rc1 ``` You can install packages from the command line: diff --git a/docs/examples/functions/create-deployment.md b/docs/examples/functions/create-deployment.md index 297bdc61..80f14165 100644 --- a/docs/examples/functions/create-deployment.md +++ b/docs/examples/functions/create-deployment.md @@ -10,7 +10,7 @@ Functions functions = Functions(client); Deployment result = await functions.createDeployment( functionId: '', - code: InputFile(path: './path-to-files/image.jpg', filename: 'image.jpg'), + code: Payload.fromFile(path: '/path/to/file.png'), activate: false, entrypoint: '', // (optional) commands: '', // (optional) diff --git a/docs/examples/functions/create-execution.md b/docs/examples/functions/create-execution.md index 2bf146e2..3246f98d 100644 --- a/docs/examples/functions/create-execution.md +++ b/docs/examples/functions/create-execution.md @@ -9,7 +9,7 @@ Functions functions = Functions(client); Execution result = await functions.createExecution( functionId: '', - body: '', // (optional) + body: Payload.fromJson({ 'x': 'y' }), // (optional) xasync: false, // (optional) path: '', // (optional) method: ExecutionMethod.gET, // (optional) diff --git a/docs/examples/storage/create-file.md b/docs/examples/storage/create-file.md index 0e06f422..0378a5c8 100644 --- a/docs/examples/storage/create-file.md +++ b/docs/examples/storage/create-file.md @@ -11,6 +11,6 @@ Storage storage = Storage(client); File result = await storage.createFile( bucketId: '', fileId: '', - file: InputFile(path: './path-to-files/image.jpg', filename: 'image.jpg'), + file: Payload.fromFile(path: '/path/to/file.png'), permissions: ["read("any")"], // (optional) ); diff --git a/lib/client_browser.dart b/lib/client_browser.dart index b9805a3a..09f110ea 100644 --- a/lib/client_browser.dart +++ b/lib/client_browser.dart @@ -1 +1 @@ -export 'src/client_browser.dart'; +export 'src/client_browser.dart'; \ No newline at end of file diff --git a/lib/client_io.dart b/lib/client_io.dart index 42a0c0b6..4d85cbfa 100644 --- a/lib/client_io.dart +++ b/lib/client_io.dart @@ -1 +1 @@ -export 'src/client_io.dart'; +export 'src/client_io.dart'; \ No newline at end of file diff --git a/lib/dart_appwrite.dart b/lib/dart_appwrite.dart index 26412fe3..659eb962 100644 --- a/lib/dart_appwrite.dart +++ b/lib/dart_appwrite.dart @@ -1,6 +1,6 @@ /// Appwrite Dart SDK /// -/// This SDK is compatible with Appwrite server version 1.6.x. +/// This SDK is compatible with Appwrite server version 1.6.x. /// For older versions, please check /// [previous releases](https://github.com/appwrite/sdk-for-dart/releases). library dart_appwrite; @@ -12,16 +12,16 @@ import 'dart:convert'; import 'src/enums.dart'; import 'src/service.dart'; -import 'src/input_file.dart'; import 'src/upload_progress.dart'; import 'models.dart' as models; import 'enums.dart' as enums; +import 'payload.dart'; export 'src/response.dart'; export 'src/client.dart'; export 'src/exception.dart'; -export 'src/input_file.dart'; export 'src/upload_progress.dart'; +export 'payload.dart'; part 'query.dart'; part 'permission.dart'; diff --git a/lib/id.dart b/lib/id.dart index 28ff15e8..72e26a23 100644 --- a/lib/id.dart +++ b/lib/id.dart @@ -10,7 +10,8 @@ class ID { final now = DateTime.now(); final sec = (now.millisecondsSinceEpoch / 1000).floor(); final usec = now.microsecondsSinceEpoch - (sec * 1000000); - return sec.toRadixString(16) + usec.toRadixString(16).padLeft(5, '0'); + return sec.toRadixString(16) + + usec.toRadixString(16).padLeft(5, '0'); } // Generate a unique ID with padding to have a longer ID diff --git a/lib/models.dart b/lib/models.dart index 98fd7d19..7338435e 100644 --- a/lib/models.dart +++ b/lib/models.dart @@ -1,6 +1,8 @@ /// Appwrite Models library dart_appwrite.models; +import 'payload.dart'; + part 'src/models/model.dart'; part 'src/models/document_list.dart'; part 'src/models/collection_list.dart'; diff --git a/lib/payload.dart b/lib/payload.dart new file mode 100644 index 00000000..5dc144c9 --- /dev/null +++ b/lib/payload.dart @@ -0,0 +1,74 @@ +import 'dart:convert'; +import 'src/exception.dart'; + +class Payload { + late final String? path; + late final List? data; + final String? filename; + + Payload._({this.path, this.filename, this.data}) { + if (path == null && data == null) { + throw AppwriteException('One of `path` or `data` is required'); + } + } + + /// Convert to binary, with optional offset and length + List toBinary({int offset = 0, int? length}) { + if(data == null) { + throw AppwriteException('`data` is not defined.'); + } + if(offset == 0 && length == null) { + return data!; + } else if (length == null) { + return data!.sublist(offset); + } else { + return data!.sublist(offset, offset + length); + } + } + + /// Convert binary data to string (utf8) + @override + String toString() { + if(data == null) { + return ''; + } + return utf8.decode(data!); + } + + /// Convert binary data to JSON object + Map toJson() { + try { + return jsonDecode(toString()); // Decode the string to JSON + } catch (e) { + throw FormatException('Failed to parse JSON: ${e.toString()}'); + } + } + + /// Create a Payload from binary data + factory Payload.fromBinary({ + required List data, + String? filename, + }) { + return Payload._(data: data, filename: filename); + } + + /// Create a Payload from a file + factory Payload.fromFile({required String path, String? filename}) { + return Payload._(path: path, filename: filename); + } + + /// Create a Payload from a JSON object + factory Payload.fromJson({ + required Map data, + String? filename, + }) { + final jsonString = jsonEncode(data); + return Payload.fromString(string: jsonString, filename: filename); + } + + /// Create a Payload from a string + factory Payload.fromString({required String string, String? filename}) { + final data = utf8.encode(string); + return Payload._(data: data, filename: filename); + } +} diff --git a/lib/query.dart b/lib/query.dart index 6b8ed94f..46882207 100644 --- a/lib/query.dart +++ b/lib/query.dart @@ -1,5 +1,6 @@ part of 'dart_appwrite.dart'; + /// Helper class to generate query strings. class Query { final String method; @@ -13,11 +14,11 @@ class Query { 'method': method, }; - if (attribute != null) { + if(attribute != null) { map['attribute'] = attribute; } - - if (values != null) { + + if(values != null) { map['values'] = values is List ? values : [values]; } @@ -28,7 +29,7 @@ class Query { String toString() => jsonEncode(toJson()); /// Filter resources where [attribute] is equal to [value]. - /// + /// /// [value] can be a single value or a list. If a list is used /// the query will return resources where [attribute] is equal /// to any of the values in the list. @@ -60,12 +61,10 @@ class Query { Query._('search', attribute, value).toString(); /// Filter resources where [attribute] is null. - static String isNull(String attribute) => - Query._('isNull', attribute).toString(); + static String isNull(String attribute) => Query._('isNull', attribute).toString(); /// Filter resources where [attribute] is not null. - static String isNotNull(String attribute) => - Query._('isNotNull', attribute).toString(); + static String isNotNull(String attribute) => Query._('isNotNull', attribute).toString(); /// Filter resources where [attribute] is between [start] and [end] (inclusive). static String between(String attribute, dynamic start, dynamic end) => @@ -85,46 +84,40 @@ class Query { Query._('contains', attribute, value).toString(); static String or(List queries) => - Query._('or', null, queries.map((query) => jsonDecode(query)).toList()) - .toString(); + Query._('or', null, queries.map((query) => jsonDecode(query)).toList()).toString(); static String and(List queries) => - Query._('and', null, queries.map((query) => jsonDecode(query)).toList()) - .toString(); + Query._('and', null, queries.map((query) => jsonDecode(query)).toList()).toString(); /// Specify which attributes should be returned by the API call. static String select(List attributes) => Query._('select', null, attributes).toString(); /// Sort results by [attribute] ascending. - static String orderAsc(String attribute) => - Query._('orderAsc', attribute).toString(); + static String orderAsc(String attribute) => Query._('orderAsc', attribute).toString(); /// Sort results by [attribute] descending. - static String orderDesc(String attribute) => - Query._('orderDesc', attribute).toString(); + static String orderDesc(String attribute) => Query._('orderDesc', attribute).toString(); /// Return results before [id]. - /// + /// /// Refer to the [Cursor Based Pagination](https://appwrite.io/docs/pagination#cursor-pagination) /// docs for more information. - static String cursorBefore(String id) => - Query._('cursorBefore', null, id).toString(); + static String cursorBefore(String id) => Query._('cursorBefore', null, id).toString(); /// Return results after [id]. - /// + /// /// Refer to the [Cursor Based Pagination](https://appwrite.io/docs/pagination#cursor-pagination) /// docs for more information. - static String cursorAfter(String id) => - Query._('cursorAfter', null, id).toString(); + static String cursorAfter(String id) => Query._('cursorAfter', null, id).toString(); /// Return only [limit] results. static String limit(int limit) => Query._('limit', null, limit).toString(); /// Return results from [offset]. - /// + /// /// Refer to the [Offset Pagination](https://appwrite.io/docs/pagination#offset-pagination) /// docs for more information. - static String offset(int offset) => - Query._('offset', null, offset).toString(); -} + static String offset(int offset) => Query._('offset', null, offset).toString(); + +} \ No newline at end of file diff --git a/lib/role.dart b/lib/role.dart index dafeb78d..6552df47 100644 --- a/lib/role.dart +++ b/lib/role.dart @@ -2,65 +2,65 @@ part of 'dart_appwrite.dart'; /// Helper class to generate role strings for [Permission]. class Role { - Role._(); - - /// Grants access to anyone. - /// - /// This includes authenticated and unauthenticated users. - static String any() { - return 'any'; - } + Role._(); + + /// Grants access to anyone. + /// + /// This includes authenticated and unauthenticated users. + static String any() { + return 'any'; + } - /// Grants access to a specific user by user ID. - /// - /// You can optionally pass verified or unverified for - /// [status] to target specific types of users. - static String user(String id, [String status = '']) { - if (status.isEmpty) { - return 'user:$id'; + /// Grants access to a specific user by user ID. + /// + /// You can optionally pass verified or unverified for + /// [status] to target specific types of users. + static String user(String id, [String status = '']) { + if(status.isEmpty) { + return 'user:$id'; + } + return 'user:$id/$status'; } - return 'user:$id/$status'; - } - /// Grants access to any authenticated or anonymous user. - /// - /// You can optionally pass verified or unverified for - /// [status] to target specific types of users. - static String users([String status = '']) { - if (status.isEmpty) { - return 'users'; + /// Grants access to any authenticated or anonymous user. + /// + /// You can optionally pass verified or unverified for + /// [status] to target specific types of users. + static String users([String status = '']) { + if(status.isEmpty) { + return 'users'; + } + return 'users/$status'; } - return 'users/$status'; - } - /// Grants access to any guest user without a session. - /// - /// Authenticated users don't have access to this role. - static String guests() { - return 'guests'; - } + /// Grants access to any guest user without a session. + /// + /// Authenticated users don't have access to this role. + static String guests() { + return 'guests'; + } - /// Grants access to a team by team ID. - /// - /// You can optionally pass a role for [role] to target - /// team members with the specified role. - static String team(String id, [String role = '']) { - if (role.isEmpty) { - return 'team:$id'; + /// Grants access to a team by team ID. + /// + /// You can optionally pass a role for [role] to target + /// team members with the specified role. + static String team(String id, [String role = '']) { + if(role.isEmpty) { + return 'team:$id'; + } + return 'team:$id/$role'; } - return 'team:$id/$role'; - } - /// Grants access to a specific member of a team. - /// - /// When the member is removed from the team, they will - /// no longer have access. - static String member(String id) { - return 'member:$id'; - } + /// Grants access to a specific member of a team. + /// + /// When the member is removed from the team, they will + /// no longer have access. + static String member(String id) { + return 'member:$id'; + } - /// Grants access to a user with the specified label. - static String label(String name) { - return 'label:$name'; - } -} + /// Grants access to a user with the specified label. + static String label(String name) { + return 'label:$name'; + } +} \ No newline at end of file diff --git a/lib/services/account.dart b/lib/services/account.dart index 6e4936cd..93c16e2d 100644 --- a/lib/services/account.dart +++ b/lib/services/account.dart @@ -2,1072 +2,1177 @@ part of '../dart_appwrite.dart'; /// The Account service allows you to authenticate and manage a user account. class Account extends Service { - Account(super.client); - - /// Get account - /// - /// Get the currently logged in user. - Future get() async { - final String apiPath = '/account'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.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](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession). - Future create( - {required String userId, - required String email, - required String password, - String? name}) async { - final String apiPath = '/account'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update 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 { - final String apiPath = '/account/email'; - - final Map apiParams = { - 'email': email, - 'password': password, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// List Identities - /// - /// Get the list of identities for the currently logged in user. - Future listIdentities({List? queries}) async { - final String apiPath = '/account/identities'; - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.IdentityList.fromMap(res.data); - } - - /// Delete identity - /// - /// Delete an identity by its unique ID. - Future deleteIdentity({required String identityId}) async { - final String apiPath = '/account/identities/{identityId}' - .replaceAll('{identityId}', identityId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Create 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 { - final String apiPath = '/account/jwts'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Jwt.fromMap(res.data); - } - - /// List logs - /// - /// Get the list of latest security activity logs for the currently logged in - /// user. Each log returns user IP address, location and date and time of log. - Future listLogs({List? queries}) async { - final String apiPath = '/account/logs'; - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// Update MFA - /// - /// Enable or disable MFA on an account. - Future updateMFA({required bool mfa}) async { - final String apiPath = '/account/mfa'; - - final Map apiParams = { - 'mfa': mfa, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create Authenticator - /// - /// Add an authenticator app to be used as an MFA factor. Verify the - /// authenticator using the [verify - /// authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) - /// method. - Future createMfaAuthenticator( - {required enums.AuthenticatorType type}) async { - final String apiPath = - '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaType.fromMap(res.data); - } - - /// Verify Authenticator - /// - /// Verify an authenticator app after adding it using the [add - /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) - /// method. - Future updateMfaAuthenticator( - {required enums.AuthenticatorType type, required String otp}) async { - final String apiPath = - '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); - - final Map apiParams = { - 'otp': otp, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Delete Authenticator - /// - /// Delete an authenticator for a user by ID. - Future deleteMfaAuthenticator({required enums.AuthenticatorType type}) async { - final String apiPath = - '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Create MFA Challenge - /// - /// Begin the process of MFA verification after sign-in. Finish the flow with - /// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) - /// method. - Future createMfaChallenge( - {required enums.AuthenticationFactor factor}) async { - final String apiPath = '/account/mfa/challenge'; - - final Map apiParams = { - 'factor': factor.value, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaChallenge.fromMap(res.data); - } - - /// Create MFA Challenge (confirmation) - /// - /// Complete the MFA challenge by providing the one-time password. Finish the - /// process of MFA verification by providing the one-time password. To begin - /// the flow, use - /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) - /// method. - Future updateMfaChallenge( - {required String challengeId, required String otp}) async { - final String apiPath = '/account/mfa/challenge'; - - final Map apiParams = { - 'challengeId': challengeId, - 'otp': otp, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List Factors - /// - /// List the factors available on the account to be used as a MFA challange. - Future listMfaFactors() async { - final String apiPath = '/account/mfa/factors'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaFactors.fromMap(res.data); - } - - /// Get MFA Recovery Codes - /// - /// Get recovery codes that can be used as backup for MFA flow. Before getting - /// codes, they must be generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. An OTP challenge is required to read recovery codes. - Future getMfaRecoveryCodes() async { - final String apiPath = '/account/mfa/recovery-codes'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Create MFA Recovery Codes - /// - /// Generate recovery codes as backup for MFA flow. It's recommended to - /// generate and show then immediately after user successfully adds their - /// authehticator. Recovery codes can be used as a MFA verification type in - /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) - /// method. - Future createMfaRecoveryCodes() async { - final String apiPath = '/account/mfa/recovery-codes'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Regenerate MFA Recovery Codes - /// - /// Regenerate recovery codes that can be used as backup for MFA flow. Before - /// regenerating codes, they must be first generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. An OTP challenge is required to regenreate recovery codes. - Future updateMfaRecoveryCodes() async { - final String apiPath = '/account/mfa/recovery-codes'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Update name - /// - /// Update currently logged in user account name. - Future updateName({required String name}) async { - final String apiPath = '/account/name'; - - final Map apiParams = { - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update 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 { - final String apiPath = '/account/password'; - - final Map apiParams = { - 'password': password, - 'oldPassword': oldPassword, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update 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](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification) - /// endpoint to send a confirmation SMS. - Future updatePhone( - {required String phone, required String password}) async { - final String apiPath = '/account/phone'; - - final Map apiParams = { - 'phone': phone, - 'password': password, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Get account preferences - /// - /// Get the preferences as a key-value object for the currently logged in user. - Future getPrefs() async { - final String apiPath = '/account/prefs'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - } - - /// Update 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 { - final String apiPath = '/account/prefs'; - - final Map apiParams = { - 'prefs': prefs, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery) - /// 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 { - final String apiPath = '/account/recovery'; - - final Map apiParams = { - 'email': email, - 'url': url, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Create 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](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery) - /// 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}) async { - final String apiPath = '/account/recovery'; - - final Map apiParams = { - 'userId': userId, - 'secret': secret, - 'password': password, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// List sessions - /// - /// Get the list of active sessions across different devices for the currently - /// logged in user. - Future listSessions() async { - final String apiPath = '/account/sessions'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SessionList.fromMap(res.data); - } - - /// Delete sessions - /// - /// Delete all sessions from the user account and remove any sessions cookies - /// from the end client. - Future deleteSessions() async { - final String apiPath = '/account/sessions'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Create 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](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail) - /// or create an [OAuth2 - /// session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session). - Future createAnonymousSession() async { - final String apiPath = '/account/sessions/anonymous'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Create email password session - /// - /// Allow the user to login into their account by providing a valid email and - /// password combination. This route will create a new session for the user. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future createEmailPasswordSession( - {required String email, required String password}) async { - final String apiPath = '/account/sessions/email'; - - final Map apiParams = { - 'email': email, - 'password': password, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Update magic URL session - /// - /// Use this endpoint to create a session from token. Provide the **userId** - /// and **secret** parameters from the successful response of authentication - /// flows initiated by token creation. For example, magic URL and phone login. - Future updateMagicURLSession( - {required String userId, required String secret}) async { - final String apiPath = '/account/sessions/magic-url'; - - final Map apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Update phone session - /// - /// Use this endpoint to create a session from token. Provide the **userId** - /// and **secret** parameters from the successful response of authentication - /// flows initiated by token creation. For example, magic URL and phone login. - Future updatePhoneSession( - {required String userId, required String secret}) async { - final String apiPath = '/account/sessions/phone'; - - final Map apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Create session - /// - /// Use this endpoint to create a session from token. Provide the **userId** - /// and **secret** parameters from the successful response of authentication - /// flows initiated by token creation. For example, magic URL and phone login. - Future createSession( - {required String userId, required String secret}) async { - final String apiPath = '/account/sessions/token'; - - final Map apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Get session - /// - /// 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 apiPath = - '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Update session - /// - /// Use this endpoint to extend a session's length. Extending a session is - /// useful when session expiry is short. If the session was created using an - /// OAuth provider, this endpoint refreshes the access token from the provider. - Future updateSession({required String sessionId}) async { - final String apiPath = - '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Delete session - /// - /// Logout the user. Use 'current' as the session ID to logout on this device, - /// use a session ID to logout on another device. If you're looking to logout - /// the user on all devices, use [Delete - /// Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions) - /// instead. - Future deleteSession({required String sessionId}) async { - final String apiPath = - '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Update 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 { - final String apiPath = '/account/status'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create email token (OTP) - /// - /// Sends the user an email with a secret key for creating a session. If the - /// provided user ID has not be registered, a new user will be created. Use the - /// returned user ID and secret and submit a request to the [POST - /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. The secret sent to the user's email - /// is valid for 15 minutes. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future createEmailToken( - {required String userId, required String email, bool? phrase}) async { - final String apiPath = '/account/tokens/email'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'phrase': phrase, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Create magic URL token - /// - /// Sends the user an email with a secret key for creating a session. If the - /// provided user ID has not been registered, a new user will be created. When - /// the user clicks the link in the email, the user is redirected back to the - /// URL you provided with the secret key and userId values attached to the URL - /// query string. Use the query string parameters to submit a request to the - /// [POST - /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. The link sent to the user's email - /// address is valid for 1 hour. If you are on a mobile device you can leave - /// the URL parameter empty, so that the login completion will be handled by - /// your Appwrite instance by default. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - /// - Future createMagicURLToken( - {required String userId, - required String email, - String? url, - bool? phrase}) async { - final String apiPath = '/account/tokens/magic-url'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'url': url, - 'phrase': phrase, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Create OAuth2 token - /// - /// Allow the user to login to their account using the OAuth2 provider of their - /// choice. Each OAuth2 provider should be enabled from the Appwrite console - /// first. Use the success and failure arguments to provide a redirect URL's - /// back to your app when login is completed. - /// - /// If authentication succeeds, `userId` and `secret` of a token will be - /// appended to the success URL as query parameters. These can be used to - /// create a new session using the [Create - /// session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future createOAuth2Token( - {required enums.OAuthProvider provider, - String? success, - String? failure, - List? scopes}) async { - final String apiPath = '/account/tokens/oauth2/{provider}' - .replaceAll('{provider}', provider.value); - - final Map params = { - 'success': success, - 'failure': failure, - 'scopes': scopes, - 'project': client.config['project'], - }; - - final List query = []; - - params.forEach((key, value) { - if (value is List) { - for (var item in value) { - query.add(Uri.encodeComponent(key + '[]') + - '=' + - Uri.encodeComponent(item)); - } - } else if (value != null) { - query.add(Uri.encodeComponent(key) + '=' + Uri.encodeComponent(value)); - } - }); - - Uri endpoint = Uri.parse(client.endPoint); - Uri url = Uri( - scheme: endpoint.scheme, - host: endpoint.host, - port: endpoint.port, - path: endpoint.path + apiPath, - query: query.join('&')); - - return client.webAuth(url); - } - - /// Create phone token - /// - /// Sends the user an SMS with a secret key for creating a session. If the - /// provided user ID has not be registered, a new user will be created. Use the - /// returned user ID and secret and submit a request to the [POST - /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. The secret sent to the user's phone - /// is valid for 15 minutes. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future createPhoneToken( - {required String userId, required String phone}) async { - final String apiPath = '/account/tokens/phone'; - - final Map apiParams = { - 'userId': userId, - 'phone': phone, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Create email verification - /// - /// Use this endpoint to send a verification message to your user email address - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). - /// 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 { - final String apiPath = '/account/verification'; - - final Map apiParams = { - 'url': url, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Create 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 { - final String apiPath = '/account/verification'; - - final Map apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone) - /// endpoint. Learn more about how to [complete the verification - /// process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification). - /// The verification code sent to the user's phone number is valid for 15 - /// minutes. - Future createPhoneVerification() async { - final String apiPath = '/account/verification/phone'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Update 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 { - final String apiPath = '/account/verification/phone'; - - final Map apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } -} + Account(super.client); + + /// Get account + /// + /// Get the currently logged in user. + Future get() async { + final String apiPath = '/account'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.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](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession). + Future create({required String userId, required String email, required String password, String? name}) async { + final String apiPath = '/account'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update 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 { + final String apiPath = '/account/email'; + + final Map apiParams = { + + 'email': email, +'password': password, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// List Identities + /// + /// Get the list of identities for the currently logged in user. + Future listIdentities({List? queries}) async { + final String apiPath = '/account/identities'; + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.IdentityList.fromMap(res.data); + + } + + /// Delete identity + /// + /// Delete an identity by its unique ID. + Future deleteIdentity({required String identityId}) async { + final String apiPath = '/account/identities/{identityId}'.replaceAll('{identityId}', identityId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Create 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 { + final String apiPath = '/account/jwts'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Jwt.fromMap(res.data); + + } + + /// List logs + /// + /// Get the list of latest security activity logs for the currently logged in + /// user. Each log returns user IP address, location and date and time of log. + Future listLogs({List? queries}) async { + final String apiPath = '/account/logs'; + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// Update MFA + /// + /// Enable or disable MFA on an account. + Future updateMFA({required bool mfa}) async { + final String apiPath = '/account/mfa'; + + final Map apiParams = { + + 'mfa': mfa, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create Authenticator + /// + /// Add an authenticator app to be used as an MFA factor. Verify the + /// authenticator using the [verify + /// authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) + /// method. + Future createMfaAuthenticator({required enums.AuthenticatorType type}) async { + final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaType.fromMap(res.data); + + } + + /// Verify Authenticator + /// + /// Verify an authenticator app after adding it using the [add + /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) + /// method. + Future updateMfaAuthenticator({required enums.AuthenticatorType type, required String otp}) async { + final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map apiParams = { + + 'otp': otp, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Delete Authenticator + /// + /// Delete an authenticator for a user by ID. + Future deleteMfaAuthenticator({required enums.AuthenticatorType type}) async { + final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Create MFA Challenge + /// + /// Begin the process of MFA verification after sign-in. Finish the flow with + /// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) + /// method. + Future createMfaChallenge({required enums.AuthenticationFactor factor}) async { + final String apiPath = '/account/mfa/challenge'; + + final Map apiParams = { + + 'factor': factor.value, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaChallenge.fromMap(res.data); + + } + + /// Create MFA Challenge (confirmation) + /// + /// Complete the MFA challenge by providing the one-time password. Finish the + /// process of MFA verification by providing the one-time password. To begin + /// the flow, use + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method. + Future updateMfaChallenge({required String challengeId, required String otp}) async { + final String apiPath = '/account/mfa/challenge'; + + final Map apiParams = { + + 'challengeId': challengeId, +'otp': otp, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List Factors + /// + /// List the factors available on the account to be used as a MFA challange. + Future listMfaFactors() async { + final String apiPath = '/account/mfa/factors'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaFactors.fromMap(res.data); + + } + + /// Get MFA Recovery Codes + /// + /// Get recovery codes that can be used as backup for MFA flow. Before getting + /// codes, they must be generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. An OTP challenge is required to read recovery codes. + Future getMfaRecoveryCodes() async { + final String apiPath = '/account/mfa/recovery-codes'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Create MFA Recovery Codes + /// + /// Generate recovery codes as backup for MFA flow. It's recommended to + /// generate and show then immediately after user successfully adds their + /// authehticator. Recovery codes can be used as a MFA verification type in + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method. + Future createMfaRecoveryCodes() async { + final String apiPath = '/account/mfa/recovery-codes'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Regenerate MFA Recovery Codes + /// + /// Regenerate recovery codes that can be used as backup for MFA flow. Before + /// regenerating codes, they must be first generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. An OTP challenge is required to regenreate recovery codes. + Future updateMfaRecoveryCodes() async { + final String apiPath = '/account/mfa/recovery-codes'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Update name + /// + /// Update currently logged in user account name. + Future updateName({required String name}) async { + final String apiPath = '/account/name'; + + final Map apiParams = { + + 'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update 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 { + final String apiPath = '/account/password'; + + final Map apiParams = { + + 'password': password, +'oldPassword': oldPassword, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update 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](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification) + /// endpoint to send a confirmation SMS. + Future updatePhone({required String phone, required String password}) async { + final String apiPath = '/account/phone'; + + final Map apiParams = { + + 'phone': phone, +'password': password, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Get account preferences + /// + /// Get the preferences as a key-value object for the currently logged in user. + Future getPrefs() async { + final String apiPath = '/account/prefs'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + + } + + /// Update 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 { + final String apiPath = '/account/prefs'; + + final Map apiParams = { + + 'prefs': prefs, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery) + /// 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 { + final String apiPath = '/account/recovery'; + + final Map apiParams = { + + 'email': email, +'url': url, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Create 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](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery) + /// 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}) async { + final String apiPath = '/account/recovery'; + + final Map apiParams = { + + 'userId': userId, +'secret': secret, +'password': password, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// List sessions + /// + /// Get the list of active sessions across different devices for the currently + /// logged in user. + Future listSessions() async { + final String apiPath = '/account/sessions'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SessionList.fromMap(res.data); + + } + + /// Delete sessions + /// + /// Delete all sessions from the user account and remove any sessions cookies + /// from the end client. + Future deleteSessions() async { + final String apiPath = '/account/sessions'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Create 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](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail) + /// or create an [OAuth2 + /// session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session). + Future createAnonymousSession() async { + final String apiPath = '/account/sessions/anonymous'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Create email password session + /// + /// Allow the user to login into their account by providing a valid email and + /// password combination. This route will create a new session for the user. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future createEmailPasswordSession({required String email, required String password}) async { + final String apiPath = '/account/sessions/email'; + + final Map apiParams = { + + 'email': email, +'password': password, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Update magic URL session + /// + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. + Future updateMagicURLSession({required String userId, required String secret}) async { + final String apiPath = '/account/sessions/magic-url'; + + final Map apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Update phone session + /// + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. + Future updatePhoneSession({required String userId, required String secret}) async { + final String apiPath = '/account/sessions/phone'; + + final Map apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Create session + /// + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. + Future createSession({required String userId, required String secret}) async { + final String apiPath = '/account/sessions/token'; + + final Map apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Get session + /// + /// 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 apiPath = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Update session + /// + /// Use this endpoint to extend a session's length. Extending a session is + /// useful when session expiry is short. If the session was created using an + /// OAuth provider, this endpoint refreshes the access token from the provider. + Future updateSession({required String sessionId}) async { + final String apiPath = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Delete session + /// + /// Logout the user. Use 'current' as the session ID to logout on this device, + /// use a session ID to logout on another device. If you're looking to logout + /// the user on all devices, use [Delete + /// Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions) + /// instead. + Future deleteSession({required String sessionId}) async { + final String apiPath = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Update 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 { + final String apiPath = '/account/status'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create email token (OTP) + /// + /// Sends the user an email with a secret key for creating a session. If the + /// provided user ID has not be registered, a new user will be created. Use the + /// returned user ID and secret and submit a request to the [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The secret sent to the user's email + /// is valid for 15 minutes. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future createEmailToken({required String userId, required String email, bool? phrase}) async { + final String apiPath = '/account/tokens/email'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'phrase': phrase, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Create magic URL token + /// + /// Sends the user an email with a secret key for creating a session. If the + /// provided user ID has not been registered, a new user will be created. When + /// the user clicks the link in the email, the user is redirected back to the + /// URL you provided with the secret key and userId values attached to the URL + /// query string. Use the query string parameters to submit a request to the + /// [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The link sent to the user's email + /// address is valid for 1 hour. If you are on a mobile device you can leave + /// the URL parameter empty, so that the login completion will be handled by + /// your Appwrite instance by default. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + /// + Future createMagicURLToken({required String userId, required String email, String? url, bool? phrase}) async { + final String apiPath = '/account/tokens/magic-url'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'url': url, +'phrase': phrase, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Create OAuth2 token + /// + /// Allow the user to login to their account using the OAuth2 provider of their + /// choice. Each OAuth2 provider should be enabled from the Appwrite console + /// first. Use the success and failure arguments to provide a redirect URL's + /// back to your app when login is completed. + /// + /// If authentication succeeds, `userId` and `secret` of a token will be + /// appended to the success URL as query parameters. These can be used to + /// create a new session using the [Create + /// session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future createOAuth2Token({required enums.OAuthProvider provider, String? success, String? failure, List? scopes}) async { + final String apiPath = '/account/tokens/oauth2/{provider}'.replaceAll('{provider}', provider.value); + + final Map params = { + 'success': success, +'failure': failure, +'scopes': scopes, + + + 'project': client.config['project'], + }; + + final List query = []; + + params.forEach((key, value) { + if (value is List) { + for (var item in value) { + query.add(Uri.encodeComponent(key + '[]') + '=' + Uri.encodeComponent(item)); + } + } else if(value != null) { + query.add(Uri.encodeComponent(key) + '=' + Uri.encodeComponent(value)); + } + }); + + Uri endpoint = Uri.parse(client.endPoint); + Uri url = Uri(scheme: endpoint.scheme, + host: endpoint.host, + port: endpoint.port, + path: endpoint.path + apiPath, + query: query.join('&') + ); + + return client.webAuth(url); + } + + /// Create phone token + /// + /// Sends the user an SMS with a secret key for creating a session. If the + /// provided user ID has not be registered, a new user will be created. Use the + /// returned user ID and secret and submit a request to the [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The secret sent to the user's phone + /// is valid for 15 minutes. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future createPhoneToken({required String userId, required String phone}) async { + final String apiPath = '/account/tokens/phone'; + + final Map apiParams = { + + 'userId': userId, +'phone': phone, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Create email verification + /// + /// Use this endpoint to send a verification message to your user email address + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). + /// 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 { + final String apiPath = '/account/verification'; + + final Map apiParams = { + + 'url': url, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Create 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 { + final String apiPath = '/account/verification'; + + final Map apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone) + /// endpoint. Learn more about how to [complete the verification + /// process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification). + /// The verification code sent to the user's phone number is valid for 15 + /// minutes. + Future createPhoneVerification() async { + final String apiPath = '/account/verification/phone'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Update 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 { + final String apiPath = '/account/verification/phone'; + + final Map apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 9c77eda6..4609b00b 100644 --- a/lib/services/avatars.dart +++ b/lib/services/avatars.dart @@ -3,209 +3,201 @@ part of '../dart_appwrite.dart'; /// The Avatars service aims to help you complete everyday tasks related to /// your app image, icons, and avatars. class Avatars extends Service { - Avatars(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](https://appwrite.io/docs/references/cloud/client-web/account#getSessions) - /// 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 enums.Browser code, - int? width, - int? height, - int? quality}) async { - final String apiPath = - '/avatars/browsers/{code}'.replaceAll('{code}', code.value); - - final Map params = { - 'width': width, - 'height': height, - 'quality': quality, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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 enums.CreditCard code, - int? width, - int? height, - int? quality}) async { - final String apiPath = - '/avatars/credit-cards/{code}'.replaceAll('{code}', code.value); - - final Map params = { - 'width': width, - 'height': height, - 'quality': quality, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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. - /// - /// This endpoint does not follow HTTP redirects. - Future getFavicon({required String url}) async { - final String apiPath = '/avatars/favicon'; - - final Map params = { - 'url': url, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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. Country codes - /// follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard. - /// - /// 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 enums.Flag code, int? width, int? height, int? quality}) async { - final String apiPath = - '/avatars/flags/{code}'.replaceAll('{code}', code.value); - - final Map params = { - 'width': width, - 'height': height, - 'quality': quality, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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. - /// - /// This endpoint does not follow HTTP redirects. - Future getImage( - {required String url, int? width, int? height}) async { - final String apiPath = '/avatars/image'; - - final Map params = { - 'url': url, - 'width': width, - 'height': height, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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? background}) async { - final String apiPath = '/avatars/initials'; - - final Map params = { - 'name': name, - 'width': width, - 'height': height, - 'background': background, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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 { - final String apiPath = '/avatars/qr'; - - final Map params = { - 'text': text, - 'size': size, - 'margin': margin, - 'download': download, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: params, responseType: ResponseType.bytes); - return res.data; - } -} + Avatars(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](https://appwrite.io/docs/references/cloud/client-web/account#getSessions) + /// 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 enums.Browser code, int? width, int? height, int? quality}) async { + final String apiPath = '/avatars/browsers/{code}'.replaceAll('{code}', code.value); + + final Map params = { + 'width': width, +'height': height, +'quality': quality, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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 enums.CreditCard code, int? width, int? height, int? quality}) async { + final String apiPath = '/avatars/credit-cards/{code}'.replaceAll('{code}', code.value); + + final Map params = { + 'width': width, +'height': height, +'quality': quality, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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. + /// + /// This endpoint does not follow HTTP redirects. + Future getFavicon({required String url}) async { + final String apiPath = '/avatars/favicon'; + + final Map params = { + 'url': url, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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. Country codes + /// follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard. + /// + /// 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 enums.Flag code, int? width, int? height, int? quality}) async { + final String apiPath = '/avatars/flags/{code}'.replaceAll('{code}', code.value); + + final Map params = { + 'width': width, +'height': height, +'quality': quality, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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. + /// + /// This endpoint does not follow HTTP redirects. + Future getImage({required String url, int? width, int? height}) async { + final String apiPath = '/avatars/image'; + + final Map params = { + 'url': url, +'width': width, +'height': height, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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? background}) async { + final String apiPath = '/avatars/initials'; + + final Map params = { + 'name': name, +'width': width, +'height': height, +'background': background, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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 { + final String apiPath = '/avatars/qr'; + + final Map params = { + 'text': text, +'size': size, +'margin': margin, +'download': download, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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 5d3a8c86..6d74eb4b 100644 --- a/lib/services/databases.dart +++ b/lib/services/databases.dart @@ -3,1280 +3,1093 @@ part of '../dart_appwrite.dart'; /// The Databases service allows you to create structured collections of /// documents, query and filter lists of documents class Databases extends Service { - Databases(super.client); - - /// List databases - /// - /// Get a list of all databases from the current Appwrite project. You can use - /// the search parameter to filter your results. - Future list( - {List? queries, String? search}) async { - final String apiPath = '/databases'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.DatabaseList.fromMap(res.data); - } - - /// Create database - /// - /// Create a new Database. - /// - Future create( - {required String databaseId, required String name, bool? enabled}) async { - final String apiPath = '/databases'; - - final Map apiParams = { - 'databaseId': databaseId, - 'name': name, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Database.fromMap(res.data); - } - - /// Get database - /// - /// Get a database by its unique ID. This endpoint response returns a JSON - /// object with the database metadata. - Future get({required String databaseId}) async { - final String apiPath = - '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Database.fromMap(res.data); - } - - /// Update database - /// - /// Update a database by its unique ID. - Future update( - {required String databaseId, required String name, bool? enabled}) async { - final String apiPath = - '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Database.fromMap(res.data); - } - - /// Delete database - /// - /// Delete a database by its unique ID. Only API keys with with databases.write - /// scope can delete a database. - Future delete({required String databaseId}) async { - final String apiPath = - '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List collections - /// - /// Get a list of all collections that belong to the provided databaseId. You - /// can use the search parameter to filter your results. - Future listCollections( - {required String databaseId, - List? queries, - String? search}) async { - final String apiPath = '/databases/{databaseId}/collections' - .replaceAll('{databaseId}', databaseId); - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.CollectionList.fromMap(res.data); - } - - /// Create collection - /// - /// Create a new Collection. Before using this route, you should create a new - /// database resource using either a [server - /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) - /// API or directly from your database console. - Future createCollection( - {required String databaseId, - required String collectionId, - required String name, - List? permissions, - bool? documentSecurity, - bool? enabled}) async { - final String apiPath = '/databases/{databaseId}/collections' - .replaceAll('{databaseId}', databaseId); - - final Map apiParams = { - 'collectionId': collectionId, - 'name': name, - 'permissions': permissions, - 'documentSecurity': documentSecurity, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Collection.fromMap(res.data); - } - - /// Get collection - /// - /// Get a collection by its unique ID. This endpoint response returns a JSON - /// object with the collection metadata. - Future getCollection( - {required String databaseId, required String collectionId}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Collection.fromMap(res.data); - } - - /// Update collection - /// - /// Update a collection by its unique ID. - Future updateCollection( - {required String databaseId, - required String collectionId, - required String name, - List? permissions, - bool? documentSecurity, - bool? enabled}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'name': name, - 'permissions': permissions, - 'documentSecurity': documentSecurity, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Collection.fromMap(res.data); - } - - /// Delete collection - /// - /// Delete a collection by its unique ID. Only users with write permissions - /// have access to delete this resource. - Future deleteCollection( - {required String databaseId, required String collectionId}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List attributes - /// - /// List attributes in the collection. - Future listAttributes( - {required String databaseId, - required String collectionId, - List? queries}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeList.fromMap(res.data); - } - - /// Create boolean attribute - /// - /// Create a boolean attribute. - /// - Future createBooleanAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - bool? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/boolean' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeBoolean.fromMap(res.data); - } - - /// Update boolean attribute - /// - /// Update a boolean attribute. Changing the `default` value will not update - /// already existing documents. - Future updateBooleanAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required bool? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/boolean/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeBoolean.fromMap(res.data); - } - - /// Create datetime attribute - /// - /// Create a date time attribute according to the ISO 8601 standard. - Future createDatetimeAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - String? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/datetime' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeDatetime.fromMap(res.data); - } - - /// Update dateTime attribute - /// - /// Update a date time attribute. Changing the `default` value will not update - /// already existing documents. - Future updateDatetimeAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required String? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/datetime/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeDatetime.fromMap(res.data); - } - - /// Create email attribute - /// - /// Create an email attribute. - /// - Future createEmailAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - String? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/email' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEmail.fromMap(res.data); - } - - /// Update email attribute - /// - /// Update an email attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateEmailAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required String? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/email/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEmail.fromMap(res.data); - } - - /// Create enum attribute - /// - /// Create an enumeration attribute. The `elements` param acts as a white-list - /// of accepted values for this attribute. - /// - Future createEnumAttribute( - {required String databaseId, - required String collectionId, - required String key, - required List elements, - required bool xrequired, - String? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/enum' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'elements': elements, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEnum.fromMap(res.data); - } - - /// Update enum attribute - /// - /// Update an enum attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateEnumAttribute( - {required String databaseId, - required String collectionId, - required String key, - required List elements, - required bool xrequired, - required String? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/enum/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'elements': elements, - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEnum.fromMap(res.data); - } - - /// Create float attribute - /// - /// Create a float attribute. Optionally, minimum and maximum values can be - /// provided. - /// - Future createFloatAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - double? min, - double? max, - double? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/float' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, - 'array': array, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeFloat.fromMap(res.data); - } - - /// Update float attribute - /// - /// Update a float attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateFloatAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required double min, - required double max, - required double? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/float/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeFloat.fromMap(res.data); - } - - /// Create integer attribute - /// - /// Create an integer attribute. Optionally, minimum and maximum values can be - /// provided. - /// - Future createIntegerAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - int? min, - int? max, - int? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/integer' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, - 'array': array, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeInteger.fromMap(res.data); - } - - /// Update integer attribute - /// - /// Update an integer attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateIntegerAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required int min, - required int max, - required int? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/integer/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeInteger.fromMap(res.data); - } - - /// Create IP address attribute - /// - /// Create IP address attribute. - /// - Future createIpAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - String? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/ip' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeIp.fromMap(res.data); - } - - /// Update IP address attribute - /// - /// Update an ip attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateIpAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required String? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/ip/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeIp.fromMap(res.data); - } - - /// Create relationship attribute - /// - /// Create relationship attribute. [Learn more about relationship - /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). - /// - Future createRelationshipAttribute( - {required String databaseId, - required String collectionId, - required String relatedCollectionId, - required enums.RelationshipType type, - bool? twoWay, - String? key, - String? twoWayKey, - enums.RelationMutate? onDelete}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/relationship' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'relatedCollectionId': relatedCollectionId, - 'type': type.value, - 'twoWay': twoWay, - 'key': key, - 'twoWayKey': twoWayKey, - 'onDelete': onDelete?.value, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeRelationship.fromMap(res.data); - } - - /// Create string attribute - /// - /// Create a string attribute. - /// - Future createStringAttribute( - {required String databaseId, - required String collectionId, - required String key, - required int size, - required bool xrequired, - String? xdefault, - bool? array, - bool? encrypt}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/string' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'size': size, - 'required': xrequired, - 'default': xdefault, - 'array': array, - 'encrypt': encrypt, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeString.fromMap(res.data); - } - - /// Update string attribute - /// - /// Update a string attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateStringAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required String? xdefault, - int? size, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/string/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'required': xrequired, - 'default': xdefault, - 'size': size, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeString.fromMap(res.data); - } - - /// Create URL attribute - /// - /// Create a URL attribute. - /// - Future createUrlAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - String? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/url' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeUrl.fromMap(res.data); - } - - /// Update URL attribute - /// - /// Update an url attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateUrlAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required String? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/url/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeUrl.fromMap(res.data); - } - - /// Get attribute - /// - /// Get attribute by ID. - Future getAttribute( - {required String databaseId, - required String collectionId, - required String key}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Delete attribute - /// - /// Deletes an attribute. - Future deleteAttribute( - {required String databaseId, - required String collectionId, - required String key}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Update relationship attribute - /// - /// Update relationship attribute. [Learn more about relationship - /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). - /// - Future updateRelationshipAttribute( - {required String databaseId, - required String collectionId, - required String key, - enums.RelationMutate? onDelete, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/{key}/relationship' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'onDelete': onDelete?.value, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeRelationship.fromMap(res.data); - } - - /// List documents - /// - /// Get a list of all the user's documents in a given collection. You can use - /// the query params to filter your results. - Future listDocuments( - {required String databaseId, - required String collectionId, - List? queries}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/documents' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.DocumentList.fromMap(res.data); - } - - /// Create document - /// - /// Create a new Document. Before using this route, you should create a new - /// collection resource using either a [server - /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) - /// API or directly from your database console. - Future createDocument( - {required String databaseId, - required String collectionId, - required String documentId, - required Map data, - List? permissions}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/documents' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'documentId': documentId, - 'data': data, - 'permissions': permissions, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Document.fromMap(res.data); - } - - /// Get document - /// - /// Get a document by its unique ID. This endpoint response returns a JSON - /// object with the document data. - Future getDocument( - {required String databaseId, - required String collectionId, - required String documentId, - List? queries}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{documentId}', documentId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Document.fromMap(res.data); - } - - /// Update document - /// - /// Update a document by its unique ID. Using the patch method you can pass - /// only specific fields that will get updated. - Future updateDocument( - {required String databaseId, - required String collectionId, - required String documentId, - Map? data, - List? permissions}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{documentId}', documentId); - - final Map apiParams = { - 'data': data, - 'permissions': permissions, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Document.fromMap(res.data); - } - - /// Delete document - /// - /// Delete a document by its unique ID. - Future deleteDocument( - {required String databaseId, - required String collectionId, - required String documentId}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{documentId}', documentId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List indexes - /// - /// List indexes in the collection. - Future listIndexes( - {required String databaseId, - required String collectionId, - List? queries}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/indexes' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.IndexList.fromMap(res.data); - } - - /// Create index - /// - /// Creates an index on the attributes listed. Your index should include all - /// the attributes you will query in a single request. - /// Attributes can be `key`, `fulltext`, and `unique`. - Future createIndex( - {required String databaseId, - required String collectionId, - required String key, - required enums.IndexType type, - required List attributes, - List? orders}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/indexes' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'type': type.value, - 'attributes': attributes, - 'orders': orders, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Index.fromMap(res.data); - } - - /// Get index - /// - /// Get index by ID. - Future getIndex( - {required String databaseId, - required String collectionId, - required String key}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/indexes/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Index.fromMap(res.data); - } - - /// Delete index - /// - /// Delete an index. - Future deleteIndex( - {required String databaseId, - required String collectionId, - required String key}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/indexes/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } -} + Databases(super.client); + + /// List databases + /// + /// Get a list of all databases from the current Appwrite project. You can use + /// the search parameter to filter your results. + Future list({List? queries, String? search}) async { + final String apiPath = '/databases'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DatabaseList.fromMap(res.data); + + } + + /// Create database + /// + /// Create a new Database. + /// + Future create({required String databaseId, required String name, bool? enabled}) async { + final String apiPath = '/databases'; + + final Map apiParams = { + + 'databaseId': databaseId, +'name': name, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Database.fromMap(res.data); + + } + + /// Get database + /// + /// Get a database by its unique ID. This endpoint response returns a JSON + /// object with the database metadata. + Future get({required String databaseId}) async { + final String apiPath = '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Database.fromMap(res.data); + + } + + /// Update database + /// + /// Update a database by its unique ID. + Future update({required String databaseId, required String name, bool? enabled}) async { + final String apiPath = '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Database.fromMap(res.data); + + } + + /// Delete database + /// + /// Delete a database by its unique ID. Only API keys with with databases.write + /// scope can delete a database. + Future delete({required String databaseId}) async { + final String apiPath = '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List collections + /// + /// Get a list of all collections that belong to the provided databaseId. You + /// can use the search parameter to filter your results. + Future listCollections({required String databaseId, List? queries, String? search}) async { + final String apiPath = '/databases/{databaseId}/collections'.replaceAll('{databaseId}', databaseId); + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.CollectionList.fromMap(res.data); + + } + + /// Create collection + /// + /// Create a new Collection. Before using this route, you should create a new + /// database resource using either a [server + /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) + /// API or directly from your database console. + Future createCollection({required String databaseId, required String collectionId, required String name, List? permissions, bool? documentSecurity, bool? enabled}) async { + final String apiPath = '/databases/{databaseId}/collections'.replaceAll('{databaseId}', databaseId); + + final Map apiParams = { + + 'collectionId': collectionId, +'name': name, +'permissions': permissions, +'documentSecurity': documentSecurity, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Collection.fromMap(res.data); + + } + + /// Get collection + /// + /// Get a collection by its unique ID. This endpoint response returns a JSON + /// object with the collection metadata. + Future getCollection({required String databaseId, required String collectionId}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Collection.fromMap(res.data); + + } + + /// Update collection + /// + /// Update a collection by its unique ID. + Future updateCollection({required String databaseId, required String collectionId, required String name, List? permissions, bool? documentSecurity, bool? enabled}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'name': name, +'permissions': permissions, +'documentSecurity': documentSecurity, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Collection.fromMap(res.data); + + } + + /// Delete collection + /// + /// Delete a collection by its unique ID. Only users with write permissions + /// have access to delete this resource. + Future deleteCollection({required String databaseId, required String collectionId}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List attributes + /// + /// List attributes in the collection. + Future listAttributes({required String databaseId, required String collectionId, List? queries}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeList.fromMap(res.data); + + } + + /// Create boolean attribute + /// + /// Create a boolean attribute. + /// + Future createBooleanAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, bool? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/boolean'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeBoolean.fromMap(res.data); + + } + + /// Update boolean attribute + /// + /// Update a boolean attribute. Changing the `default` value will not update + /// already existing documents. + Future updateBooleanAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required bool? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/boolean/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeBoolean.fromMap(res.data); + + } + + /// Create datetime attribute + /// + /// Create a date time attribute according to the ISO 8601 standard. + Future createDatetimeAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/datetime'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeDatetime.fromMap(res.data); + + } + + /// Update dateTime attribute + /// + /// Update a date time attribute. Changing the `default` value will not update + /// already existing documents. + Future updateDatetimeAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/datetime/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeDatetime.fromMap(res.data); + + } + + /// Create email attribute + /// + /// Create an email attribute. + /// + Future createEmailAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/email'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEmail.fromMap(res.data); + + } + + /// Update email attribute + /// + /// Update an email attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateEmailAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/email/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEmail.fromMap(res.data); + + } + + /// Create enum attribute + /// + /// Create an enumeration attribute. The `elements` param acts as a white-list + /// of accepted values for this attribute. + /// + Future createEnumAttribute({required String databaseId, required String collectionId, required String key, required List elements, required bool xrequired, String? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/enum'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'elements': elements, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEnum.fromMap(res.data); + + } + + /// Update enum attribute + /// + /// Update an enum attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateEnumAttribute({required String databaseId, required String collectionId, required String key, required List elements, required bool xrequired, required String? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/enum/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'elements': elements, +'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEnum.fromMap(res.data); + + } + + /// Create float attribute + /// + /// Create a float attribute. Optionally, minimum and maximum values can be + /// provided. + /// + Future createFloatAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, double? min, double? max, double? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/float'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'required': xrequired, +'min': min, +'max': max, +'default': xdefault, +'array': array, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeFloat.fromMap(res.data); + + } + + /// Update float attribute + /// + /// Update a float attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateFloatAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required double min, required double max, required double? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/float/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'required': xrequired, +'min': min, +'max': max, +'default': xdefault, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeFloat.fromMap(res.data); + + } + + /// Create integer attribute + /// + /// Create an integer attribute. Optionally, minimum and maximum values can be + /// provided. + /// + Future createIntegerAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, int? min, int? max, int? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/integer'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'required': xrequired, +'min': min, +'max': max, +'default': xdefault, +'array': array, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeInteger.fromMap(res.data); + + } + + /// Update integer attribute + /// + /// Update an integer attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateIntegerAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required int min, required int max, required int? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/integer/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'required': xrequired, +'min': min, +'max': max, +'default': xdefault, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeInteger.fromMap(res.data); + + } + + /// Create IP address attribute + /// + /// Create IP address attribute. + /// + Future createIpAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/ip'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeIp.fromMap(res.data); + + } + + /// Update IP address attribute + /// + /// Update an ip attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateIpAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/ip/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeIp.fromMap(res.data); + + } + + /// Create relationship attribute + /// + /// Create relationship attribute. [Learn more about relationship + /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). + /// + Future createRelationshipAttribute({required String databaseId, required String collectionId, required String relatedCollectionId, required enums.RelationshipType type, bool? twoWay, String? key, String? twoWayKey, enums.RelationMutate? onDelete}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/relationship'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'relatedCollectionId': relatedCollectionId, +'type': type.value, +'twoWay': twoWay, +'key': key, +'twoWayKey': twoWayKey, +'onDelete': onDelete?.value, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeRelationship.fromMap(res.data); + + } + + /// Create string attribute + /// + /// Create a string attribute. + /// + Future createStringAttribute({required String databaseId, required String collectionId, required String key, required int size, required bool xrequired, String? xdefault, bool? array, bool? encrypt}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/string'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'size': size, +'required': xrequired, +'default': xdefault, +'array': array, +'encrypt': encrypt, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeString.fromMap(res.data); + + } + + /// Update string attribute + /// + /// Update a string attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateStringAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, int? size, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/string/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'required': xrequired, +'default': xdefault, +'size': size, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeString.fromMap(res.data); + + } + + /// Create URL attribute + /// + /// Create a URL attribute. + /// + Future createUrlAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/url'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeUrl.fromMap(res.data); + + } + + /// Update URL attribute + /// + /// Update an url attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateUrlAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/url/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeUrl.fromMap(res.data); + + } + + /// Get attribute + /// + /// Get attribute by ID. + Future getAttribute({required String databaseId, required String collectionId, required String key}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Delete attribute + /// + /// Deletes an attribute. + Future deleteAttribute({required String databaseId, required String collectionId, required String key}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Update relationship attribute + /// + /// Update relationship attribute. [Learn more about relationship + /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). + /// + Future updateRelationshipAttribute({required String databaseId, required String collectionId, required String key, enums.RelationMutate? onDelete, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}/relationship'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'onDelete': onDelete?.value, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeRelationship.fromMap(res.data); + + } + + /// List documents + /// + /// Get a list of all the user's documents in a given collection. You can use + /// the query params to filter your results. + Future listDocuments({required String databaseId, required String collectionId, List? queries}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DocumentList.fromMap(res.data); + + } + + /// Create document + /// + /// Create a new Document. Before using this route, you should create a new + /// collection resource using either a [server + /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) + /// API or directly from your database console. + Future createDocument({required String databaseId, required String collectionId, required String documentId, required Map data, List? permissions}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'documentId': documentId, +'data': data, +'permissions': permissions, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Document.fromMap(res.data); + + } + + /// Get document + /// + /// Get a document by its unique ID. This endpoint response returns a JSON + /// object with the document data. + Future getDocument({required String databaseId, required String collectionId, required String documentId, List? queries}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Document.fromMap(res.data); + + } + + /// Update document + /// + /// Update a document by its unique ID. Using the patch method you can pass + /// only specific fields that will get updated. + Future updateDocument({required String databaseId, required String collectionId, required String documentId, Map? data, List? permissions}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); + + final Map apiParams = { + + 'data': data, +'permissions': permissions, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Document.fromMap(res.data); + + } + + /// Delete document + /// + /// Delete a document by its unique ID. + Future deleteDocument({required String databaseId, required String collectionId, required String documentId}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List indexes + /// + /// List indexes in the collection. + Future listIndexes({required String databaseId, required String collectionId, List? queries}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.IndexList.fromMap(res.data); + + } + + /// Create index + /// + /// Creates an index on the attributes listed. Your index should include all + /// the attributes you will query in a single request. + /// Attributes can be `key`, `fulltext`, and `unique`. + Future createIndex({required String databaseId, required String collectionId, required String key, required enums.IndexType type, required List attributes, List? orders}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'type': type.value, +'attributes': attributes, +'orders': orders, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Index.fromMap(res.data); + + } + + /// Get index + /// + /// Get index by ID. + Future getIndex({required String databaseId, required String collectionId, required String key}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Index.fromMap(res.data); + + } + + /// Delete index + /// + /// Delete an index. + Future deleteIndex({required String databaseId, required String collectionId, required String key}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } +} \ No newline at end of file diff --git a/lib/services/functions.dart b/lib/services/functions.dart index 7a59547e..2bc323e9 100644 --- a/lib/services/functions.dart +++ b/lib/services/functions.dart @@ -3,649 +3,619 @@ part of '../dart_appwrite.dart'; /// The Functions Service allows you view, create and manage your Cloud /// Functions. class Functions extends Service { - Functions(super.client); - - /// List functions - /// - /// Get a list of all the project's functions. You can use the query params to - /// filter your results. - Future list( - {List? queries, String? search}) async { - final String apiPath = '/functions'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.FunctionList.fromMap(res.data); - } - - /// Create function - /// - /// Create a new function. You can pass a list of - /// [permissions](https://appwrite.io/docs/permissions) to allow different - /// project users or team with access to execute the function using the client - /// API. - Future create( - {required String functionId, - required String name, - required enums.Runtime runtime, - List? execute, - List? events, - String? schedule, - int? timeout, - bool? enabled, - bool? logging, - String? entrypoint, - String? commands, - List? scopes, - String? installationId, - String? providerRepositoryId, - String? providerBranch, - bool? providerSilentMode, - String? providerRootDirectory, - String? templateRepository, - String? templateOwner, - String? templateRootDirectory, - String? templateVersion, - String? specification}) async { - final String apiPath = '/functions'; - - final Map apiParams = { - 'functionId': functionId, - 'name': name, - 'runtime': runtime.value, - 'execute': execute, - 'events': events, - 'schedule': schedule, - 'timeout': timeout, - 'enabled': enabled, - 'logging': logging, - 'entrypoint': entrypoint, - 'commands': commands, - 'scopes': scopes, - 'installationId': installationId, - 'providerRepositoryId': providerRepositoryId, - 'providerBranch': providerBranch, - 'providerSilentMode': providerSilentMode, - 'providerRootDirectory': providerRootDirectory, - 'templateRepository': templateRepository, - 'templateOwner': templateOwner, - 'templateRootDirectory': templateRootDirectory, - 'templateVersion': templateVersion, - 'specification': specification, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - } - - /// List runtimes - /// - /// Get a list of all runtimes that are currently active on your instance. - Future listRuntimes() async { - final String apiPath = '/functions/runtimes'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.RuntimeList.fromMap(res.data); - } - - /// List available function runtime specifications - /// - /// List allowed function specifications for this instance. - /// - Future listSpecifications() async { - final String apiPath = '/functions/specifications'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SpecificationList.fromMap(res.data); - } - - /// Get function - /// - /// Get a function by its unique ID. - Future get({required String functionId}) async { - final String apiPath = - '/functions/{functionId}'.replaceAll('{functionId}', functionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - } - - /// Update function - /// - /// Update function by its unique ID. - Future update( - {required String functionId, - required String name, - enums.Runtime? runtime, - List? execute, - List? events, - String? schedule, - int? timeout, - bool? enabled, - bool? logging, - String? entrypoint, - String? commands, - List? scopes, - String? installationId, - String? providerRepositoryId, - String? providerBranch, - bool? providerSilentMode, - String? providerRootDirectory, - String? specification}) async { - final String apiPath = - '/functions/{functionId}'.replaceAll('{functionId}', functionId); - - final Map apiParams = { - 'name': name, - 'runtime': runtime?.value, - 'execute': execute, - 'events': events, - 'schedule': schedule, - 'timeout': timeout, - 'enabled': enabled, - 'logging': logging, - 'entrypoint': entrypoint, - 'commands': commands, - 'scopes': scopes, - 'installationId': installationId, - 'providerRepositoryId': providerRepositoryId, - 'providerBranch': providerBranch, - 'providerSilentMode': providerSilentMode, - 'providerRootDirectory': providerRootDirectory, - 'specification': specification, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - } - - /// Delete function - /// - /// Delete a function by its unique ID. - Future delete({required String functionId}) async { - final String apiPath = - '/functions/{functionId}'.replaceAll('{functionId}', functionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List deployments - /// - /// Get a list of all the project's code deployments. You can use the query - /// params to filter your results. - Future listDeployments( - {required String functionId, - List? queries, - String? search}) async { - final String apiPath = '/functions/{functionId}/deployments' - .replaceAll('{functionId}', functionId); - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.DeploymentList.fromMap(res.data); - } - - /// Create deployment - /// - /// Create a new function code deployment. Use this endpoint to upload a new - /// version of your code function. To execute your newly uploaded code, you'll - /// need to update the function's deployment to use your new deployment UID. - /// - /// This endpoint accepts a tar.gz file compressed with your code. Make sure to - /// include any dependencies your code has within the compressed file. You can - /// learn more about code packaging in the [Appwrite Cloud Functions - /// tutorial](https://appwrite.io/docs/functions). - /// - /// Use the "command" param to set the entrypoint used to execute your code. - Future createDeployment( - {required String functionId, - required InputFile code, - required bool activate, - String? entrypoint, - String? commands, - Function(UploadProgress)? onProgress}) async { - final String apiPath = '/functions/{functionId}/deployments' - .replaceAll('{functionId}', functionId); - - final Map apiParams = { - 'entrypoint': entrypoint, - 'commands': commands, - 'code': code, - 'activate': activate, - }; - - final Map apiHeaders = { - 'content-type': 'multipart/form-data', - }; - - String idParamName = ''; - final paramName = 'code'; - final res = await client.chunkedUpload( - path: apiPath, - params: apiParams, - paramName: paramName, - idParamName: idParamName, - headers: apiHeaders, - onProgress: onProgress, - ); - - return models.Deployment.fromMap(res.data); - } - - /// Get deployment - /// - /// Get a code deployment by its unique ID. - Future getDeployment( - {required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Deployment.fromMap(res.data); - } - - /// Update deployment - /// - /// Update the function code deployment ID using the unique function ID. Use - /// this endpoint to switch the code deployment that should be executed by the - /// execution endpoint. - Future updateDeployment( - {required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - } - - /// Delete deployment - /// - /// Delete a code deployment by its unique ID. - Future deleteDeployment( - {required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Rebuild deployment - /// - Future createBuild( - {required String functionId, - required String deploymentId, - String? buildId}) async { - final String apiPath = - '/functions/{functionId}/deployments/{deploymentId}/build' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map apiParams = { - 'buildId': buildId, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Cancel deployment - /// - Future updateDeploymentBuild( - {required String functionId, required String deploymentId}) async { - final String apiPath = - '/functions/{functionId}/deployments/{deploymentId}/build' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Build.fromMap(res.data); - } - - /// Download deployment - /// - /// Get a Deployment's contents by its unique ID. This endpoint supports range - /// requests for partial or streaming file download. - Future getDeploymentDownload( - {required String functionId, required String deploymentId}) async { - final String apiPath = - '/functions/{functionId}/deployments/{deploymentId}/download' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map params = { - 'project': client.config['project'], - 'key': client.config['key'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: params, responseType: ResponseType.bytes); - 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. - Future listExecutions( - {required String functionId, - List? queries, - String? search}) async { - final String apiPath = '/functions/{functionId}/executions' - .replaceAll('{functionId}', functionId); - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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? body, - bool? xasync, - String? path, - enums.ExecutionMethod? method, - Map? headers, - String? scheduledAt}) async { - final String apiPath = '/functions/{functionId}/executions' - .replaceAll('{functionId}', functionId); - - final Map apiParams = { - 'body': body, - 'async': xasync, - 'path': path, - 'method': method?.value, - 'headers': headers, - 'scheduledAt': scheduledAt, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/functions/{functionId}/executions/{executionId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{executionId}', executionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Execution.fromMap(res.data); - } - - /// Delete execution - /// - /// Delete a function execution by its unique ID. - /// - Future deleteExecution( - {required String functionId, required String executionId}) async { - final String apiPath = '/functions/{functionId}/executions/{executionId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{executionId}', executionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List variables - /// - /// Get a list of all variables of a specific function. - Future listVariables( - {required String functionId}) async { - final String apiPath = '/functions/{functionId}/variables' - .replaceAll('{functionId}', functionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.VariableList.fromMap(res.data); - } - - /// Create variable - /// - /// Create a new function environment variable. These variables can be accessed - /// in the function at runtime as environment variables. - Future createVariable( - {required String functionId, - required String key, - required String value}) async { - final String apiPath = '/functions/{functionId}/variables' - .replaceAll('{functionId}', functionId); - - final Map apiParams = { - 'key': key, - 'value': value, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Variable.fromMap(res.data); - } - - /// Get variable - /// - /// Get a variable by its unique ID. - Future getVariable( - {required String functionId, required String variableId}) async { - final String apiPath = '/functions/{functionId}/variables/{variableId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{variableId}', variableId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Variable.fromMap(res.data); - } - - /// Update variable - /// - /// Update variable by its unique ID. - Future updateVariable( - {required String functionId, - required String variableId, - required String key, - String? value}) async { - final String apiPath = '/functions/{functionId}/variables/{variableId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{variableId}', variableId); - - final Map apiParams = { - 'key': key, - 'value': value, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Variable.fromMap(res.data); - } - - /// Delete variable - /// - /// Delete a variable by its unique ID. - Future deleteVariable( - {required String functionId, required String variableId}) async { - final String apiPath = '/functions/{functionId}/variables/{variableId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{variableId}', variableId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } -} + Functions(super.client); + + /// List functions + /// + /// Get a list of all the project's functions. You can use the query params to + /// filter your results. + Future list({List? queries, String? search}) async { + final String apiPath = '/functions'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.FunctionList.fromMap(res.data); + + } + + /// Create function + /// + /// Create a new function. You can pass a list of + /// [permissions](https://appwrite.io/docs/permissions) to allow different + /// project users or team with access to execute the function using the client + /// API. + Future create({required String functionId, required String name, required enums.Runtime runtime, List? execute, List? events, String? schedule, int? timeout, bool? enabled, bool? logging, String? entrypoint, String? commands, List? scopes, String? installationId, String? providerRepositoryId, String? providerBranch, bool? providerSilentMode, String? providerRootDirectory, String? templateRepository, String? templateOwner, String? templateRootDirectory, String? templateVersion, String? specification}) async { + final String apiPath = '/functions'; + + final Map apiParams = { + + 'functionId': functionId, +'name': name, +'runtime': runtime.value, +'execute': execute, +'events': events, +'schedule': schedule, +'timeout': timeout, +'enabled': enabled, +'logging': logging, +'entrypoint': entrypoint, +'commands': commands, +'scopes': scopes, +'installationId': installationId, +'providerRepositoryId': providerRepositoryId, +'providerBranch': providerBranch, +'providerSilentMode': providerSilentMode, +'providerRootDirectory': providerRootDirectory, +'templateRepository': templateRepository, +'templateOwner': templateOwner, +'templateRootDirectory': templateRootDirectory, +'templateVersion': templateVersion, +'specification': specification, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + + } + + /// List runtimes + /// + /// Get a list of all runtimes that are currently active on your instance. + Future listRuntimes() async { + final String apiPath = '/functions/runtimes'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.RuntimeList.fromMap(res.data); + + } + + /// List available function runtime specifications + /// + /// List allowed function specifications for this instance. + /// + Future listSpecifications() async { + final String apiPath = '/functions/specifications'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SpecificationList.fromMap(res.data); + + } + + /// Get function + /// + /// Get a function by its unique ID. + Future get({required String functionId}) async { + final String apiPath = '/functions/{functionId}'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + + } + + /// Update function + /// + /// Update function by its unique ID. + Future update({required String functionId, required String name, enums.Runtime? runtime, List? execute, List? events, String? schedule, int? timeout, bool? enabled, bool? logging, String? entrypoint, String? commands, List? scopes, String? installationId, String? providerRepositoryId, String? providerBranch, bool? providerSilentMode, String? providerRootDirectory, String? specification}) async { + final String apiPath = '/functions/{functionId}'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + + 'name': name, +'runtime': runtime?.value, +'execute': execute, +'events': events, +'schedule': schedule, +'timeout': timeout, +'enabled': enabled, +'logging': logging, +'entrypoint': entrypoint, +'commands': commands, +'scopes': scopes, +'installationId': installationId, +'providerRepositoryId': providerRepositoryId, +'providerBranch': providerBranch, +'providerSilentMode': providerSilentMode, +'providerRootDirectory': providerRootDirectory, +'specification': specification, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + + } + + /// Delete function + /// + /// Delete a function by its unique ID. + Future delete({required String functionId}) async { + final String apiPath = '/functions/{functionId}'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List deployments + /// + /// Get a list of all the project's code deployments. You can use the query + /// params to filter your results. + Future listDeployments({required String functionId, List? queries, String? search}) async { + final String apiPath = '/functions/{functionId}/deployments'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DeploymentList.fromMap(res.data); + + } + + /// Create deployment + /// + /// Create a new function code deployment. Use this endpoint to upload a new + /// version of your code function. To execute your newly uploaded code, you'll + /// need to update the function's deployment to use your new deployment UID. + /// + /// This endpoint accepts a tar.gz file compressed with your code. Make sure to + /// include any dependencies your code has within the compressed file. You can + /// learn more about code packaging in the [Appwrite Cloud Functions + /// tutorial](https://appwrite.io/docs/functions). + /// + /// Use the "command" param to set the entrypoint used to execute your code. + Future createDeployment({required String functionId, required Payload code, required bool activate, String? entrypoint, String? commands, Function(UploadProgress)? onProgress}) async { + final String apiPath = '/functions/{functionId}/deployments'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + + 'entrypoint': entrypoint, +'commands': commands, +'code': code, +'activate': activate, + + }; + + final Map apiHeaders = { + 'content-type': 'multipart/form-data', + + }; + + String idParamName = ''; + final paramName = 'code'; + final res = await client.chunkedUpload( + path: apiPath, + params: apiParams, + paramName: paramName, + idParamName: idParamName, + headers: apiHeaders, + onProgress: onProgress, + ); + + return models.Deployment.fromMap(res.data); + + } + + /// Get deployment + /// + /// Get a code deployment by its unique ID. + Future getDeployment({required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Deployment.fromMap(res.data); + + } + + /// Update deployment + /// + /// Update the function code deployment ID using the unique function ID. Use + /// this endpoint to switch the code deployment that should be executed by the + /// execution endpoint. + Future updateDeployment({required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + + } + + /// Delete deployment + /// + /// Delete a code deployment by its unique ID. + Future deleteDeployment({required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Rebuild deployment + /// + Future createBuild({required String functionId, required String deploymentId, String? buildId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}/build'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map apiParams = { + + 'buildId': buildId, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Cancel deployment + /// + Future updateDeploymentBuild({required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}/build'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Build.fromMap(res.data); + + } + + /// Download deployment + /// + /// Get a Deployment's contents by its unique ID. This endpoint supports range + /// requests for partial or streaming file download. + Future getDeploymentDownload({required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}/download'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map params = { + + + 'project': client.config['project'], + 'key': client.config['key'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: params, responseType: ResponseType.bytes); + 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. + Future listExecutions({required String functionId, List? queries, String? search}) async { + final String apiPath = '/functions/{functionId}/executions'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + 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, Payload? body, bool? xasync, String? path, enums.ExecutionMethod? method, Map? headers, String? scheduledAt, Function(UploadProgress)? onProgress}) async { + final String apiPath = '/functions/{functionId}/executions'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + + 'body': body, +'async': xasync, +'path': path, +'method': method?.value, +'headers': headers, +'scheduledAt': scheduledAt, + + }; + + final Map apiHeaders = { + 'content-type': 'multipart/form-data', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/functions/{functionId}/executions/{executionId}'.replaceAll('{functionId}', functionId).replaceAll('{executionId}', executionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Execution.fromMap(res.data); + + } + + /// Delete execution + /// + /// Delete a function execution by its unique ID. + /// + Future deleteExecution({required String functionId, required String executionId}) async { + final String apiPath = '/functions/{functionId}/executions/{executionId}'.replaceAll('{functionId}', functionId).replaceAll('{executionId}', executionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List variables + /// + /// Get a list of all variables of a specific function. + Future listVariables({required String functionId}) async { + final String apiPath = '/functions/{functionId}/variables'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.VariableList.fromMap(res.data); + + } + + /// Create variable + /// + /// Create a new function environment variable. These variables can be accessed + /// in the function at runtime as environment variables. + Future createVariable({required String functionId, required String key, required String value}) async { + final String apiPath = '/functions/{functionId}/variables'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + + 'key': key, +'value': value, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Variable.fromMap(res.data); + + } + + /// Get variable + /// + /// Get a variable by its unique ID. + Future getVariable({required String functionId, required String variableId}) async { + final String apiPath = '/functions/{functionId}/variables/{variableId}'.replaceAll('{functionId}', functionId).replaceAll('{variableId}', variableId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Variable.fromMap(res.data); + + } + + /// Update variable + /// + /// Update variable by its unique ID. + Future updateVariable({required String functionId, required String variableId, required String key, String? value}) async { + final String apiPath = '/functions/{functionId}/variables/{variableId}'.replaceAll('{functionId}', functionId).replaceAll('{variableId}', variableId); + + final Map apiParams = { + + 'key': key, +'value': value, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Variable.fromMap(res.data); + + } + + /// Delete variable + /// + /// Delete a variable by its unique ID. + Future deleteVariable({required String functionId, required String variableId}) async { + final String apiPath = '/functions/{functionId}/variables/{variableId}'.replaceAll('{functionId}', functionId).replaceAll('{variableId}', variableId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } +} \ No newline at end of file diff --git a/lib/services/graphql.dart b/lib/services/graphql.dart index fdc1ae0b..be9d037b 100644 --- a/lib/services/graphql.dart +++ b/lib/services/graphql.dart @@ -3,47 +3,53 @@ part of '../dart_appwrite.dart'; /// The GraphQL API allows you to query and mutate your Appwrite server using /// GraphQL. class Graphql extends Service { - Graphql(super.client); - - /// GraphQL endpoint - /// - /// Execute a GraphQL mutation. - Future query({required Map query}) async { - final String apiPath = '/graphql'; - - final Map apiParams = { - 'query': query, - }; - - final Map apiHeaders = { - 'x-sdk-graphql': 'true', - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// GraphQL endpoint - /// - /// Execute a GraphQL mutation. - Future mutation({required Map query}) async { - final String apiPath = '/graphql/mutation'; - - final Map apiParams = { - 'query': query, - }; - - final Map apiHeaders = { - 'x-sdk-graphql': 'true', - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } -} + Graphql(super.client); + + /// GraphQL endpoint + /// + /// Execute a GraphQL mutation. + Future query({required Map query}) async { + final String apiPath = '/graphql'; + + final Map apiParams = { + + 'query': query, + + }; + + final Map apiHeaders = { + 'x-sdk-graphql': 'true', +'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// GraphQL endpoint + /// + /// Execute a GraphQL mutation. + Future mutation({required Map query}) async { + final String apiPath = '/graphql/mutation'; + + final Map apiParams = { + + 'query': query, + + }; + + final Map apiHeaders = { + 'x-sdk-graphql': 'true', +'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } +} \ No newline at end of file diff --git a/lib/services/health.dart b/lib/services/health.dart index 121083c0..4e7b4603 100644 --- a/lib/services/health.dart +++ b/lib/services/health.dart @@ -3,473 +3,548 @@ part of '../dart_appwrite.dart'; /// The Health service allows you to both validate and monitor your Appwrite /// server's health. class Health extends Service { - Health(super.client); + Health(super.client); - /// Get HTTP - /// - /// Check the Appwrite HTTP server is up and responsive. - Future get() async { - final String apiPath = '/health'; + /// Get HTTP + /// + /// Check the Appwrite HTTP server is up and responsive. + Future get() async { + final String apiPath = '/health'; - final Map apiParams = {}; + final Map apiParams = { + + + }; - final Map apiHeaders = { - 'content-type': 'application/json', - }; + final Map apiHeaders = { + 'content-type': 'application/json', - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + }; - return models.HealthStatus.fromMap(res.data); - } + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - /// Get antivirus - /// - /// Check the Appwrite Antivirus server is up and connection is successful. - Future getAntivirus() async { - final String apiPath = '/health/anti-virus'; + return models.HealthStatus.fromMap(res.data); - final Map apiParams = {}; + } - final Map apiHeaders = { - 'content-type': 'application/json', - }; + /// Get antivirus + /// + /// Check the Appwrite Antivirus server is up and connection is successful. + Future getAntivirus() async { + final String apiPath = '/health/anti-virus'; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + final Map apiParams = { + + + }; - return models.HealthAntivirus.fromMap(res.data); - } + final Map apiHeaders = { + 'content-type': 'application/json', - /// Get cache - /// - /// Check the Appwrite in-memory cache servers are up and connection is - /// successful. - Future getCache() async { - final String apiPath = '/health/cache'; + }; - final Map apiParams = {}; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final Map apiHeaders = { - 'content-type': 'application/json', - }; + return models.HealthAntivirus.fromMap(res.data); - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + } - return models.HealthStatus.fromMap(res.data); - } + /// Get cache + /// + /// Check the Appwrite in-memory cache servers are up and connection is + /// successful. + Future getCache() async { + final String apiPath = '/health/cache'; - /// Get the SSL certificate for a domain - /// - /// Get the SSL certificate for a domain - Future getCertificate({String? domain}) async { - final String apiPath = '/health/certificate'; + final Map apiParams = { + + + }; - final Map apiParams = { - 'domain': domain, - }; + final Map apiHeaders = { + 'content-type': 'application/json', - final Map apiHeaders = { - 'content-type': 'application/json', - }; + }; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - return models.HealthCertificate.fromMap(res.data); - } + return models.HealthStatus.fromMap(res.data); - /// Get DB - /// - /// Check the Appwrite database servers are up and connection is successful. - Future getDB() async { - final String apiPath = '/health/db'; + } - final Map apiParams = {}; + /// Get the SSL certificate for a domain + /// + /// Get the SSL certificate for a domain + Future getCertificate({String? domain}) async { + final String apiPath = '/health/certificate'; - final Map apiHeaders = { - 'content-type': 'application/json', - }; + final Map apiParams = { + 'domain': domain, - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + + }; - return models.HealthStatus.fromMap(res.data); - } + final Map apiHeaders = { + 'content-type': 'application/json', - /// Get pubsub - /// - /// Check the Appwrite pub-sub servers are up and connection is successful. - Future getPubSub() async { - final String apiPath = '/health/pubsub'; + }; - final Map apiParams = {}; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final Map apiHeaders = { - 'content-type': 'application/json', - }; + return models.HealthCertificate.fromMap(res.data); - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + } - return models.HealthStatus.fromMap(res.data); - } + /// Get DB + /// + /// Check the Appwrite database servers are up and connection is successful. + Future getDB() async { + final String apiPath = '/health/db'; - /// Get queue - /// - /// Check the Appwrite queue messaging servers are up and connection is - /// successful. - Future getQueue() async { - final String apiPath = '/health/queue'; + final Map apiParams = { + + + }; - final Map apiParams = {}; + final Map apiHeaders = { + 'content-type': 'application/json', - final Map apiHeaders = { - 'content-type': 'application/json', - }; + }; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthStatus.fromMap(res.data); - } + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - /// Get builds queue - /// - /// Get the number of builds that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueBuilds({int? threshold}) async { - final String apiPath = '/health/queue/builds'; - - final Map apiParams = { - 'threshold': threshold, - }; + return models.HealthStatus.fromMap(res.data); - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get certificates queue - /// - /// Get the number of certificates that are waiting to be issued against - /// [Letsencrypt](https://letsencrypt.org/) in the Appwrite internal queue - /// server. - Future getQueueCertificates({int? threshold}) async { - final String apiPath = '/health/queue/certificates'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get databases queue - /// - /// Get the number of database changes that are waiting to be processed in the - /// Appwrite internal queue server. - Future getQueueDatabases( - {String? name, int? threshold}) async { - final String apiPath = '/health/queue/databases'; - - final Map apiParams = { - 'name': name, - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get deletes queue - /// - /// Get the number of background destructive changes that are waiting to be - /// processed in the Appwrite internal queue server. - Future getQueueDeletes({int? threshold}) async { - final String apiPath = '/health/queue/deletes'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get number of failed queue jobs - /// - /// Returns the amount of failed jobs in a given queue. - /// - Future getFailedJobs( - {required enums.Name name, int? threshold}) async { - final String apiPath = - '/health/queue/failed/{name}'.replaceAll('{name}', name.value); - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get functions queue - /// - /// Get the number of function executions that are waiting to be processed in - /// the Appwrite internal queue server. - Future getQueueFunctions({int? threshold}) async { - final String apiPath = '/health/queue/functions'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get logs queue - /// - /// Get the number of logs that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueLogs({int? threshold}) async { - final String apiPath = '/health/queue/logs'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get mails queue - /// - /// Get the number of mails that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueMails({int? threshold}) async { - final String apiPath = '/health/queue/mails'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get messaging queue - /// - /// Get the number of messages that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueMessaging({int? threshold}) async { - final String apiPath = '/health/queue/messaging'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get migrations queue - /// - /// Get the number of migrations that are waiting to be processed in the - /// Appwrite internal queue server. - Future getQueueMigrations({int? threshold}) async { - final String apiPath = '/health/queue/migrations'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } + } - /// Get usage queue - /// - /// Get the number of metrics that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueUsage({int? threshold}) async { - final String apiPath = '/health/queue/usage'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get usage dump queue - /// - /// Get the number of projects containing metrics that are waiting to be - /// processed in the Appwrite internal queue server. - Future getQueueUsageDump({int? threshold}) async { - final String apiPath = '/health/queue/usage-dump'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get webhooks queue - /// - /// Get the number of webhooks that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueWebhooks({int? threshold}) async { - final String apiPath = '/health/queue/webhooks'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get storage - /// - /// Check the Appwrite storage device is up and connection is successful. - Future getStorage() async { - final String apiPath = '/health/storage'; + /// Get pubsub + /// + /// Check the Appwrite pub-sub servers are up and connection is successful. + Future getPubSub() async { + final String apiPath = '/health/pubsub'; - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthStatus.fromMap(res.data); - } - - /// Get local storage - /// - /// Check the Appwrite local storage device is up and connection is successful. - Future getStorageLocal() async { - final String apiPath = '/health/storage/local'; - - final Map apiParams = {}; + final Map apiParams = { + + + }; - final Map apiHeaders = { - 'content-type': 'application/json', - }; + final Map apiHeaders = { + 'content-type': 'application/json', - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthStatus.fromMap(res.data); - } - - /// Get time - /// - /// Check the Appwrite server time is synced with Google remote NTP server. We - /// use this technology to smoothly handle leap seconds with no disruptive - /// events. The [Network Time - /// Protocol](https://en.wikipedia.org/wiki/Network_Time_Protocol) (NTP) is - /// used by hundreds of millions of computers and devices to synchronize their - /// clocks over the Internet. If your computer sets its own clock, it likely - /// uses NTP. - Future getTime() async { - final String apiPath = '/health/time'; + }; - final Map apiParams = {}; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final Map apiHeaders = { - 'content-type': 'application/json', - }; + return models.HealthStatus.fromMap(res.data); - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthTime.fromMap(res.data); - } -} + } + + /// Get queue + /// + /// Check the Appwrite queue messaging servers are up and connection is + /// successful. + Future getQueue() async { + final String apiPath = '/health/queue'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthStatus.fromMap(res.data); + + } + + /// Get builds queue + /// + /// Get the number of builds that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueBuilds({int? threshold}) async { + final String apiPath = '/health/queue/builds'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get certificates queue + /// + /// Get the number of certificates that are waiting to be issued against + /// [Letsencrypt](https://letsencrypt.org/) in the Appwrite internal queue + /// server. + Future getQueueCertificates({int? threshold}) async { + final String apiPath = '/health/queue/certificates'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get databases queue + /// + /// Get the number of database changes that are waiting to be processed in the + /// Appwrite internal queue server. + Future getQueueDatabases({String? name, int? threshold}) async { + final String apiPath = '/health/queue/databases'; + + final Map apiParams = { + 'name': name, +'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get deletes queue + /// + /// Get the number of background destructive changes that are waiting to be + /// processed in the Appwrite internal queue server. + Future getQueueDeletes({int? threshold}) async { + final String apiPath = '/health/queue/deletes'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get number of failed queue jobs + /// + /// Returns the amount of failed jobs in a given queue. + /// + Future getFailedJobs({required enums.Name name, int? threshold}) async { + final String apiPath = '/health/queue/failed/{name}'.replaceAll('{name}', name.value); + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get functions queue + /// + /// Get the number of function executions that are waiting to be processed in + /// the Appwrite internal queue server. + Future getQueueFunctions({int? threshold}) async { + final String apiPath = '/health/queue/functions'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get logs queue + /// + /// Get the number of logs that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueLogs({int? threshold}) async { + final String apiPath = '/health/queue/logs'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get mails queue + /// + /// Get the number of mails that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueMails({int? threshold}) async { + final String apiPath = '/health/queue/mails'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get messaging queue + /// + /// Get the number of messages that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueMessaging({int? threshold}) async { + final String apiPath = '/health/queue/messaging'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get migrations queue + /// + /// Get the number of migrations that are waiting to be processed in the + /// Appwrite internal queue server. + Future getQueueMigrations({int? threshold}) async { + final String apiPath = '/health/queue/migrations'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get usage queue + /// + /// Get the number of metrics that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueUsage({int? threshold}) async { + final String apiPath = '/health/queue/usage'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get usage dump queue + /// + /// Get the number of projects containing metrics that are waiting to be + /// processed in the Appwrite internal queue server. + Future getQueueUsageDump({int? threshold}) async { + final String apiPath = '/health/queue/usage-dump'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get webhooks queue + /// + /// Get the number of webhooks that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueWebhooks({int? threshold}) async { + final String apiPath = '/health/queue/webhooks'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get storage + /// + /// Check the Appwrite storage device is up and connection is successful. + Future getStorage() async { + final String apiPath = '/health/storage'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthStatus.fromMap(res.data); + + } + + /// Get local storage + /// + /// Check the Appwrite local storage device is up and connection is successful. + Future getStorageLocal() async { + final String apiPath = '/health/storage/local'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthStatus.fromMap(res.data); + + } + + /// Get time + /// + /// Check the Appwrite server time is synced with Google remote NTP server. We + /// use this technology to smoothly handle leap seconds with no disruptive + /// events. The [Network Time + /// Protocol](https://en.wikipedia.org/wiki/Network_Time_Protocol) (NTP) is + /// used by hundreds of millions of computers and devices to synchronize their + /// clocks over the Internet. If your computer sets its own clock, it likely + /// uses NTP. + Future getTime() async { + final String apiPath = '/health/time'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthTime.fromMap(res.data); + + } +} \ No newline at end of file diff --git a/lib/services/locale.dart b/lib/services/locale.dart index b287c8e9..78372039 100644 --- a/lib/services/locale.dart +++ b/lib/services/locale.dart @@ -3,162 +3,194 @@ part of '../dart_appwrite.dart'; /// The Locale service allows you to customize your app based on your users' /// location. class Locale extends Service { - Locale(super.client); + Locale(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 { - final String apiPath = '/locale'; + /// 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 { + final String apiPath = '/locale'; - final Map apiParams = {}; + final Map apiParams = { + + + }; - final Map apiHeaders = { - 'content-type': 'application/json', - }; + final Map apiHeaders = { + 'content-type': 'application/json', - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + }; - return models.Locale.fromMap(res.data); - } + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - /// List Locale Codes - /// - /// List of all locale codes in [ISO - /// 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). - Future listCodes() async { - final String apiPath = '/locale/codes'; + return models.Locale.fromMap(res.data); - final Map apiParams = {}; + } - final Map apiHeaders = { - 'content-type': 'application/json', - }; + /// List Locale Codes + /// + /// List of all locale codes in [ISO + /// 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). + Future listCodes() async { + final String apiPath = '/locale/codes'; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + final Map apiParams = { + + + }; - return models.LocaleCodeList.fromMap(res.data); - } + final Map apiHeaders = { + 'content-type': 'application/json', - /// List continents - /// - /// List of all continents. You can use the locale header to get the data in a - /// supported language. - Future listContinents() async { - final String apiPath = '/locale/continents'; + }; - final Map apiParams = {}; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final Map apiHeaders = { - 'content-type': 'application/json', - }; + return models.LocaleCodeList.fromMap(res.data); - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + } - return models.ContinentList.fromMap(res.data); - } + /// List continents + /// + /// List of all continents. You can use the locale header to get the data in a + /// supported language. + Future listContinents() async { + final String apiPath = '/locale/continents'; - /// List countries - /// - /// List of all countries. You can use the locale header to get the data in a - /// supported language. - Future listCountries() async { - final String apiPath = '/locale/countries'; + final Map apiParams = { + + + }; - final Map apiParams = {}; + final Map apiHeaders = { + 'content-type': 'application/json', - final Map apiHeaders = { - 'content-type': 'application/json', - }; + }; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - return models.CountryList.fromMap(res.data); - } + return models.ContinentList.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 listCountriesEU() async { - final String apiPath = '/locale/countries/eu'; + } - final Map apiParams = {}; + /// List countries + /// + /// List of all countries. You can use the locale header to get the data in a + /// supported language. + Future listCountries() async { + final String apiPath = '/locale/countries'; - final Map apiHeaders = { - 'content-type': 'application/json', - }; + final Map apiParams = { + + + }; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + final Map apiHeaders = { + 'content-type': 'application/json', - 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 listCountriesPhones() async { - final String apiPath = '/locale/countries/phones'; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final Map apiParams = {}; + return models.CountryList.fromMap(res.data); - final Map apiHeaders = { - 'content-type': 'application/json', - }; + } - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + /// 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 listCountriesEU() async { + final String apiPath = '/locale/countries/eu'; - return models.PhoneList.fromMap(res.data); - } + final Map apiParams = { + + + }; - /// 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 listCurrencies() async { - final String apiPath = '/locale/currencies'; + final Map apiHeaders = { + 'content-type': 'application/json', - final Map apiParams = {}; + }; - final Map apiHeaders = { - 'content-type': 'application/json', - }; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + return models.CountryList.fromMap(res.data); - 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 listLanguages() async { - final String apiPath = '/locale/languages'; + /// 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 listCountriesPhones() async { + final String apiPath = '/locale/countries/phones'; - final Map apiParams = {}; + final Map apiParams = { + + + }; - final Map apiHeaders = { - 'content-type': 'application/json', - }; + final Map apiHeaders = { + 'content-type': 'application/json', - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + }; - return models.LanguageList.fromMap(res.data); - } -} + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 listCurrencies() async { + final String apiPath = '/locale/currencies'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.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 listLanguages() async { + final String apiPath = '/locale/languages'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LanguageList.fromMap(res.data); + + } +} \ No newline at end of file diff --git a/lib/services/messaging.dart b/lib/services/messaging.dart index ecde5409..e88b18f5 100644 --- a/lib/services/messaging.dart +++ b/lib/services/messaging.dart @@ -3,1374 +3,1251 @@ part of '../dart_appwrite.dart'; /// The Messaging service allows you to send messages to any provider type /// (SMTP, push notification, SMS, etc.). class Messaging extends Service { - Messaging(super.client); - - /// List messages - /// - /// Get a list of all messages from the current Appwrite project. - Future listMessages( - {List? queries, String? search}) async { - final String apiPath = '/messaging/messages'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MessageList.fromMap(res.data); - } - - /// Create email - /// - /// Create a new email message. - Future createEmail( - {required String messageId, - required String subject, - required String content, - List? topics, - List? users, - List? targets, - List? cc, - List? bcc, - List? attachments, - bool? draft, - bool? html, - String? scheduledAt}) async { - final String apiPath = '/messaging/messages/email'; - - final Map apiParams = { - 'messageId': messageId, - 'subject': subject, - 'content': content, - 'topics': topics, - 'users': users, - 'targets': targets, - 'cc': cc, - 'bcc': bcc, - 'attachments': attachments, - 'draft': draft, - 'html': html, - 'scheduledAt': scheduledAt, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Update email - /// - /// Update an email message by its unique ID. - /// - Future updateEmail( - {required String messageId, - List? topics, - List? users, - List? targets, - String? subject, - String? content, - bool? draft, - bool? html, - List? cc, - List? bcc, - String? scheduledAt, - List? attachments}) async { - final String apiPath = '/messaging/messages/email/{messageId}' - .replaceAll('{messageId}', messageId); - - final Map apiParams = { - 'topics': topics, - 'users': users, - 'targets': targets, - 'subject': subject, - 'content': content, - 'draft': draft, - 'html': html, - 'cc': cc, - 'bcc': bcc, - 'scheduledAt': scheduledAt, - 'attachments': attachments, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Create push notification - /// - /// Create a new push notification. - Future createPush( - {required String messageId, - required String title, - required String body, - List? topics, - List? users, - List? targets, - Map? data, - String? action, - String? image, - String? icon, - String? sound, - String? color, - String? tag, - String? badge, - bool? draft, - String? scheduledAt}) async { - final String apiPath = '/messaging/messages/push'; - - final Map apiParams = { - 'messageId': messageId, - 'title': title, - 'body': body, - 'topics': topics, - 'users': users, - 'targets': targets, - 'data': data, - 'action': action, - 'image': image, - 'icon': icon, - 'sound': sound, - 'color': color, - 'tag': tag, - 'badge': badge, - 'draft': draft, - 'scheduledAt': scheduledAt, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Update push notification - /// - /// Update a push notification by its unique ID. - /// - Future updatePush( - {required String messageId, - List? topics, - List? users, - List? targets, - String? title, - String? body, - Map? data, - String? action, - String? image, - String? icon, - String? sound, - String? color, - String? tag, - int? badge, - bool? draft, - String? scheduledAt}) async { - final String apiPath = '/messaging/messages/push/{messageId}' - .replaceAll('{messageId}', messageId); - - final Map apiParams = { - 'topics': topics, - 'users': users, - 'targets': targets, - 'title': title, - 'body': body, - 'data': data, - 'action': action, - 'image': image, - 'icon': icon, - 'sound': sound, - 'color': color, - 'tag': tag, - 'badge': badge, - 'draft': draft, - 'scheduledAt': scheduledAt, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Create SMS - /// - /// Create a new SMS message. - Future createSms( - {required String messageId, - required String content, - List? topics, - List? users, - List? targets, - bool? draft, - String? scheduledAt}) async { - final String apiPath = '/messaging/messages/sms'; - - final Map apiParams = { - 'messageId': messageId, - 'content': content, - 'topics': topics, - 'users': users, - 'targets': targets, - 'draft': draft, - 'scheduledAt': scheduledAt, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Update SMS - /// - /// Update an email message by its unique ID. - /// - Future updateSms( - {required String messageId, - List? topics, - List? users, - List? targets, - String? content, - bool? draft, - String? scheduledAt}) async { - final String apiPath = '/messaging/messages/sms/{messageId}' - .replaceAll('{messageId}', messageId); - - final Map apiParams = { - 'topics': topics, - 'users': users, - 'targets': targets, - 'content': content, - 'draft': draft, - 'scheduledAt': scheduledAt, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Get message - /// - /// Get a message by its unique ID. - /// - Future getMessage({required String messageId}) async { - final String apiPath = - '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Delete message - /// - /// Delete a message. If the message is not a draft or scheduled, but has been - /// sent, this will not recall the message. - Future delete({required String messageId}) async { - final String apiPath = - '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List message logs - /// - /// Get the message activity logs listed by its unique ID. - Future listMessageLogs( - {required String messageId, List? queries}) async { - final String apiPath = '/messaging/messages/{messageId}/logs' - .replaceAll('{messageId}', messageId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// List message targets - /// - /// Get a list of the targets associated with a message. - Future listTargets( - {required String messageId, List? queries}) async { - final String apiPath = '/messaging/messages/{messageId}/targets' - .replaceAll('{messageId}', messageId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.TargetList.fromMap(res.data); - } - - /// List providers - /// - /// Get a list of all providers from the current Appwrite project. - Future listProviders( - {List? queries, String? search}) async { - final String apiPath = '/messaging/providers'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.ProviderList.fromMap(res.data); - } - - /// Create APNS provider - /// - /// Create a new Apple Push Notification service provider. - Future createApnsProvider( - {required String providerId, - required String name, - String? authKey, - String? authKeyId, - String? teamId, - String? bundleId, - bool? sandbox, - bool? enabled}) async { - final String apiPath = '/messaging/providers/apns'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'authKey': authKey, - 'authKeyId': authKeyId, - 'teamId': teamId, - 'bundleId': bundleId, - 'sandbox': sandbox, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update APNS provider - /// - /// Update a Apple Push Notification service provider by its unique ID. - Future updateApnsProvider( - {required String providerId, - String? name, - bool? enabled, - String? authKey, - String? authKeyId, - String? teamId, - String? bundleId, - bool? sandbox}) async { - final String apiPath = '/messaging/providers/apns/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - 'authKey': authKey, - 'authKeyId': authKeyId, - 'teamId': teamId, - 'bundleId': bundleId, - 'sandbox': sandbox, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create FCM provider - /// - /// Create a new Firebase Cloud Messaging provider. - Future createFcmProvider( - {required String providerId, - required String name, - Map? serviceAccountJSON, - bool? enabled}) async { - final String apiPath = '/messaging/providers/fcm'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'serviceAccountJSON': serviceAccountJSON, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update FCM provider - /// - /// Update a Firebase Cloud Messaging provider by its unique ID. - Future updateFcmProvider( - {required String providerId, - String? name, - bool? enabled, - Map? serviceAccountJSON}) async { - final String apiPath = '/messaging/providers/fcm/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - 'serviceAccountJSON': serviceAccountJSON, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Mailgun provider - /// - /// Create a new Mailgun provider. - Future createMailgunProvider( - {required String providerId, - required String name, - String? apiKey, - String? domain, - bool? isEuRegion, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail, - bool? enabled}) async { - final String apiPath = '/messaging/providers/mailgun'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'apiKey': apiKey, - 'domain': domain, - 'isEuRegion': isEuRegion, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Mailgun provider - /// - /// Update a Mailgun provider by its unique ID. - Future updateMailgunProvider( - {required String providerId, - String? name, - String? apiKey, - String? domain, - bool? isEuRegion, - bool? enabled, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail}) async { - final String apiPath = '/messaging/providers/mailgun/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'apiKey': apiKey, - 'domain': domain, - 'isEuRegion': isEuRegion, - 'enabled': enabled, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Msg91 provider - /// - /// Create a new MSG91 provider. - Future createMsg91Provider( - {required String providerId, - required String name, - String? templateId, - String? senderId, - String? authKey, - bool? enabled}) async { - final String apiPath = '/messaging/providers/msg91'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'templateId': templateId, - 'senderId': senderId, - 'authKey': authKey, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Msg91 provider - /// - /// Update a MSG91 provider by its unique ID. - Future updateMsg91Provider( - {required String providerId, - String? name, - bool? enabled, - String? templateId, - String? senderId, - String? authKey}) async { - final String apiPath = '/messaging/providers/msg91/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - 'templateId': templateId, - 'senderId': senderId, - 'authKey': authKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Sendgrid provider - /// - /// Create a new Sendgrid provider. - Future createSendgridProvider( - {required String providerId, - required String name, - String? apiKey, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail, - bool? enabled}) async { - final String apiPath = '/messaging/providers/sendgrid'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'apiKey': apiKey, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Sendgrid provider - /// - /// Update a Sendgrid provider by its unique ID. - Future updateSendgridProvider( - {required String providerId, - String? name, - bool? enabled, - String? apiKey, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail}) async { - final String apiPath = '/messaging/providers/sendgrid/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - 'apiKey': apiKey, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create SMTP provider - /// - /// Create a new SMTP provider. - Future createSmtpProvider( - {required String providerId, - required String name, - required String host, - int? port, - String? username, - String? password, - enums.SmtpEncryption? encryption, - bool? autoTLS, - String? mailer, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail, - bool? enabled}) async { - final String apiPath = '/messaging/providers/smtp'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'host': host, - 'port': port, - 'username': username, - 'password': password, - 'encryption': encryption?.value, - 'autoTLS': autoTLS, - 'mailer': mailer, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update SMTP provider - /// - /// Update a SMTP provider by its unique ID. - Future updateSmtpProvider( - {required String providerId, - String? name, - String? host, - int? port, - String? username, - String? password, - enums.SmtpEncryption? encryption, - bool? autoTLS, - String? mailer, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail, - bool? enabled}) async { - final String apiPath = '/messaging/providers/smtp/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'host': host, - 'port': port, - 'username': username, - 'password': password, - 'encryption': encryption?.value, - 'autoTLS': autoTLS, - 'mailer': mailer, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Telesign provider - /// - /// Create a new Telesign provider. - Future createTelesignProvider( - {required String providerId, - required String name, - String? from, - String? customerId, - String? apiKey, - bool? enabled}) async { - final String apiPath = '/messaging/providers/telesign'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'from': from, - 'customerId': customerId, - 'apiKey': apiKey, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Telesign provider - /// - /// Update a Telesign provider by its unique ID. - Future updateTelesignProvider( - {required String providerId, - String? name, - bool? enabled, - String? customerId, - String? apiKey, - String? from}) async { - final String apiPath = '/messaging/providers/telesign/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - 'customerId': customerId, - 'apiKey': apiKey, - 'from': from, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Textmagic provider - /// - /// Create a new Textmagic provider. - Future createTextmagicProvider( - {required String providerId, - required String name, - String? from, - String? username, - String? apiKey, - bool? enabled}) async { - final String apiPath = '/messaging/providers/textmagic'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'from': from, - 'username': username, - 'apiKey': apiKey, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Textmagic provider - /// - /// Update a Textmagic provider by its unique ID. - Future updateTextmagicProvider( - {required String providerId, - String? name, - bool? enabled, - String? username, - String? apiKey, - String? from}) async { - final String apiPath = '/messaging/providers/textmagic/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - 'username': username, - 'apiKey': apiKey, - 'from': from, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Twilio provider - /// - /// Create a new Twilio provider. - Future createTwilioProvider( - {required String providerId, - required String name, - String? from, - String? accountSid, - String? authToken, - bool? enabled}) async { - final String apiPath = '/messaging/providers/twilio'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'from': from, - 'accountSid': accountSid, - 'authToken': authToken, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Twilio provider - /// - /// Update a Twilio provider by its unique ID. - Future updateTwilioProvider( - {required String providerId, - String? name, - bool? enabled, - String? accountSid, - String? authToken, - String? from}) async { - final String apiPath = '/messaging/providers/twilio/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - 'accountSid': accountSid, - 'authToken': authToken, - 'from': from, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Vonage provider - /// - /// Create a new Vonage provider. - Future createVonageProvider( - {required String providerId, - required String name, - String? from, - String? apiKey, - String? apiSecret, - bool? enabled}) async { - final String apiPath = '/messaging/providers/vonage'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'from': from, - 'apiKey': apiKey, - 'apiSecret': apiSecret, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Vonage provider - /// - /// Update a Vonage provider by its unique ID. - Future updateVonageProvider( - {required String providerId, - String? name, - bool? enabled, - String? apiKey, - String? apiSecret, - String? from}) async { - final String apiPath = '/messaging/providers/vonage/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - 'apiKey': apiKey, - 'apiSecret': apiSecret, - 'from': from, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Get provider - /// - /// Get a provider by its unique ID. - /// - Future getProvider({required String providerId}) async { - final String apiPath = '/messaging/providers/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Delete provider - /// - /// Delete a provider by its unique ID. - Future deleteProvider({required String providerId}) async { - final String apiPath = '/messaging/providers/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List provider logs - /// - /// Get the provider activity logs listed by its unique ID. - Future listProviderLogs( - {required String providerId, List? queries}) async { - final String apiPath = '/messaging/providers/{providerId}/logs' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// List subscriber logs - /// - /// Get the subscriber activity logs listed by its unique ID. - Future listSubscriberLogs( - {required String subscriberId, List? queries}) async { - final String apiPath = '/messaging/subscribers/{subscriberId}/logs' - .replaceAll('{subscriberId}', subscriberId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// List topics - /// - /// Get a list of all topics from the current Appwrite project. - Future listTopics( - {List? queries, String? search}) async { - final String apiPath = '/messaging/topics'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.TopicList.fromMap(res.data); - } - - /// Create topic - /// - /// Create a new topic. - Future createTopic( - {required String topicId, - required String name, - List? subscribe}) async { - final String apiPath = '/messaging/topics'; - - final Map apiParams = { - 'topicId': topicId, - 'name': name, - 'subscribe': subscribe, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Topic.fromMap(res.data); - } - - /// Get topic - /// - /// Get a topic by its unique ID. - /// - Future getTopic({required String topicId}) async { - final String apiPath = - '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Topic.fromMap(res.data); - } - - /// Update topic - /// - /// Update a topic by its unique ID. - /// - Future updateTopic( - {required String topicId, String? name, List? subscribe}) async { - final String apiPath = - '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); - - final Map apiParams = { - 'name': name, - 'subscribe': subscribe, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Topic.fromMap(res.data); - } - - /// Delete topic - /// - /// Delete a topic by its unique ID. - Future deleteTopic({required String topicId}) async { - final String apiPath = - '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List topic logs - /// - /// Get the topic activity logs listed by its unique ID. - Future listTopicLogs( - {required String topicId, List? queries}) async { - final String apiPath = - '/messaging/topics/{topicId}/logs'.replaceAll('{topicId}', topicId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// List subscribers - /// - /// Get a list of all subscribers from the current Appwrite project. - Future listSubscribers( - {required String topicId, List? queries, String? search}) async { - final String apiPath = '/messaging/topics/{topicId}/subscribers' - .replaceAll('{topicId}', topicId); - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SubscriberList.fromMap(res.data); - } - - /// Create subscriber - /// - /// Create a new subscriber. - Future createSubscriber( - {required String topicId, - required String subscriberId, - required String targetId}) async { - final String apiPath = '/messaging/topics/{topicId}/subscribers' - .replaceAll('{topicId}', topicId); - - final Map apiParams = { - 'subscriberId': subscriberId, - 'targetId': targetId, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Subscriber.fromMap(res.data); - } - - /// Get subscriber - /// - /// Get a subscriber by its unique ID. - /// - Future getSubscriber( - {required String topicId, required String subscriberId}) async { - final String apiPath = - '/messaging/topics/{topicId}/subscribers/{subscriberId}' - .replaceAll('{topicId}', topicId) - .replaceAll('{subscriberId}', subscriberId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Subscriber.fromMap(res.data); - } - - /// Delete subscriber - /// - /// Delete a subscriber by its unique ID. - Future deleteSubscriber( - {required String topicId, required String subscriberId}) async { - final String apiPath = - '/messaging/topics/{topicId}/subscribers/{subscriberId}' - .replaceAll('{topicId}', topicId) - .replaceAll('{subscriberId}', subscriberId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } -} + Messaging(super.client); + + /// List messages + /// + /// Get a list of all messages from the current Appwrite project. + Future listMessages({List? queries, String? search}) async { + final String apiPath = '/messaging/messages'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MessageList.fromMap(res.data); + + } + + /// Create email + /// + /// Create a new email message. + Future createEmail({required String messageId, required String subject, required String content, List? topics, List? users, List? targets, List? cc, List? bcc, List? attachments, bool? draft, bool? html, String? scheduledAt}) async { + final String apiPath = '/messaging/messages/email'; + + final Map apiParams = { + + 'messageId': messageId, +'subject': subject, +'content': content, +'topics': topics, +'users': users, +'targets': targets, +'cc': cc, +'bcc': bcc, +'attachments': attachments, +'draft': draft, +'html': html, +'scheduledAt': scheduledAt, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Update email + /// + /// Update an email message by its unique ID. + /// + Future updateEmail({required String messageId, List? topics, List? users, List? targets, String? subject, String? content, bool? draft, bool? html, List? cc, List? bcc, String? scheduledAt, List? attachments}) async { + final String apiPath = '/messaging/messages/email/{messageId}'.replaceAll('{messageId}', messageId); + + final Map apiParams = { + + 'topics': topics, +'users': users, +'targets': targets, +'subject': subject, +'content': content, +'draft': draft, +'html': html, +'cc': cc, +'bcc': bcc, +'scheduledAt': scheduledAt, +'attachments': attachments, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Create push notification + /// + /// Create a new push notification. + Future createPush({required String messageId, required String title, required String body, List? topics, List? users, List? targets, Map? data, String? action, String? image, String? icon, String? sound, String? color, String? tag, String? badge, bool? draft, String? scheduledAt}) async { + final String apiPath = '/messaging/messages/push'; + + final Map apiParams = { + + 'messageId': messageId, +'title': title, +'body': body, +'topics': topics, +'users': users, +'targets': targets, +'data': data, +'action': action, +'image': image, +'icon': icon, +'sound': sound, +'color': color, +'tag': tag, +'badge': badge, +'draft': draft, +'scheduledAt': scheduledAt, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Update push notification + /// + /// Update a push notification by its unique ID. + /// + Future updatePush({required String messageId, List? topics, List? users, List? targets, String? title, String? body, Map? data, String? action, String? image, String? icon, String? sound, String? color, String? tag, int? badge, bool? draft, String? scheduledAt}) async { + final String apiPath = '/messaging/messages/push/{messageId}'.replaceAll('{messageId}', messageId); + + final Map apiParams = { + + 'topics': topics, +'users': users, +'targets': targets, +'title': title, +'body': body, +'data': data, +'action': action, +'image': image, +'icon': icon, +'sound': sound, +'color': color, +'tag': tag, +'badge': badge, +'draft': draft, +'scheduledAt': scheduledAt, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Create SMS + /// + /// Create a new SMS message. + Future createSms({required String messageId, required String content, List? topics, List? users, List? targets, bool? draft, String? scheduledAt}) async { + final String apiPath = '/messaging/messages/sms'; + + final Map apiParams = { + + 'messageId': messageId, +'content': content, +'topics': topics, +'users': users, +'targets': targets, +'draft': draft, +'scheduledAt': scheduledAt, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Update SMS + /// + /// Update an email message by its unique ID. + /// + Future updateSms({required String messageId, List? topics, List? users, List? targets, String? content, bool? draft, String? scheduledAt}) async { + final String apiPath = '/messaging/messages/sms/{messageId}'.replaceAll('{messageId}', messageId); + + final Map apiParams = { + + 'topics': topics, +'users': users, +'targets': targets, +'content': content, +'draft': draft, +'scheduledAt': scheduledAt, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Get message + /// + /// Get a message by its unique ID. + /// + Future getMessage({required String messageId}) async { + final String apiPath = '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Delete message + /// + /// Delete a message. If the message is not a draft or scheduled, but has been + /// sent, this will not recall the message. + Future delete({required String messageId}) async { + final String apiPath = '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List message logs + /// + /// Get the message activity logs listed by its unique ID. + Future listMessageLogs({required String messageId, List? queries}) async { + final String apiPath = '/messaging/messages/{messageId}/logs'.replaceAll('{messageId}', messageId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// List message targets + /// + /// Get a list of the targets associated with a message. + Future listTargets({required String messageId, List? queries}) async { + final String apiPath = '/messaging/messages/{messageId}/targets'.replaceAll('{messageId}', messageId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.TargetList.fromMap(res.data); + + } + + /// List providers + /// + /// Get a list of all providers from the current Appwrite project. + Future listProviders({List? queries, String? search}) async { + final String apiPath = '/messaging/providers'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.ProviderList.fromMap(res.data); + + } + + /// Create APNS provider + /// + /// Create a new Apple Push Notification service provider. + Future createApnsProvider({required String providerId, required String name, String? authKey, String? authKeyId, String? teamId, String? bundleId, bool? sandbox, bool? enabled}) async { + final String apiPath = '/messaging/providers/apns'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'authKey': authKey, +'authKeyId': authKeyId, +'teamId': teamId, +'bundleId': bundleId, +'sandbox': sandbox, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update APNS provider + /// + /// Update a Apple Push Notification service provider by its unique ID. + Future updateApnsProvider({required String providerId, String? name, bool? enabled, String? authKey, String? authKeyId, String? teamId, String? bundleId, bool? sandbox}) async { + final String apiPath = '/messaging/providers/apns/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, +'authKey': authKey, +'authKeyId': authKeyId, +'teamId': teamId, +'bundleId': bundleId, +'sandbox': sandbox, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create FCM provider + /// + /// Create a new Firebase Cloud Messaging provider. + Future createFcmProvider({required String providerId, required String name, Map? serviceAccountJSON, bool? enabled}) async { + final String apiPath = '/messaging/providers/fcm'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'serviceAccountJSON': serviceAccountJSON, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update FCM provider + /// + /// Update a Firebase Cloud Messaging provider by its unique ID. + Future updateFcmProvider({required String providerId, String? name, bool? enabled, Map? serviceAccountJSON}) async { + final String apiPath = '/messaging/providers/fcm/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, +'serviceAccountJSON': serviceAccountJSON, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Mailgun provider + /// + /// Create a new Mailgun provider. + Future createMailgunProvider({required String providerId, required String name, String? apiKey, String? domain, bool? isEuRegion, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { + final String apiPath = '/messaging/providers/mailgun'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'apiKey': apiKey, +'domain': domain, +'isEuRegion': isEuRegion, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Mailgun provider + /// + /// Update a Mailgun provider by its unique ID. + Future updateMailgunProvider({required String providerId, String? name, String? apiKey, String? domain, bool? isEuRegion, bool? enabled, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail}) async { + final String apiPath = '/messaging/providers/mailgun/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'apiKey': apiKey, +'domain': domain, +'isEuRegion': isEuRegion, +'enabled': enabled, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Msg91 provider + /// + /// Create a new MSG91 provider. + Future createMsg91Provider({required String providerId, required String name, String? templateId, String? senderId, String? authKey, bool? enabled}) async { + final String apiPath = '/messaging/providers/msg91'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'templateId': templateId, +'senderId': senderId, +'authKey': authKey, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Msg91 provider + /// + /// Update a MSG91 provider by its unique ID. + Future updateMsg91Provider({required String providerId, String? name, bool? enabled, String? templateId, String? senderId, String? authKey}) async { + final String apiPath = '/messaging/providers/msg91/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, +'templateId': templateId, +'senderId': senderId, +'authKey': authKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Sendgrid provider + /// + /// Create a new Sendgrid provider. + Future createSendgridProvider({required String providerId, required String name, String? apiKey, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { + final String apiPath = '/messaging/providers/sendgrid'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'apiKey': apiKey, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Sendgrid provider + /// + /// Update a Sendgrid provider by its unique ID. + Future updateSendgridProvider({required String providerId, String? name, bool? enabled, String? apiKey, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail}) async { + final String apiPath = '/messaging/providers/sendgrid/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, +'apiKey': apiKey, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create SMTP provider + /// + /// Create a new SMTP provider. + Future createSmtpProvider({required String providerId, required String name, required String host, int? port, String? username, String? password, enums.SmtpEncryption? encryption, bool? autoTLS, String? mailer, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { + final String apiPath = '/messaging/providers/smtp'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'host': host, +'port': port, +'username': username, +'password': password, +'encryption': encryption?.value, +'autoTLS': autoTLS, +'mailer': mailer, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update SMTP provider + /// + /// Update a SMTP provider by its unique ID. + Future updateSmtpProvider({required String providerId, String? name, String? host, int? port, String? username, String? password, enums.SmtpEncryption? encryption, bool? autoTLS, String? mailer, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { + final String apiPath = '/messaging/providers/smtp/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'host': host, +'port': port, +'username': username, +'password': password, +'encryption': encryption?.value, +'autoTLS': autoTLS, +'mailer': mailer, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Telesign provider + /// + /// Create a new Telesign provider. + Future createTelesignProvider({required String providerId, required String name, String? from, String? customerId, String? apiKey, bool? enabled}) async { + final String apiPath = '/messaging/providers/telesign'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'from': from, +'customerId': customerId, +'apiKey': apiKey, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Telesign provider + /// + /// Update a Telesign provider by its unique ID. + Future updateTelesignProvider({required String providerId, String? name, bool? enabled, String? customerId, String? apiKey, String? from}) async { + final String apiPath = '/messaging/providers/telesign/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, +'customerId': customerId, +'apiKey': apiKey, +'from': from, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Textmagic provider + /// + /// Create a new Textmagic provider. + Future createTextmagicProvider({required String providerId, required String name, String? from, String? username, String? apiKey, bool? enabled}) async { + final String apiPath = '/messaging/providers/textmagic'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'from': from, +'username': username, +'apiKey': apiKey, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Textmagic provider + /// + /// Update a Textmagic provider by its unique ID. + Future updateTextmagicProvider({required String providerId, String? name, bool? enabled, String? username, String? apiKey, String? from}) async { + final String apiPath = '/messaging/providers/textmagic/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, +'username': username, +'apiKey': apiKey, +'from': from, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Twilio provider + /// + /// Create a new Twilio provider. + Future createTwilioProvider({required String providerId, required String name, String? from, String? accountSid, String? authToken, bool? enabled}) async { + final String apiPath = '/messaging/providers/twilio'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'from': from, +'accountSid': accountSid, +'authToken': authToken, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Twilio provider + /// + /// Update a Twilio provider by its unique ID. + Future updateTwilioProvider({required String providerId, String? name, bool? enabled, String? accountSid, String? authToken, String? from}) async { + final String apiPath = '/messaging/providers/twilio/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, +'accountSid': accountSid, +'authToken': authToken, +'from': from, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Vonage provider + /// + /// Create a new Vonage provider. + Future createVonageProvider({required String providerId, required String name, String? from, String? apiKey, String? apiSecret, bool? enabled}) async { + final String apiPath = '/messaging/providers/vonage'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'from': from, +'apiKey': apiKey, +'apiSecret': apiSecret, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Vonage provider + /// + /// Update a Vonage provider by its unique ID. + Future updateVonageProvider({required String providerId, String? name, bool? enabled, String? apiKey, String? apiSecret, String? from}) async { + final String apiPath = '/messaging/providers/vonage/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, +'apiKey': apiKey, +'apiSecret': apiSecret, +'from': from, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Get provider + /// + /// Get a provider by its unique ID. + /// + Future getProvider({required String providerId}) async { + final String apiPath = '/messaging/providers/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Delete provider + /// + /// Delete a provider by its unique ID. + Future deleteProvider({required String providerId}) async { + final String apiPath = '/messaging/providers/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List provider logs + /// + /// Get the provider activity logs listed by its unique ID. + Future listProviderLogs({required String providerId, List? queries}) async { + final String apiPath = '/messaging/providers/{providerId}/logs'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// List subscriber logs + /// + /// Get the subscriber activity logs listed by its unique ID. + Future listSubscriberLogs({required String subscriberId, List? queries}) async { + final String apiPath = '/messaging/subscribers/{subscriberId}/logs'.replaceAll('{subscriberId}', subscriberId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// List topics + /// + /// Get a list of all topics from the current Appwrite project. + Future listTopics({List? queries, String? search}) async { + final String apiPath = '/messaging/topics'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.TopicList.fromMap(res.data); + + } + + /// Create topic + /// + /// Create a new topic. + Future createTopic({required String topicId, required String name, List? subscribe}) async { + final String apiPath = '/messaging/topics'; + + final Map apiParams = { + + 'topicId': topicId, +'name': name, +'subscribe': subscribe, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Topic.fromMap(res.data); + + } + + /// Get topic + /// + /// Get a topic by its unique ID. + /// + Future getTopic({required String topicId}) async { + final String apiPath = '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Topic.fromMap(res.data); + + } + + /// Update topic + /// + /// Update a topic by its unique ID. + /// + Future updateTopic({required String topicId, String? name, List? subscribe}) async { + final String apiPath = '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); + + final Map apiParams = { + + 'name': name, +'subscribe': subscribe, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Topic.fromMap(res.data); + + } + + /// Delete topic + /// + /// Delete a topic by its unique ID. + Future deleteTopic({required String topicId}) async { + final String apiPath = '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List topic logs + /// + /// Get the topic activity logs listed by its unique ID. + Future listTopicLogs({required String topicId, List? queries}) async { + final String apiPath = '/messaging/topics/{topicId}/logs'.replaceAll('{topicId}', topicId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// List subscribers + /// + /// Get a list of all subscribers from the current Appwrite project. + Future listSubscribers({required String topicId, List? queries, String? search}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers'.replaceAll('{topicId}', topicId); + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SubscriberList.fromMap(res.data); + + } + + /// Create subscriber + /// + /// Create a new subscriber. + Future createSubscriber({required String topicId, required String subscriberId, required String targetId}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers'.replaceAll('{topicId}', topicId); + + final Map apiParams = { + + 'subscriberId': subscriberId, +'targetId': targetId, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Subscriber.fromMap(res.data); + + } + + /// Get subscriber + /// + /// Get a subscriber by its unique ID. + /// + Future getSubscriber({required String topicId, required String subscriberId}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replaceAll('{topicId}', topicId).replaceAll('{subscriberId}', subscriberId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Subscriber.fromMap(res.data); + + } + + /// Delete subscriber + /// + /// Delete a subscriber by its unique ID. + Future deleteSubscriber({required String topicId, required String subscriberId}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replaceAll('{topicId}', topicId).replaceAll('{subscriberId}', subscriberId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } +} \ No newline at end of file diff --git a/lib/services/storage.dart b/lib/services/storage.dart index 12b86227..6ffbeafe 100644 --- a/lib/services/storage.dart +++ b/lib/services/storage.dart @@ -2,382 +2,356 @@ part of '../dart_appwrite.dart'; /// The Storage service allows you to manage your project files. class Storage extends Service { - Storage(super.client); - - /// List buckets - /// - /// Get a list of all the storage buckets. You can use the query params to - /// filter your results. - Future listBuckets( - {List? queries, String? search}) async { - final String apiPath = '/storage/buckets'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.BucketList.fromMap(res.data); - } - - /// Create bucket - /// - /// Create a new storage bucket. - Future createBucket( - {required String bucketId, - required String name, - List? permissions, - bool? fileSecurity, - bool? enabled, - int? maximumFileSize, - List? allowedFileExtensions, - enums.Compression? compression, - bool? encryption, - bool? antivirus}) async { - final String apiPath = '/storage/buckets'; - - final Map apiParams = { - 'bucketId': bucketId, - 'name': name, - 'permissions': permissions, - 'fileSecurity': fileSecurity, - 'enabled': enabled, - 'maximumFileSize': maximumFileSize, - 'allowedFileExtensions': allowedFileExtensions, - 'compression': compression?.value, - 'encryption': encryption, - 'antivirus': antivirus, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Bucket.fromMap(res.data); - } - - /// Get bucket - /// - /// Get a storage bucket by its unique ID. This endpoint response returns a - /// JSON object with the storage bucket metadata. - Future getBucket({required String bucketId}) async { - final String apiPath = - '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Bucket.fromMap(res.data); - } - - /// Update bucket - /// - /// Update a storage bucket by its unique ID. - Future updateBucket( - {required String bucketId, - required String name, - List? permissions, - bool? fileSecurity, - bool? enabled, - int? maximumFileSize, - List? allowedFileExtensions, - enums.Compression? compression, - bool? encryption, - bool? antivirus}) async { - final String apiPath = - '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); - - final Map apiParams = { - 'name': name, - 'permissions': permissions, - 'fileSecurity': fileSecurity, - 'enabled': enabled, - 'maximumFileSize': maximumFileSize, - 'allowedFileExtensions': allowedFileExtensions, - 'compression': compression?.value, - 'encryption': encryption, - 'antivirus': antivirus, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Bucket.fromMap(res.data); - } - - /// Delete bucket - /// - /// Delete a storage bucket by its unique ID. - Future deleteBucket({required String bucketId}) async { - final String apiPath = - '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List files - /// - /// Get a list of all the user files. You can use the query params to filter - /// your results. - Future listFiles( - {required String bucketId, List? queries, String? search}) async { - final String apiPath = - '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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](https://appwrite.io/docs/server/storage#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? permissions, - Function(UploadProgress)? onProgress}) async { - final String apiPath = - '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); - - final Map apiParams = { - 'fileId': fileId, - 'file': file, - 'permissions': permissions, - }; - - final Map apiHeaders = { - 'content-type': 'multipart/form-data', - }; - - String idParamName = ''; - idParamName = 'fileId'; - final paramName = 'file'; - final res = await client.chunkedUpload( - path: apiPath, - params: apiParams, - paramName: paramName, - idParamName: idParamName, - headers: apiHeaders, - onProgress: onProgress, - ); - - 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 { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.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, - String? name, - List? permissions}) async { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map apiParams = { - 'name': name, - 'permissions': permissions, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// 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 apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map params = { - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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, - enums.ImageGravity? gravity, - int? quality, - int? borderWidth, - String? borderColor, - int? borderRadius, - double? opacity, - int? rotation, - String? background, - enums.ImageFormat? output}) async { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map params = { - 'width': width, - 'height': height, - 'gravity': gravity?.value, - 'quality': quality, - 'borderWidth': borderWidth, - 'borderColor': borderColor, - 'borderRadius': borderRadius, - 'opacity': opacity, - 'rotation': rotation, - 'background': background, - 'output': output?.value, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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 { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map params = { - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: params, responseType: ResponseType.bytes); - return res.data; - } -} + Storage(super.client); + + /// List buckets + /// + /// Get a list of all the storage buckets. You can use the query params to + /// filter your results. + Future listBuckets({List? queries, String? search}) async { + final String apiPath = '/storage/buckets'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.BucketList.fromMap(res.data); + + } + + /// Create bucket + /// + /// Create a new storage bucket. + Future createBucket({required String bucketId, required String name, List? permissions, bool? fileSecurity, bool? enabled, int? maximumFileSize, List? allowedFileExtensions, enums.Compression? compression, bool? encryption, bool? antivirus}) async { + final String apiPath = '/storage/buckets'; + + final Map apiParams = { + + 'bucketId': bucketId, +'name': name, +'permissions': permissions, +'fileSecurity': fileSecurity, +'enabled': enabled, +'maximumFileSize': maximumFileSize, +'allowedFileExtensions': allowedFileExtensions, +'compression': compression?.value, +'encryption': encryption, +'antivirus': antivirus, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Bucket.fromMap(res.data); + + } + + /// Get bucket + /// + /// Get a storage bucket by its unique ID. This endpoint response returns a + /// JSON object with the storage bucket metadata. + Future getBucket({required String bucketId}) async { + final String apiPath = '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Bucket.fromMap(res.data); + + } + + /// Update bucket + /// + /// Update a storage bucket by its unique ID. + Future updateBucket({required String bucketId, required String name, List? permissions, bool? fileSecurity, bool? enabled, int? maximumFileSize, List? allowedFileExtensions, enums.Compression? compression, bool? encryption, bool? antivirus}) async { + final String apiPath = '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); + + final Map apiParams = { + + 'name': name, +'permissions': permissions, +'fileSecurity': fileSecurity, +'enabled': enabled, +'maximumFileSize': maximumFileSize, +'allowedFileExtensions': allowedFileExtensions, +'compression': compression?.value, +'encryption': encryption, +'antivirus': antivirus, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Bucket.fromMap(res.data); + + } + + /// Delete bucket + /// + /// Delete a storage bucket by its unique ID. + Future deleteBucket({required String bucketId}) async { + final String apiPath = '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List files + /// + /// Get a list of all the user files. You can use the query params to filter + /// your results. + Future listFiles({required String bucketId, List? queries, String? search}) async { + final String apiPath = '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + 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](https://appwrite.io/docs/server/storage#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 Payload file, List? permissions, Function(UploadProgress)? onProgress}) async { + final String apiPath = '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); + + final Map apiParams = { + + 'fileId': fileId, +'file': file, +'permissions': permissions, + + }; + + final Map apiHeaders = { + 'content-type': 'multipart/form-data', + + }; + + String idParamName = ''; + idParamName = 'fileId'; + final paramName = 'file'; + final res = await client.chunkedUpload( + path: apiPath, + params: apiParams, + paramName: paramName, + idParamName: idParamName, + headers: apiHeaders, + onProgress: onProgress, + ); + + 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 { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.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, String? name, List? permissions}) async { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map apiParams = { + + 'name': name, +'permissions': permissions, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// 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 apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map params = { + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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, enums.ImageGravity? gravity, int? quality, int? borderWidth, String? borderColor, int? borderRadius, double? opacity, int? rotation, String? background, enums.ImageFormat? output}) async { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map params = { + 'width': width, +'height': height, +'gravity': gravity?.value, +'quality': quality, +'borderWidth': borderWidth, +'borderColor': borderColor, +'borderRadius': borderRadius, +'opacity': opacity, +'rotation': rotation, +'background': background, +'output': output?.value, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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 { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map params = { + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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 27f5aff5..4d7ee475 100644 --- a/lib/services/teams.dart +++ b/lib/services/teams.dart @@ -3,340 +3,350 @@ part of '../dart_appwrite.dart'; /// 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(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. - Future list({List? queries, String? search}) async { - final String apiPath = '/teams'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams'; - - final Map apiParams = { - 'teamId': teamId, - 'name': name, - 'roles': roles, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Team.fromMap(res.data); - } - - /// Update name - /// - /// Update the team's name by its unique ID. - Future updateName( - {required String teamId, required String name}) async { - final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); - - final Map apiParams = { - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List 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 listMemberships( - {required String teamId, List? queries, String? search}) async { - final String apiPath = - '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MembershipList.fromMap(res.data); - } - - /// Create team membership - /// - /// Invite a new member to join your team. Provide an ID for existing users, or - /// invite unregistered users using an email or phone number. If initiated from - /// a Client SDK, Appwrite will send an email or sms with a link to join the - /// team to the invited user, and an account will be created for them if one - /// doesn't exist. If initiated from a Server SDK, the new member will be added - /// automatically to the team. - /// - /// You only need to provide one of a user ID, email, or phone number. Appwrite - /// will prioritize accepting the user ID > email > phone number if you provide - /// more than one of these parameters. - /// - /// Use the `url` parameter to redirect the user from the invitation email to - /// your app. After the user is redirected, use the [Update Team Membership - /// Status](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus) - /// 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) - /// Appwrite will accept the only redirect URLs under the domains you have - /// added as a platform on the Appwrite Console. - /// - Future createMembership( - {required String teamId, - required List roles, - String? email, - String? userId, - String? phone, - String? url, - String? name}) async { - final String apiPath = - '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); - - final Map apiParams = { - 'email': email, - 'userId': userId, - 'phone': phone, - 'roles': roles, - 'url': url, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams/{teamId}/memberships/{membershipId}' - .replaceAll('{teamId}', teamId) - .replaceAll('{membershipId}', membershipId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Membership.fromMap(res.data); - } - - /// Update membership - /// - /// 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](https://appwrite.io/docs/permissions). - /// - Future updateMembership( - {required String teamId, - required String membershipId, - required List roles}) async { - final String apiPath = '/teams/{teamId}/memberships/{membershipId}' - .replaceAll('{teamId}', teamId) - .replaceAll('{membershipId}', membershipId); - - final Map apiParams = { - 'roles': roles, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams/{teamId}/memberships/{membershipId}' - .replaceAll('{teamId}', teamId) - .replaceAll('{membershipId}', membershipId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// 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 apiPath = '/teams/{teamId}/memberships/{membershipId}/status' - .replaceAll('{teamId}', teamId) - .replaceAll('{membershipId}', membershipId); - - final Map apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Membership.fromMap(res.data); - } - - /// Get team preferences - /// - /// Get the team's shared preferences by its unique ID. If a preference doesn't - /// need to be shared by all team members, prefer storing them in [user - /// preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs). - Future getPrefs({required String teamId}) async { - final String apiPath = - '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - } - - /// Update preferences - /// - /// Update the team's preferences by its unique ID. The object you pass is - /// stored as is and replaces any previous value. The maximum allowed prefs - /// size is 64kB and throws an error if exceeded. - Future updatePrefs( - {required String teamId, required Map prefs}) async { - final String apiPath = - '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); - - final Map apiParams = { - 'prefs': prefs, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - } -} + Teams(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. + Future list({List? queries, String? search}) async { + final String apiPath = '/teams'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams'; + + final Map apiParams = { + + 'teamId': teamId, +'name': name, +'roles': roles, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Team.fromMap(res.data); + + } + + /// Update name + /// + /// Update the team's name by its unique ID. + Future updateName({required String teamId, required String name}) async { + final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + + 'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List 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 listMemberships({required String teamId, List? queries, String? search}) async { + final String apiPath = '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MembershipList.fromMap(res.data); + + } + + /// Create team membership + /// + /// Invite a new member to join your team. Provide an ID for existing users, or + /// invite unregistered users using an email or phone number. If initiated from + /// a Client SDK, Appwrite will send an email or sms with a link to join the + /// team to the invited user, and an account will be created for them if one + /// doesn't exist. If initiated from a Server SDK, the new member will be added + /// automatically to the team. + /// + /// You only need to provide one of a user ID, email, or phone number. Appwrite + /// will prioritize accepting the user ID > email > phone number if you provide + /// more than one of these parameters. + /// + /// Use the `url` parameter to redirect the user from the invitation email to + /// your app. After the user is redirected, use the [Update Team Membership + /// Status](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus) + /// 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) + /// Appwrite will accept the only redirect URLs under the domains you have + /// added as a platform on the Appwrite Console. + /// + Future createMembership({required String teamId, required List roles, String? email, String? userId, String? phone, String? url, String? name}) async { + final String apiPath = '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + + 'email': email, +'userId': userId, +'phone': phone, +'roles': roles, +'url': url, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Membership.fromMap(res.data); + + } + + /// Update membership + /// + /// 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](https://appwrite.io/docs/permissions). + /// + Future updateMembership({required String teamId, required String membershipId, required List roles}) async { + final String apiPath = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); + + final Map apiParams = { + + 'roles': roles, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// 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 apiPath = '/teams/{teamId}/memberships/{membershipId}/status'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); + + final Map apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Membership.fromMap(res.data); + + } + + /// Get team preferences + /// + /// Get the team's shared preferences by its unique ID. If a preference doesn't + /// need to be shared by all team members, prefer storing them in [user + /// preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs). + Future getPrefs({required String teamId}) async { + final String apiPath = '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + + } + + /// Update preferences + /// + /// Update the team's preferences by its unique ID. The object you pass is + /// stored as is and replaces any previous value. The maximum allowed prefs + /// size is 64kB and throws an error if exceeded. + Future updatePrefs({required String teamId, required Map prefs}) async { + final String apiPath = '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + + 'prefs': prefs, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + + } +} \ No newline at end of file diff --git a/lib/services/users.dart b/lib/services/users.dart index 74c375eb..ac4bac14 100644 --- a/lib/services/users.dart +++ b/lib/services/users.dart @@ -2,1023 +2,1055 @@ part of '../dart_appwrite.dart'; /// The Users service allows you to manage your project users. class Users extends Service { - Users(super.client); - - /// List users - /// - /// Get a list of all the project's users. You can use the query params to - /// filter your results. - Future list({List? queries, String? search}) async { - final String apiPath = '/users'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.UserList.fromMap(res.data); - } - - /// Create user - /// - /// Create a new user. - Future create( - {required String userId, - String? email, - String? phone, - String? password, - String? name}) async { - final String apiPath = '/users'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'phone': phone, - 'password': password, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with Argon2 password - /// - /// Create a new user. Password provided must be hashed with the - /// [Argon2](https://en.wikipedia.org/wiki/Argon2) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createArgon2User( - {required String userId, - required String email, - required String password, - String? name}) async { - final String apiPath = '/users/argon2'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with bcrypt password - /// - /// Create a new user. Password provided must be hashed with the - /// [Bcrypt](https://en.wikipedia.org/wiki/Bcrypt) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createBcryptUser( - {required String userId, - required String email, - required String password, - String? name}) async { - final String apiPath = '/users/bcrypt'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// List Identities - /// - /// Get identities for all users. - Future listIdentities( - {List? queries, String? search}) async { - final String apiPath = '/users/identities'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.IdentityList.fromMap(res.data); - } - - /// Delete identity - /// - /// Delete an identity by its unique ID. - Future deleteIdentity({required String identityId}) async { - final String apiPath = - '/users/identities/{identityId}'.replaceAll('{identityId}', identityId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Create user with MD5 password - /// - /// Create a new user. Password provided must be hashed with the - /// [MD5](https://en.wikipedia.org/wiki/MD5) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createMD5User( - {required String userId, - required String email, - required String password, - String? name}) async { - final String apiPath = '/users/md5'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with PHPass password - /// - /// Create a new user. Password provided must be hashed with the - /// [PHPass](https://www.openwall.com/phpass/) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createPHPassUser( - {required String userId, - required String email, - required String password, - String? name}) async { - final String apiPath = '/users/phpass'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with Scrypt password - /// - /// Create a new user. Password provided must be hashed with the - /// [Scrypt](https://github.com/Tarsnap/scrypt) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createScryptUser( - {required String userId, - required String email, - required String password, - required String passwordSalt, - required int passwordCpu, - required int passwordMemory, - required int passwordParallel, - required int passwordLength, - String? name}) async { - final String apiPath = '/users/scrypt'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'passwordSalt': passwordSalt, - 'passwordCpu': passwordCpu, - 'passwordMemory': passwordMemory, - 'passwordParallel': passwordParallel, - 'passwordLength': passwordLength, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with Scrypt modified password - /// - /// Create a new user. Password provided must be hashed with the [Scrypt - /// Modified](https://gist.github.com/Meldiron/eecf84a0225eccb5a378d45bb27462cc) - /// algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createScryptModifiedUser( - {required String userId, - required String email, - required String password, - required String passwordSalt, - required String passwordSaltSeparator, - required String passwordSignerKey, - String? name}) async { - final String apiPath = '/users/scrypt-modified'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'passwordSalt': passwordSalt, - 'passwordSaltSeparator': passwordSaltSeparator, - 'passwordSignerKey': passwordSignerKey, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with SHA password - /// - /// Create a new user. Password provided must be hashed with the - /// [SHA](https://en.wikipedia.org/wiki/Secure_Hash_Algorithm) algorithm. Use - /// the [POST /users](https://appwrite.io/docs/server/users#usersCreate) - /// endpoint to create users with a plain text password. - Future createSHAUser( - {required String userId, - required String email, - required String password, - enums.PasswordHash? passwordVersion, - String? name}) async { - final String apiPath = '/users/sha'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'passwordVersion': passwordVersion?.value, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Get user - /// - /// Get a user by its unique ID. - Future get({required String userId}) async { - final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Delete user - /// - /// Delete a user by its unique ID, thereby releasing it's ID. Since ID is - /// released and can be reused, all user-related resources like documents or - /// storage files should be deleted before user deletion. If you want to keep - /// ID reserved, use the - /// [updateStatus](https://appwrite.io/docs/server/users#usersUpdateStatus) - /// endpoint instead. - Future delete({required String userId}) async { - final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Update email - /// - /// Update the user email by its unique ID. - Future updateEmail( - {required String userId, required String email}) async { - final String apiPath = - '/users/{userId}/email'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'email': email, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user JWT - /// - /// Use this endpoint to create a JSON Web Token for user by its unique ID. You - /// can use the resulting JWT to authenticate on behalf of the user. The JWT - /// secret will become invalid if the session it uses gets deleted. - Future createJWT( - {required String userId, String? sessionId, int? duration}) async { - final String apiPath = - '/users/{userId}/jwts'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'sessionId': sessionId, - 'duration': duration, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Jwt.fromMap(res.data); - } - - /// Update user labels - /// - /// Update the user labels by its unique ID. - /// - /// Labels can be used to grant access to resources. While teams are a way for - /// user's to share access to a resource, labels can be defined by the - /// developer to grant access without an invitation. See the [Permissions - /// docs](https://appwrite.io/docs/permissions) for more info. - Future updateLabels( - {required String userId, required List labels}) async { - final String apiPath = - '/users/{userId}/labels'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'labels': labels, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// List user logs - /// - /// Get the user activity logs list by its unique ID. - Future listLogs( - {required String userId, List? queries}) async { - final String apiPath = - '/users/{userId}/logs'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// List user memberships - /// - /// Get the user membership list by its unique ID. - Future listMemberships( - {required String userId}) async { - final String apiPath = - '/users/{userId}/memberships'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MembershipList.fromMap(res.data); - } - - /// Update MFA - /// - /// Enable or disable MFA on a user account. - Future updateMfa( - {required String userId, required bool mfa}) async { - final String apiPath = '/users/{userId}/mfa'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'mfa': mfa, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Delete Authenticator - /// - /// Delete an authenticator app. - Future deleteMfaAuthenticator( - {required String userId, required enums.AuthenticatorType type}) async { - final String apiPath = '/users/{userId}/mfa/authenticators/{type}' - .replaceAll('{userId}', userId) - .replaceAll('{type}', type.value); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// List Factors - /// - /// List the factors available on the account to be used as a MFA challange. - Future listMfaFactors({required String userId}) async { - final String apiPath = - '/users/{userId}/mfa/factors'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaFactors.fromMap(res.data); - } - - /// Get MFA Recovery Codes - /// - /// Get recovery codes that can be used as backup for MFA flow by User ID. - /// Before getting codes, they must be generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. - Future getMfaRecoveryCodes( - {required String userId}) async { - final String apiPath = - '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Regenerate MFA Recovery Codes - /// - /// Regenerate recovery codes that can be used as backup for MFA flow by User - /// ID. Before regenerating codes, they must be first generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. - Future updateMfaRecoveryCodes( - {required String userId}) async { - final String apiPath = - '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Create MFA Recovery Codes - /// - /// Generate recovery codes used as backup for MFA flow for User ID. Recovery - /// codes can be used as a MFA verification type in - /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) - /// method by client SDK. - Future createMfaRecoveryCodes( - {required String userId}) async { - final String apiPath = - '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Update name - /// - /// Update the user name by its unique ID. - Future updateName( - {required String userId, required String name}) async { - final String apiPath = - '/users/{userId}/name'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update password - /// - /// Update the user password by its unique ID. - Future updatePassword( - {required String userId, required String password}) async { - final String apiPath = - '/users/{userId}/password'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'password': password, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update phone - /// - /// Update the user phone by its unique ID. - Future updatePhone( - {required String userId, required String number}) async { - final String apiPath = - '/users/{userId}/phone'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'number': number, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Get user preferences - /// - /// Get the user preferences by its unique ID. - Future getPrefs({required String userId}) async { - final String apiPath = - '/users/{userId}/prefs'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - } - - /// Update user preferences - /// - /// Update the user preferences by its unique ID. 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 String userId, required Map prefs}) async { - final String apiPath = - '/users/{userId}/prefs'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'prefs': prefs, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - } - - /// List user sessions - /// - /// Get the user sessions list by its unique ID. - Future listSessions({required String userId}) async { - final String apiPath = - '/users/{userId}/sessions'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SessionList.fromMap(res.data); - } - - /// Create session - /// - /// Creates a session for a user. Returns an immediately usable session object. - /// - /// If you want to generate a token for a custom authentication flow, use the - /// [POST - /// /users/{userId}/tokens](https://appwrite.io/docs/server/users#createToken) - /// endpoint. - Future createSession({required String userId}) async { - final String apiPath = - '/users/{userId}/sessions'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Delete user sessions - /// - /// Delete all user's sessions by using the user's unique ID. - Future deleteSessions({required String userId}) async { - final String apiPath = - '/users/{userId}/sessions'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Delete user session - /// - /// Delete a user sessions by its unique ID. - Future deleteSession( - {required String userId, required String sessionId}) async { - final String apiPath = '/users/{userId}/sessions/{sessionId}' - .replaceAll('{userId}', userId) - .replaceAll('{sessionId}', sessionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Update user status - /// - /// Update the user status by its unique ID. Use this endpoint as an - /// alternative to deleting a user if you want to keep user's ID reserved. - Future updateStatus( - {required String userId, required bool status}) async { - final String apiPath = - '/users/{userId}/status'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'status': status, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// List User Targets - /// - /// List the messaging targets that are associated with a user. - Future listTargets( - {required String userId, List? queries}) async { - final String apiPath = - '/users/{userId}/targets'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.TargetList.fromMap(res.data); - } - - /// Create User Target - /// - /// Create a messaging target. - Future createTarget( - {required String userId, - required String targetId, - required enums.MessagingProviderType providerType, - required String identifier, - String? providerId, - String? name}) async { - final String apiPath = - '/users/{userId}/targets'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'targetId': targetId, - 'providerType': providerType.value, - 'identifier': identifier, - 'providerId': providerId, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Target.fromMap(res.data); - } - - /// Get User Target - /// - /// Get a user's push notification target by ID. - Future getTarget( - {required String userId, required String targetId}) async { - final String apiPath = '/users/{userId}/targets/{targetId}' - .replaceAll('{userId}', userId) - .replaceAll('{targetId}', targetId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Target.fromMap(res.data); - } - - /// Update User target - /// - /// Update a messaging target. - Future updateTarget( - {required String userId, - required String targetId, - String? identifier, - String? providerId, - String? name}) async { - final String apiPath = '/users/{userId}/targets/{targetId}' - .replaceAll('{userId}', userId) - .replaceAll('{targetId}', targetId); - - final Map apiParams = { - 'identifier': identifier, - 'providerId': providerId, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Target.fromMap(res.data); - } - - /// Delete user target - /// - /// Delete a messaging target. - Future deleteTarget( - {required String userId, required String targetId}) async { - final String apiPath = '/users/{userId}/targets/{targetId}' - .replaceAll('{userId}', userId) - .replaceAll('{targetId}', targetId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Create token - /// - /// Returns a token with a secret key for creating a session. Use the user ID - /// and secret and submit a request to the [PUT - /// /account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. - /// - Future createToken( - {required String userId, int? length, int? expire}) async { - final String apiPath = - '/users/{userId}/tokens'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'length': length, - 'expire': expire, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Update email verification - /// - /// Update the user email verification status by its unique ID. - Future updateEmailVerification( - {required String userId, required bool emailVerification}) async { - final String apiPath = - '/users/{userId}/verification'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'emailVerification': emailVerification, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update phone verification - /// - /// Update the user phone verification status by its unique ID. - Future updatePhoneVerification( - {required String userId, required bool phoneVerification}) async { - final String apiPath = - '/users/{userId}/verification/phone'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'phoneVerification': phoneVerification, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } -} + Users(super.client); + + /// List users + /// + /// Get a list of all the project's users. You can use the query params to + /// filter your results. + Future list({List? queries, String? search}) async { + final String apiPath = '/users'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.UserList.fromMap(res.data); + + } + + /// Create user + /// + /// Create a new user. + Future create({required String userId, String? email, String? phone, String? password, String? name}) async { + final String apiPath = '/users'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'phone': phone, +'password': password, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with Argon2 password + /// + /// Create a new user. Password provided must be hashed with the + /// [Argon2](https://en.wikipedia.org/wiki/Argon2) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createArgon2User({required String userId, required String email, required String password, String? name}) async { + final String apiPath = '/users/argon2'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with bcrypt password + /// + /// Create a new user. Password provided must be hashed with the + /// [Bcrypt](https://en.wikipedia.org/wiki/Bcrypt) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createBcryptUser({required String userId, required String email, required String password, String? name}) async { + final String apiPath = '/users/bcrypt'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// List Identities + /// + /// Get identities for all users. + Future listIdentities({List? queries, String? search}) async { + final String apiPath = '/users/identities'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.IdentityList.fromMap(res.data); + + } + + /// Delete identity + /// + /// Delete an identity by its unique ID. + Future deleteIdentity({required String identityId}) async { + final String apiPath = '/users/identities/{identityId}'.replaceAll('{identityId}', identityId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Create user with MD5 password + /// + /// Create a new user. Password provided must be hashed with the + /// [MD5](https://en.wikipedia.org/wiki/MD5) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createMD5User({required String userId, required String email, required String password, String? name}) async { + final String apiPath = '/users/md5'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with PHPass password + /// + /// Create a new user. Password provided must be hashed with the + /// [PHPass](https://www.openwall.com/phpass/) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createPHPassUser({required String userId, required String email, required String password, String? name}) async { + final String apiPath = '/users/phpass'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with Scrypt password + /// + /// Create a new user. Password provided must be hashed with the + /// [Scrypt](https://github.com/Tarsnap/scrypt) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createScryptUser({required String userId, required String email, required String password, required String passwordSalt, required int passwordCpu, required int passwordMemory, required int passwordParallel, required int passwordLength, String? name}) async { + final String apiPath = '/users/scrypt'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'passwordSalt': passwordSalt, +'passwordCpu': passwordCpu, +'passwordMemory': passwordMemory, +'passwordParallel': passwordParallel, +'passwordLength': passwordLength, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with Scrypt modified password + /// + /// Create a new user. Password provided must be hashed with the [Scrypt + /// Modified](https://gist.github.com/Meldiron/eecf84a0225eccb5a378d45bb27462cc) + /// algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createScryptModifiedUser({required String userId, required String email, required String password, required String passwordSalt, required String passwordSaltSeparator, required String passwordSignerKey, String? name}) async { + final String apiPath = '/users/scrypt-modified'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'passwordSalt': passwordSalt, +'passwordSaltSeparator': passwordSaltSeparator, +'passwordSignerKey': passwordSignerKey, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with SHA password + /// + /// Create a new user. Password provided must be hashed with the + /// [SHA](https://en.wikipedia.org/wiki/Secure_Hash_Algorithm) algorithm. Use + /// the [POST /users](https://appwrite.io/docs/server/users#usersCreate) + /// endpoint to create users with a plain text password. + Future createSHAUser({required String userId, required String email, required String password, enums.PasswordHash? passwordVersion, String? name}) async { + final String apiPath = '/users/sha'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'passwordVersion': passwordVersion?.value, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Get user + /// + /// Get a user by its unique ID. + Future get({required String userId}) async { + final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Delete user + /// + /// Delete a user by its unique ID, thereby releasing it's ID. Since ID is + /// released and can be reused, all user-related resources like documents or + /// storage files should be deleted before user deletion. If you want to keep + /// ID reserved, use the + /// [updateStatus](https://appwrite.io/docs/server/users#usersUpdateStatus) + /// endpoint instead. + Future delete({required String userId}) async { + final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Update email + /// + /// Update the user email by its unique ID. + Future updateEmail({required String userId, required String email}) async { + final String apiPath = '/users/{userId}/email'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'email': email, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user JWT + /// + /// Use this endpoint to create a JSON Web Token for user by its unique ID. You + /// can use the resulting JWT to authenticate on behalf of the user. The JWT + /// secret will become invalid if the session it uses gets deleted. + Future createJWT({required String userId, String? sessionId, int? duration}) async { + final String apiPath = '/users/{userId}/jwts'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'sessionId': sessionId, +'duration': duration, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Jwt.fromMap(res.data); + + } + + /// Update user labels + /// + /// Update the user labels by its unique ID. + /// + /// Labels can be used to grant access to resources. While teams are a way for + /// user's to share access to a resource, labels can be defined by the + /// developer to grant access without an invitation. See the [Permissions + /// docs](https://appwrite.io/docs/permissions) for more info. + Future updateLabels({required String userId, required List labels}) async { + final String apiPath = '/users/{userId}/labels'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'labels': labels, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// List user logs + /// + /// Get the user activity logs list by its unique ID. + Future listLogs({required String userId, List? queries}) async { + final String apiPath = '/users/{userId}/logs'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// List user memberships + /// + /// Get the user membership list by its unique ID. + Future listMemberships({required String userId}) async { + final String apiPath = '/users/{userId}/memberships'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MembershipList.fromMap(res.data); + + } + + /// Update MFA + /// + /// Enable or disable MFA on a user account. + Future updateMfa({required String userId, required bool mfa}) async { + final String apiPath = '/users/{userId}/mfa'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'mfa': mfa, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Delete Authenticator + /// + /// Delete an authenticator app. + Future deleteMfaAuthenticator({required String userId, required enums.AuthenticatorType type}) async { + final String apiPath = '/users/{userId}/mfa/authenticators/{type}'.replaceAll('{userId}', userId).replaceAll('{type}', type.value); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// List Factors + /// + /// List the factors available on the account to be used as a MFA challange. + Future listMfaFactors({required String userId}) async { + final String apiPath = '/users/{userId}/mfa/factors'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaFactors.fromMap(res.data); + + } + + /// Get MFA Recovery Codes + /// + /// Get recovery codes that can be used as backup for MFA flow by User ID. + /// Before getting codes, they must be generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. + Future getMfaRecoveryCodes({required String userId}) async { + final String apiPath = '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Regenerate MFA Recovery Codes + /// + /// Regenerate recovery codes that can be used as backup for MFA flow by User + /// ID. Before regenerating codes, they must be first generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. + Future updateMfaRecoveryCodes({required String userId}) async { + final String apiPath = '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Create MFA Recovery Codes + /// + /// Generate recovery codes used as backup for MFA flow for User ID. Recovery + /// codes can be used as a MFA verification type in + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method by client SDK. + Future createMfaRecoveryCodes({required String userId}) async { + final String apiPath = '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Update name + /// + /// Update the user name by its unique ID. + Future updateName({required String userId, required String name}) async { + final String apiPath = '/users/{userId}/name'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update password + /// + /// Update the user password by its unique ID. + Future updatePassword({required String userId, required String password}) async { + final String apiPath = '/users/{userId}/password'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'password': password, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update phone + /// + /// Update the user phone by its unique ID. + Future updatePhone({required String userId, required String number}) async { + final String apiPath = '/users/{userId}/phone'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'number': number, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Get user preferences + /// + /// Get the user preferences by its unique ID. + Future getPrefs({required String userId}) async { + final String apiPath = '/users/{userId}/prefs'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + + } + + /// Update user preferences + /// + /// Update the user preferences by its unique ID. 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 String userId, required Map prefs}) async { + final String apiPath = '/users/{userId}/prefs'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'prefs': prefs, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + + } + + /// List user sessions + /// + /// Get the user sessions list by its unique ID. + Future listSessions({required String userId}) async { + final String apiPath = '/users/{userId}/sessions'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SessionList.fromMap(res.data); + + } + + /// Create session + /// + /// Creates a session for a user. Returns an immediately usable session object. + /// + /// If you want to generate a token for a custom authentication flow, use the + /// [POST + /// /users/{userId}/tokens](https://appwrite.io/docs/server/users#createToken) + /// endpoint. + Future createSession({required String userId}) async { + final String apiPath = '/users/{userId}/sessions'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Delete user sessions + /// + /// Delete all user's sessions by using the user's unique ID. + Future deleteSessions({required String userId}) async { + final String apiPath = '/users/{userId}/sessions'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Delete user session + /// + /// Delete a user sessions by its unique ID. + Future deleteSession({required String userId, required String sessionId}) async { + final String apiPath = '/users/{userId}/sessions/{sessionId}'.replaceAll('{userId}', userId).replaceAll('{sessionId}', sessionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Update user status + /// + /// Update the user status by its unique ID. Use this endpoint as an + /// alternative to deleting a user if you want to keep user's ID reserved. + Future updateStatus({required String userId, required bool status}) async { + final String apiPath = '/users/{userId}/status'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'status': status, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// List User Targets + /// + /// List the messaging targets that are associated with a user. + Future listTargets({required String userId, List? queries}) async { + final String apiPath = '/users/{userId}/targets'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.TargetList.fromMap(res.data); + + } + + /// Create User Target + /// + /// Create a messaging target. + Future createTarget({required String userId, required String targetId, required enums.MessagingProviderType providerType, required String identifier, String? providerId, String? name}) async { + final String apiPath = '/users/{userId}/targets'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'targetId': targetId, +'providerType': providerType.value, +'identifier': identifier, +'providerId': providerId, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Target.fromMap(res.data); + + } + + /// Get User Target + /// + /// Get a user's push notification target by ID. + Future getTarget({required String userId, required String targetId}) async { + final String apiPath = '/users/{userId}/targets/{targetId}'.replaceAll('{userId}', userId).replaceAll('{targetId}', targetId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Target.fromMap(res.data); + + } + + /// Update User target + /// + /// Update a messaging target. + Future updateTarget({required String userId, required String targetId, String? identifier, String? providerId, String? name}) async { + final String apiPath = '/users/{userId}/targets/{targetId}'.replaceAll('{userId}', userId).replaceAll('{targetId}', targetId); + + final Map apiParams = { + + 'identifier': identifier, +'providerId': providerId, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Target.fromMap(res.data); + + } + + /// Delete user target + /// + /// Delete a messaging target. + Future deleteTarget({required String userId, required String targetId}) async { + final String apiPath = '/users/{userId}/targets/{targetId}'.replaceAll('{userId}', userId).replaceAll('{targetId}', targetId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Create token + /// + /// Returns a token with a secret key for creating a session. Use the user ID + /// and secret and submit a request to the [PUT + /// /account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. + /// + Future createToken({required String userId, int? length, int? expire}) async { + final String apiPath = '/users/{userId}/tokens'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'length': length, +'expire': expire, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Update email verification + /// + /// Update the user email verification status by its unique ID. + Future updateEmailVerification({required String userId, required bool emailVerification}) async { + final String apiPath = '/users/{userId}/verification'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'emailVerification': emailVerification, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update phone verification + /// + /// Update the user phone verification status by its unique ID. + Future updatePhoneVerification({required String userId, required bool phoneVerification}) async { + final String apiPath = '/users/{userId}/verification/phone'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'phoneVerification': phoneVerification, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } +} \ No newline at end of file diff --git a/lib/src/client.dart b/lib/src/client.dart index bac07cfb..8dee2426 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -8,7 +8,7 @@ import 'upload_progress.dart'; /// [Client] that handles requests to Appwrite abstract class Client { /// The size for cunked uploads in bytes. - static const int CHUNK_SIZE = 5 * 1024 * 1024; + static const int CHUNK_SIZE = 5*1024*1024; /// Holds configuration such as project. late Map config; @@ -27,7 +27,7 @@ abstract class Client { Future webAuth(Uri url); /// Set self signed to [status]. - /// + /// /// If self signed is true, [Client] will ignore invalid certificates. /// This is helpful in environments where your Appwrite /// instance does not have a valid SSL certificate. @@ -78,8 +78,7 @@ abstract class Client { }); /// Send the API request. - Future call( - HttpMethod method, { + Future call(HttpMethod method, { String path = '', Map headers = const {}, Map params = const {}, diff --git a/lib/src/client_base.dart b/lib/src/client_base.dart index 95476465..21992eb0 100644 --- a/lib/src/client_base.dart +++ b/lib/src/client_base.dart @@ -2,25 +2,21 @@ import 'response.dart'; import 'client.dart'; import 'enums.dart'; -abstract class ClientBase implements Client { +abstract class ClientBase implements Client { /// Your project ID @override ClientBase setProject(value); - /// Your secret API key @override ClientBase setKey(value); - /// Your secret JSON Web Token @override ClientBase setJWT(value); @override ClientBase setLocale(value); - /// The user session to authenticate with @override ClientBase setSession(value); - /// The user agent string of the client that made the request @override ClientBase setForwardedUserAgent(value); diff --git a/lib/src/client_browser.dart b/lib/src/client_browser.dart index c75d7838..af7cf916 100644 --- a/lib/src/client_browser.dart +++ b/lib/src/client_browser.dart @@ -6,7 +6,7 @@ import 'enums.dart'; import 'exception.dart'; import 'client_base.dart'; import 'response.dart'; -import 'input_file.dart'; +import '../payload.dart'; import 'upload_progress.dart'; ClientBase createClient({ @@ -16,7 +16,7 @@ ClientBase createClient({ ClientBrowser(endPoint: endPoint, selfSigned: selfSigned); class ClientBrowser extends ClientBase with ClientMixin { - static const int CHUNK_SIZE = 5 * 1024 * 1024; + static const int CHUNK_SIZE = 5*1024*1024; String _endPoint; Map? _headers; @override @@ -33,8 +33,8 @@ class ClientBrowser extends ClientBase with ClientMixin { 'x-sdk-name': 'Dart', 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', - 'x-sdk-version': '12.1.0', - 'X-Appwrite-Response-Format': '1.6.0', + 'x-sdk-version': '13.0.0-rc1', + 'X-Appwrite-Response-Format' : '1.6.0', }; config = {}; @@ -46,52 +46,47 @@ class ClientBrowser extends ClientBase with ClientMixin { @override String get endPoint => _endPoint; - /// Your project ID - @override - ClientBrowser setProject(value) { - config['project'] = value; - addHeader('X-Appwrite-Project', value); - return this; - } - - /// Your secret API key - @override - ClientBrowser setKey(value) { - config['key'] = value; - addHeader('X-Appwrite-Key', value); - return this; - } - - /// Your secret JSON Web Token - @override - ClientBrowser setJWT(value) { - config['jWT'] = value; - addHeader('X-Appwrite-JWT', value); - return this; - } - - @override - ClientBrowser setLocale(value) { - config['locale'] = value; - addHeader('X-Appwrite-Locale', value); - return this; - } - - /// The user session to authenticate with - @override - ClientBrowser setSession(value) { - config['session'] = value; - addHeader('X-Appwrite-Session', value); - return this; - } - - /// The user agent string of the client that made the request - @override - ClientBrowser setForwardedUserAgent(value) { - config['forwardedUserAgent'] = value; - addHeader('X-Forwarded-User-Agent', value); - return this; - } + /// Your project ID + @override + ClientBrowser setProject(value) { + config['project'] = value; + addHeader('X-Appwrite-Project', value); + return this; + } + /// Your secret API key + @override + ClientBrowser setKey(value) { + config['key'] = value; + addHeader('X-Appwrite-Key', value); + return this; + } + /// Your secret JSON Web Token + @override + ClientBrowser setJWT(value) { + config['jWT'] = value; + addHeader('X-Appwrite-JWT', value); + return this; + } + @override + ClientBrowser setLocale(value) { + config['locale'] = value; + addHeader('X-Appwrite-Locale', value); + return this; + } + /// The user session to authenticate with + @override + ClientBrowser setSession(value) { + config['session'] = value; + addHeader('X-Appwrite-Session', value); + return this; + } + /// The user agent string of the client that made the request + @override + ClientBrowser setForwardedUserAgent(value) { + config['forwardedUserAgent'] = value; + addHeader('X-Forwarded-User-Agent', value); + return this; + } @override ClientBrowser setSelfSigned({bool status = true}) { @@ -127,17 +122,16 @@ class ClientBrowser extends ClientBase with ClientMixin { required Map headers, Function(UploadProgress)? onProgress, }) async { - InputFile file = params[paramName]; - if (file.bytes == null) { - throw AppwriteException("File bytes must be provided for Flutter web"); + Payload file = params[paramName]; + if (file.data == null) { + throw AppwriteException("File data must be provided for Flutter web"); } - int size = file.bytes!.length; + int size = file.data!.length; late Response res; if (size <= CHUNK_SIZE) { - params[paramName] = http.MultipartFile.fromBytes(paramName, file.bytes!, - filename: file.filename); + params[paramName] = http.MultipartFile.fromBytes(paramName, file.data!, filename: file.filename); return call( HttpMethod.post, path: path, @@ -163,9 +157,9 @@ class ClientBrowser extends ClientBase with ClientMixin { while (offset < size) { List chunk = []; final end = min(offset + CHUNK_SIZE, size); - chunk = file.bytes!.getRange(offset, end).toList(); - params[paramName] = http.MultipartFile.fromBytes(paramName, chunk, - filename: file.filename); + chunk = file.toBinary(length: offset, length: min(CHUNK_SIZE, size - offset)); + params[paramName] = + http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename); headers['content-range'] = 'bytes $offset-${min((offset + CHUNK_SIZE - 1), size - 1)}/$size'; res = await call(HttpMethod.post, diff --git a/lib/src/client_io.dart b/lib/src/client_io.dart index eeae66f0..0877997e 100644 --- a/lib/src/client_io.dart +++ b/lib/src/client_io.dart @@ -2,12 +2,13 @@ import 'dart:io'; import 'dart:math'; import 'package:http/http.dart' as http; import 'package:http/io_client.dart'; + import 'client_mixin.dart'; import 'client_base.dart'; import 'enums.dart'; import 'exception.dart'; import 'response.dart'; -import 'input_file.dart'; +import '../payload.dart'; import 'upload_progress.dart'; ClientBase createClient({ @@ -20,7 +21,7 @@ ClientBase createClient({ ); class ClientIO extends ClientBase with ClientMixin { - static const int CHUNK_SIZE = 5 * 1024 * 1024; + static const int CHUNK_SIZE = 5*1024*1024; String _endPoint; Map? _headers; @override @@ -42,10 +43,9 @@ class ClientIO extends ClientBase with ClientMixin { 'x-sdk-name': 'Dart', 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', - 'x-sdk-version': '12.1.0', - 'user-agent': - 'AppwriteDartSDK/12.1.0 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', - 'X-Appwrite-Response-Format': '1.6.0', + 'x-sdk-version': '13.0.0-rc1', + 'user-agent' : 'AppwriteDartSDK/13.0.0-rc1 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', + 'X-Appwrite-Response-Format' : '1.6.0', }; config = {}; @@ -57,52 +57,47 @@ class ClientIO extends ClientBase with ClientMixin { @override String get endPoint => _endPoint; - /// Your project ID - @override - ClientIO setProject(value) { - config['project'] = value; - addHeader('X-Appwrite-Project', value); - return this; - } - - /// Your secret API key - @override - ClientIO setKey(value) { - config['key'] = value; - addHeader('X-Appwrite-Key', value); - return this; - } - - /// Your secret JSON Web Token - @override - ClientIO setJWT(value) { - config['jWT'] = value; - addHeader('X-Appwrite-JWT', value); - return this; - } - - @override - ClientIO setLocale(value) { - config['locale'] = value; - addHeader('X-Appwrite-Locale', value); - return this; - } - - /// The user session to authenticate with - @override - ClientIO setSession(value) { - config['session'] = value; - addHeader('X-Appwrite-Session', value); - return this; - } - - /// The user agent string of the client that made the request - @override - ClientIO setForwardedUserAgent(value) { - config['forwardedUserAgent'] = value; - addHeader('X-Forwarded-User-Agent', value); - return this; - } + /// Your project ID + @override + ClientIO setProject(value) { + config['project'] = value; + addHeader('X-Appwrite-Project', value); + return this; + } + /// Your secret API key + @override + ClientIO setKey(value) { + config['key'] = value; + addHeader('X-Appwrite-Key', value); + return this; + } + /// Your secret JSON Web Token + @override + ClientIO setJWT(value) { + config['jWT'] = value; + addHeader('X-Appwrite-JWT', value); + return this; + } + @override + ClientIO setLocale(value) { + config['locale'] = value; + addHeader('X-Appwrite-Locale', value); + return this; + } + /// The user session to authenticate with + @override + ClientIO setSession(value) { + config['session'] = value; + addHeader('X-Appwrite-Session', value); + return this; + } + /// The user agent string of the client that made the request + @override + ClientIO setForwardedUserAgent(value) { + config['forwardedUserAgent'] = value; + addHeader('X-Forwarded-User-Agent', value); + return this; + } @override ClientIO setSelfSigned({bool status = true}) { @@ -132,14 +127,14 @@ class ClientIO extends ClientBase with ClientMixin { required Map headers, Function(UploadProgress)? onProgress, }) async { - InputFile file = params[paramName]; - if (file.path == null && file.bytes == null) { - throw AppwriteException("File path or bytes must be provided"); + Payload file = params[paramName]; + if (file.path == null && file.data == null) { + throw AppwriteException("File path or data must be provided"); } int size = 0; - if (file.bytes != null) { - size = file.bytes!.length; + if (file.data != null) { + size = file.data!.length; } File? iofile; @@ -156,7 +151,7 @@ class ClientIO extends ClientBase with ClientMixin { paramName, file.path!, filename: file.filename); } else { - params[paramName] = http.MultipartFile.fromBytes(paramName, file.bytes!, + params[paramName] = http.MultipartFile.fromBytes(paramName, file.data!, filename: file.filename); } return call( @@ -189,15 +184,14 @@ class ClientIO extends ClientBase with ClientMixin { while (offset < size) { List chunk = []; - if (file.bytes != null) { - final end = min(offset + CHUNK_SIZE, size); - chunk = file.bytes!.getRange(offset, end).toList(); + if (file.data != null) { + chunk = file.toBinary(offset: offset, length: min(CHUNK_SIZE, size - offset)); } else { raf!.setPositionSync(offset); chunk = raf.readSync(CHUNK_SIZE); } - params[paramName] = http.MultipartFile.fromBytes(paramName, chunk, - filename: file.filename); + params[paramName] = + http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename); headers['content-range'] = 'bytes $offset-${min((offset + CHUNK_SIZE - 1), size - 1)}/$size'; res = await call(HttpMethod.post, diff --git a/lib/src/client_mixin.dart b/lib/src/client_mixin.dart index 1078c313..f7dd73a7 100644 --- a/lib/src/client_mixin.dart +++ b/lib/src/client_mixin.dart @@ -1,11 +1,21 @@ import 'package:http/http.dart' as http; +import 'package:http_parser/http_parser.dart'; +import 'package:mime/mime.dart'; +import 'package:string_scanner/string_scanner.dart'; + import 'exception.dart'; import 'response.dart'; import 'dart:convert'; import 'dart:developer'; import 'enums.dart'; +import '../payload.dart'; + +mixin ClientMixin { + final _token = RegExp(r'[^()<>@,;:"\\/[\]?={} \t\x00-\x1F\x7F]+'); + final _whitespace = RegExp(r'(?:(?:\r\n)?[ \t]+)*'); + final _quotedString = RegExp(r'"(?:[^"\x00-\x1F\x7F]|\\.)*"'); + final _quotedPair = RegExp(r'\\(.)'); -class ClientMixin { http.BaseRequest prepareRequest( HttpMethod method, { required Uri uri, @@ -40,7 +50,7 @@ class ClientMixin { } } else if (method == HttpMethod.get) { if (params.isNotEmpty) { - params = params.map((key, value) { + params = params.map((key, value){ if (value is int || value is double) { return MapEntry(key, value.toString()); } @@ -66,7 +76,7 @@ class ClientMixin { return request; } - Response prepareResponse(http.Response res, {ResponseType? responseType}) { + Future prepareResponse(http.Response res, {ResponseType? responseType}) async { responseType ??= ResponseType.json; String? warnings = res.headers['x-appwrite-warning']; @@ -96,6 +106,9 @@ class ClientMixin { } else { data = res.body; } + } else if((res.headers['content-type'] ?? '').contains('multipart/form-data')) { + data = await _parseMultipart(res.headers['content-type']!, Stream.value(res.bodyBytes)); + return Response(data: data); } else { if (responseType == ResponseType.bytes) { data = res.bodyBytes; @@ -106,23 +119,133 @@ class ClientMixin { return Response(data: data); } - Future toResponse( - http.StreamedResponse streamedResponse) async { - if (streamedResponse.statusCode == 204) { - return http.Response( - '', - streamedResponse.statusCode, - headers: streamedResponse.headers.map((k, v) => - k.toLowerCase() == 'content-type' - ? MapEntry(k, 'text/plain') - : MapEntry(k, v)), - request: streamedResponse.request, - isRedirect: streamedResponse.isRedirect, - persistentConnection: streamedResponse.persistentConnection, - reasonPhrase: streamedResponse.reasonPhrase, - ); - } else { - return await http.Response.fromStream(streamedResponse); + Future toResponse(http.StreamedResponse streamedResponse) async { + if(streamedResponse.statusCode == 204) { + return http.Response('', + streamedResponse.statusCode, + headers: streamedResponse.headers.map((k,v) => k.toLowerCase()=='content-type' ? MapEntry(k, 'text/plain') : MapEntry(k,v)), + request: streamedResponse.request, + isRedirect: streamedResponse.isRedirect, + persistentConnection: streamedResponse.persistentConnection, + reasonPhrase: streamedResponse.reasonPhrase, + ); + } else { + return await http.Response.fromStream(streamedResponse); + } + } + + Future> _decodeMimeMultipart(MimeMultipart part) async { + List result = []; + + await for (var chunk in part) { + result.addAll(chunk); + } + + return result; + } + + /// Parse multipart forma data + Future> _parseMultipart( + String header, Stream> body) async { + final data = await _parts(header, body) + .map<_FormData?>((part) { + final rawDisposition = part.headers['content-disposition']; + if (rawDisposition == null) return null; + + final formDataParams = + _parseFormDataContentDisposition(rawDisposition); + if (formDataParams == null) return null; + + final name = formDataParams['name']; + if (name == null) return null; + + final filename = formDataParams['filename']; + dynamic value; + if (name == 'responseBody') { + return _FormData._(name, filename, part); + } else if (filename != null) { + value = { + "file": part, + "filename": filename, + "mimeType": part.headers['Content-Type'], + }; + } else { + value = utf8.decodeStream(part); + } + return _FormData._(name, filename, value); + }) + .where((data) => data != null) + .toList(); + final Map out = {}; + for (final item in data) { + if (item!.name == 'responseBody') { + out[item.name] = + Payload.fromBinary(data: await _decodeMimeMultipart(item.value), filename: item.filename); + } else { + out[item.name] = await item.value; + } } + return out; + } + + Stream _parts(String header, Stream> body) { + final boundary = _extractBoundary(header); + if (boundary == null) { + throw Exception('Not a multipart request'); + } + return MimeMultipartTransformer(boundary).bind(body!); + } + + String? _extractBoundary(String header) { + final contentType = MediaType.parse(header); + if (contentType.type != 'multipart') return null; + + return contentType.parameters['boundary']; + } + + /// Parses a `content-disposition: form-data; arg1="val1"; ...` header. + Map? _parseFormDataContentDisposition(String header) { + final scanner = StringScanner(header); + + scanner + ..scan(_whitespace) + ..expect(_token); + if (scanner.lastMatch![0] != 'form-data') return null; + + final params = {}; + + while (scanner.scan(';')) { + scanner + ..scan(_whitespace) + ..scan(_token); + final key = scanner.lastMatch![0]!; + scanner.expect('='); + + String value; + if (scanner.scan(_token)) { + value = scanner.lastMatch![0]!; + } else { + scanner.expect(_quotedString, name: 'quoted string'); + final string = scanner.lastMatch![0]!; + + value = string + .substring(1, string.length - 1) + .replaceAllMapped(_quotedPair, (match) => match[1]!); + } + + scanner.scan(_whitespace); + params[key] = value; + } + + scanner.expectDone(); + return params; } } + +class _FormData { + final String name; + final dynamic value; + final String? filename; + + _FormData._(this.name, this.filename, this.value); +} \ No newline at end of file diff --git a/lib/src/client_stub.dart b/lib/src/client_stub.dart index 95e9d217..40423b49 100644 --- a/lib/src/client_stub.dart +++ b/lib/src/client_stub.dart @@ -1,6 +1,6 @@ import 'client_base.dart'; -/// Implemented in `browser_client.dart` and `io_client.dart`. +/// Implemented in `client_browser.dart` and `client_io.dart`. ClientBase createClient({required String endPoint, required bool selfSigned}) => throw UnsupportedError( 'Cannot create a client without dart:html or dart:io.'); diff --git a/lib/src/enums/authentication_factor.dart b/lib/src/enums/authentication_factor.dart index 1d5271eb..00d12830 100644 --- a/lib/src/enums/authentication_factor.dart +++ b/lib/src/enums/authentication_factor.dart @@ -1,14 +1,16 @@ part of '../../enums.dart'; enum AuthenticationFactor { - email(value: 'email'), - phone(value: 'phone'), - totp(value: 'totp'), - recoverycode(value: 'recoverycode'); + email(value: 'email'), + phone(value: 'phone'), + totp(value: 'totp'), + recoverycode(value: 'recoverycode'); - const AuthenticationFactor({required this.value}); + const AuthenticationFactor({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/authenticator_type.dart b/lib/src/enums/authenticator_type.dart index c1fe8584..10460393 100644 --- a/lib/src/enums/authenticator_type.dart +++ b/lib/src/enums/authenticator_type.dart @@ -1,11 +1,13 @@ part of '../../enums.dart'; enum AuthenticatorType { - totp(value: 'totp'); + totp(value: 'totp'); - const AuthenticatorType({required this.value}); + const AuthenticatorType({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/browser.dart b/lib/src/enums/browser.dart index 949f4c47..386fa11d 100644 --- a/lib/src/enums/browser.dart +++ b/lib/src/enums/browser.dart @@ -1,24 +1,26 @@ part of '../../enums.dart'; enum Browser { - avantBrowser(value: 'aa'), - androidWebViewBeta(value: 'an'), - googleChrome(value: 'ch'), - googleChromeIOS(value: 'ci'), - googleChromeMobile(value: 'cm'), - chromium(value: 'cr'), - mozillaFirefox(value: 'ff'), - safari(value: 'sf'), - mobileSafari(value: 'mf'), - microsoftEdge(value: 'ps'), - microsoftEdgeIOS(value: 'oi'), - operaMini(value: 'om'), - opera(value: 'op'), - operaNext(value: 'on'); + avantBrowser(value: 'aa'), + androidWebViewBeta(value: 'an'), + googleChrome(value: 'ch'), + googleChromeIOS(value: 'ci'), + googleChromeMobile(value: 'cm'), + chromium(value: 'cr'), + mozillaFirefox(value: 'ff'), + safari(value: 'sf'), + mobileSafari(value: 'mf'), + microsoftEdge(value: 'ps'), + microsoftEdgeIOS(value: 'oi'), + operaMini(value: 'om'), + opera(value: 'op'), + operaNext(value: 'on'); - const Browser({required this.value}); + const Browser({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/compression.dart b/lib/src/enums/compression.dart index 768930d9..209acfb8 100644 --- a/lib/src/enums/compression.dart +++ b/lib/src/enums/compression.dart @@ -1,13 +1,15 @@ part of '../../enums.dart'; enum Compression { - none(value: 'none'), - gzip(value: 'gzip'), - zstd(value: 'zstd'); + none(value: 'none'), + gzip(value: 'gzip'), + zstd(value: 'zstd'); - const Compression({required this.value}); + const Compression({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/credit_card.dart b/lib/src/enums/credit_card.dart index 3a6b256a..7d54fa80 100644 --- a/lib/src/enums/credit_card.dart +++ b/lib/src/enums/credit_card.dart @@ -1,26 +1,28 @@ part of '../../enums.dart'; enum CreditCard { - americanExpress(value: 'amex'), - argencard(value: 'argencard'), - cabal(value: 'cabal'), - cencosud(value: 'cencosud'), - dinersClub(value: 'diners'), - discover(value: 'discover'), - elo(value: 'elo'), - hipercard(value: 'hipercard'), - jCB(value: 'jcb'), - mastercard(value: 'mastercard'), - naranja(value: 'naranja'), - tarjetaShopping(value: 'targeta-shopping'), - unionChinaPay(value: 'union-china-pay'), - visa(value: 'visa'), - mIR(value: 'mir'), - maestro(value: 'maestro'); + americanExpress(value: 'amex'), + argencard(value: 'argencard'), + cabal(value: 'cabal'), + cencosud(value: 'cencosud'), + dinersClub(value: 'diners'), + discover(value: 'discover'), + elo(value: 'elo'), + hipercard(value: 'hipercard'), + jCB(value: 'jcb'), + mastercard(value: 'mastercard'), + naranja(value: 'naranja'), + tarjetaShopping(value: 'targeta-shopping'), + unionChinaPay(value: 'union-china-pay'), + visa(value: 'visa'), + mIR(value: 'mir'), + maestro(value: 'maestro'); - const CreditCard({required this.value}); + const CreditCard({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/execution_method.dart b/lib/src/enums/execution_method.dart index 42954430..7d2d7016 100644 --- a/lib/src/enums/execution_method.dart +++ b/lib/src/enums/execution_method.dart @@ -1,16 +1,18 @@ part of '../../enums.dart'; enum ExecutionMethod { - gET(value: 'GET'), - pOST(value: 'POST'), - pUT(value: 'PUT'), - pATCH(value: 'PATCH'), - dELETE(value: 'DELETE'), - oPTIONS(value: 'OPTIONS'); + gET(value: 'GET'), + pOST(value: 'POST'), + pUT(value: 'PUT'), + pATCH(value: 'PATCH'), + dELETE(value: 'DELETE'), + oPTIONS(value: 'OPTIONS'); - const ExecutionMethod({required this.value}); + const ExecutionMethod({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/flag.dart b/lib/src/enums/flag.dart index a44cb81d..27c25cac 100644 --- a/lib/src/enums/flag.dart +++ b/lib/src/enums/flag.dart @@ -1,205 +1,207 @@ part of '../../enums.dart'; enum Flag { - afghanistan(value: 'af'), - angola(value: 'ao'), - albania(value: 'al'), - andorra(value: 'ad'), - unitedArabEmirates(value: 'ae'), - argentina(value: 'ar'), - armenia(value: 'am'), - antiguaAndBarbuda(value: 'ag'), - australia(value: 'au'), - austria(value: 'at'), - azerbaijan(value: 'az'), - burundi(value: 'bi'), - belgium(value: 'be'), - benin(value: 'bj'), - burkinaFaso(value: 'bf'), - bangladesh(value: 'bd'), - bulgaria(value: 'bg'), - bahrain(value: 'bh'), - bahamas(value: 'bs'), - bosniaAndHerzegovina(value: 'ba'), - belarus(value: 'by'), - belize(value: 'bz'), - bolivia(value: 'bo'), - brazil(value: 'br'), - barbados(value: 'bb'), - bruneiDarussalam(value: 'bn'), - bhutan(value: 'bt'), - botswana(value: 'bw'), - centralAfricanRepublic(value: 'cf'), - canada(value: 'ca'), - switzerland(value: 'ch'), - chile(value: 'cl'), - china(value: 'cn'), - coteDIvoire(value: 'ci'), - cameroon(value: 'cm'), - democraticRepublicOfTheCongo(value: 'cd'), - republicOfTheCongo(value: 'cg'), - colombia(value: 'co'), - comoros(value: 'km'), - capeVerde(value: 'cv'), - costaRica(value: 'cr'), - cuba(value: 'cu'), - cyprus(value: 'cy'), - czechRepublic(value: 'cz'), - germany(value: 'de'), - djibouti(value: 'dj'), - dominica(value: 'dm'), - denmark(value: 'dk'), - dominicanRepublic(value: 'do'), - algeria(value: 'dz'), - ecuador(value: 'ec'), - egypt(value: 'eg'), - eritrea(value: 'er'), - spain(value: 'es'), - estonia(value: 'ee'), - ethiopia(value: 'et'), - finland(value: 'fi'), - fiji(value: 'fj'), - france(value: 'fr'), - micronesiaFederatedStatesOf(value: 'fm'), - gabon(value: 'ga'), - unitedKingdom(value: 'gb'), - georgia(value: 'ge'), - ghana(value: 'gh'), - guinea(value: 'gn'), - gambia(value: 'gm'), - guineaBissau(value: 'gw'), - equatorialGuinea(value: 'gq'), - greece(value: 'gr'), - grenada(value: 'gd'), - guatemala(value: 'gt'), - guyana(value: 'gy'), - honduras(value: 'hn'), - croatia(value: 'hr'), - haiti(value: 'ht'), - hungary(value: 'hu'), - indonesia(value: 'id'), - india(value: 'in'), - ireland(value: 'ie'), - iranIslamicRepublicOf(value: 'ir'), - iraq(value: 'iq'), - iceland(value: 'is'), - israel(value: 'il'), - italy(value: 'it'), - jamaica(value: 'jm'), - jordan(value: 'jo'), - japan(value: 'jp'), - kazakhstan(value: 'kz'), - kenya(value: 'ke'), - kyrgyzstan(value: 'kg'), - cambodia(value: 'kh'), - kiribati(value: 'ki'), - saintKittsAndNevis(value: 'kn'), - southKorea(value: 'kr'), - kuwait(value: 'kw'), - laoPeopleSDemocraticRepublic(value: 'la'), - lebanon(value: 'lb'), - liberia(value: 'lr'), - libya(value: 'ly'), - saintLucia(value: 'lc'), - liechtenstein(value: 'li'), - sriLanka(value: 'lk'), - lesotho(value: 'ls'), - lithuania(value: 'lt'), - luxembourg(value: 'lu'), - latvia(value: 'lv'), - morocco(value: 'ma'), - monaco(value: 'mc'), - moldova(value: 'md'), - madagascar(value: 'mg'), - maldives(value: 'mv'), - mexico(value: 'mx'), - marshallIslands(value: 'mh'), - northMacedonia(value: 'mk'), - mali(value: 'ml'), - malta(value: 'mt'), - myanmar(value: 'mm'), - montenegro(value: 'me'), - mongolia(value: 'mn'), - mozambique(value: 'mz'), - mauritania(value: 'mr'), - mauritius(value: 'mu'), - malawi(value: 'mw'), - malaysia(value: 'my'), - namibia(value: 'na'), - niger(value: 'ne'), - nigeria(value: 'ng'), - nicaragua(value: 'ni'), - netherlands(value: 'nl'), - norway(value: 'no'), - nepal(value: 'np'), - nauru(value: 'nr'), - newZealand(value: 'nz'), - oman(value: 'om'), - pakistan(value: 'pk'), - panama(value: 'pa'), - peru(value: 'pe'), - philippines(value: 'ph'), - palau(value: 'pw'), - papuaNewGuinea(value: 'pg'), - poland(value: 'pl'), - frenchPolynesia(value: 'pf'), - northKorea(value: 'kp'), - portugal(value: 'pt'), - paraguay(value: 'py'), - qatar(value: 'qa'), - romania(value: 'ro'), - russia(value: 'ru'), - rwanda(value: 'rw'), - saudiArabia(value: 'sa'), - sudan(value: 'sd'), - senegal(value: 'sn'), - singapore(value: 'sg'), - solomonIslands(value: 'sb'), - sierraLeone(value: 'sl'), - elSalvador(value: 'sv'), - sanMarino(value: 'sm'), - somalia(value: 'so'), - serbia(value: 'rs'), - southSudan(value: 'ss'), - saoTomeAndPrincipe(value: 'st'), - suriname(value: 'sr'), - slovakia(value: 'sk'), - slovenia(value: 'si'), - sweden(value: 'se'), - eswatini(value: 'sz'), - seychelles(value: 'sc'), - syria(value: 'sy'), - chad(value: 'td'), - togo(value: 'tg'), - thailand(value: 'th'), - tajikistan(value: 'tj'), - turkmenistan(value: 'tm'), - timorLeste(value: 'tl'), - tonga(value: 'to'), - trinidadAndTobago(value: 'tt'), - tunisia(value: 'tn'), - turkey(value: 'tr'), - tuvalu(value: 'tv'), - tanzania(value: 'tz'), - uganda(value: 'ug'), - ukraine(value: 'ua'), - uruguay(value: 'uy'), - unitedStates(value: 'us'), - uzbekistan(value: 'uz'), - vaticanCity(value: 'va'), - saintVincentAndTheGrenadines(value: 'vc'), - venezuela(value: 've'), - vietnam(value: 'vn'), - vanuatu(value: 'vu'), - samoa(value: 'ws'), - yemen(value: 'ye'), - southAfrica(value: 'za'), - zambia(value: 'zm'), - zimbabwe(value: 'zw'); + afghanistan(value: 'af'), + angola(value: 'ao'), + albania(value: 'al'), + andorra(value: 'ad'), + unitedArabEmirates(value: 'ae'), + argentina(value: 'ar'), + armenia(value: 'am'), + antiguaAndBarbuda(value: 'ag'), + australia(value: 'au'), + austria(value: 'at'), + azerbaijan(value: 'az'), + burundi(value: 'bi'), + belgium(value: 'be'), + benin(value: 'bj'), + burkinaFaso(value: 'bf'), + bangladesh(value: 'bd'), + bulgaria(value: 'bg'), + bahrain(value: 'bh'), + bahamas(value: 'bs'), + bosniaAndHerzegovina(value: 'ba'), + belarus(value: 'by'), + belize(value: 'bz'), + bolivia(value: 'bo'), + brazil(value: 'br'), + barbados(value: 'bb'), + bruneiDarussalam(value: 'bn'), + bhutan(value: 'bt'), + botswana(value: 'bw'), + centralAfricanRepublic(value: 'cf'), + canada(value: 'ca'), + switzerland(value: 'ch'), + chile(value: 'cl'), + china(value: 'cn'), + coteDIvoire(value: 'ci'), + cameroon(value: 'cm'), + democraticRepublicOfTheCongo(value: 'cd'), + republicOfTheCongo(value: 'cg'), + colombia(value: 'co'), + comoros(value: 'km'), + capeVerde(value: 'cv'), + costaRica(value: 'cr'), + cuba(value: 'cu'), + cyprus(value: 'cy'), + czechRepublic(value: 'cz'), + germany(value: 'de'), + djibouti(value: 'dj'), + dominica(value: 'dm'), + denmark(value: 'dk'), + dominicanRepublic(value: 'do'), + algeria(value: 'dz'), + ecuador(value: 'ec'), + egypt(value: 'eg'), + eritrea(value: 'er'), + spain(value: 'es'), + estonia(value: 'ee'), + ethiopia(value: 'et'), + finland(value: 'fi'), + fiji(value: 'fj'), + france(value: 'fr'), + micronesiaFederatedStatesOf(value: 'fm'), + gabon(value: 'ga'), + unitedKingdom(value: 'gb'), + georgia(value: 'ge'), + ghana(value: 'gh'), + guinea(value: 'gn'), + gambia(value: 'gm'), + guineaBissau(value: 'gw'), + equatorialGuinea(value: 'gq'), + greece(value: 'gr'), + grenada(value: 'gd'), + guatemala(value: 'gt'), + guyana(value: 'gy'), + honduras(value: 'hn'), + croatia(value: 'hr'), + haiti(value: 'ht'), + hungary(value: 'hu'), + indonesia(value: 'id'), + india(value: 'in'), + ireland(value: 'ie'), + iranIslamicRepublicOf(value: 'ir'), + iraq(value: 'iq'), + iceland(value: 'is'), + israel(value: 'il'), + italy(value: 'it'), + jamaica(value: 'jm'), + jordan(value: 'jo'), + japan(value: 'jp'), + kazakhstan(value: 'kz'), + kenya(value: 'ke'), + kyrgyzstan(value: 'kg'), + cambodia(value: 'kh'), + kiribati(value: 'ki'), + saintKittsAndNevis(value: 'kn'), + southKorea(value: 'kr'), + kuwait(value: 'kw'), + laoPeopleSDemocraticRepublic(value: 'la'), + lebanon(value: 'lb'), + liberia(value: 'lr'), + libya(value: 'ly'), + saintLucia(value: 'lc'), + liechtenstein(value: 'li'), + sriLanka(value: 'lk'), + lesotho(value: 'ls'), + lithuania(value: 'lt'), + luxembourg(value: 'lu'), + latvia(value: 'lv'), + morocco(value: 'ma'), + monaco(value: 'mc'), + moldova(value: 'md'), + madagascar(value: 'mg'), + maldives(value: 'mv'), + mexico(value: 'mx'), + marshallIslands(value: 'mh'), + northMacedonia(value: 'mk'), + mali(value: 'ml'), + malta(value: 'mt'), + myanmar(value: 'mm'), + montenegro(value: 'me'), + mongolia(value: 'mn'), + mozambique(value: 'mz'), + mauritania(value: 'mr'), + mauritius(value: 'mu'), + malawi(value: 'mw'), + malaysia(value: 'my'), + namibia(value: 'na'), + niger(value: 'ne'), + nigeria(value: 'ng'), + nicaragua(value: 'ni'), + netherlands(value: 'nl'), + norway(value: 'no'), + nepal(value: 'np'), + nauru(value: 'nr'), + newZealand(value: 'nz'), + oman(value: 'om'), + pakistan(value: 'pk'), + panama(value: 'pa'), + peru(value: 'pe'), + philippines(value: 'ph'), + palau(value: 'pw'), + papuaNewGuinea(value: 'pg'), + poland(value: 'pl'), + frenchPolynesia(value: 'pf'), + northKorea(value: 'kp'), + portugal(value: 'pt'), + paraguay(value: 'py'), + qatar(value: 'qa'), + romania(value: 'ro'), + russia(value: 'ru'), + rwanda(value: 'rw'), + saudiArabia(value: 'sa'), + sudan(value: 'sd'), + senegal(value: 'sn'), + singapore(value: 'sg'), + solomonIslands(value: 'sb'), + sierraLeone(value: 'sl'), + elSalvador(value: 'sv'), + sanMarino(value: 'sm'), + somalia(value: 'so'), + serbia(value: 'rs'), + southSudan(value: 'ss'), + saoTomeAndPrincipe(value: 'st'), + suriname(value: 'sr'), + slovakia(value: 'sk'), + slovenia(value: 'si'), + sweden(value: 'se'), + eswatini(value: 'sz'), + seychelles(value: 'sc'), + syria(value: 'sy'), + chad(value: 'td'), + togo(value: 'tg'), + thailand(value: 'th'), + tajikistan(value: 'tj'), + turkmenistan(value: 'tm'), + timorLeste(value: 'tl'), + tonga(value: 'to'), + trinidadAndTobago(value: 'tt'), + tunisia(value: 'tn'), + turkey(value: 'tr'), + tuvalu(value: 'tv'), + tanzania(value: 'tz'), + uganda(value: 'ug'), + ukraine(value: 'ua'), + uruguay(value: 'uy'), + unitedStates(value: 'us'), + uzbekistan(value: 'uz'), + vaticanCity(value: 'va'), + saintVincentAndTheGrenadines(value: 'vc'), + venezuela(value: 've'), + vietnam(value: 'vn'), + vanuatu(value: 'vu'), + samoa(value: 'ws'), + yemen(value: 'ye'), + southAfrica(value: 'za'), + zambia(value: 'zm'), + zimbabwe(value: 'zw'); - const Flag({required this.value}); + const Flag({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/image_format.dart b/lib/src/enums/image_format.dart index 2ab5d7b9..66527dfa 100644 --- a/lib/src/enums/image_format.dart +++ b/lib/src/enums/image_format.dart @@ -1,15 +1,17 @@ part of '../../enums.dart'; enum ImageFormat { - jpg(value: 'jpg'), - jpeg(value: 'jpeg'), - gif(value: 'gif'), - png(value: 'png'), - webp(value: 'webp'); + jpg(value: 'jpg'), + jpeg(value: 'jpeg'), + gif(value: 'gif'), + png(value: 'png'), + webp(value: 'webp'); - const ImageFormat({required this.value}); + const ImageFormat({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/image_gravity.dart b/lib/src/enums/image_gravity.dart index 88029044..79bc4d62 100644 --- a/lib/src/enums/image_gravity.dart +++ b/lib/src/enums/image_gravity.dart @@ -1,19 +1,21 @@ part of '../../enums.dart'; enum ImageGravity { - center(value: 'center'), - topLeft(value: 'top-left'), - top(value: 'top'), - topRight(value: 'top-right'), - left(value: 'left'), - right(value: 'right'), - bottomLeft(value: 'bottom-left'), - bottom(value: 'bottom'), - bottomRight(value: 'bottom-right'); + center(value: 'center'), + topLeft(value: 'top-left'), + top(value: 'top'), + topRight(value: 'top-right'), + left(value: 'left'), + right(value: 'right'), + bottomLeft(value: 'bottom-left'), + bottom(value: 'bottom'), + bottomRight(value: 'bottom-right'); - const ImageGravity({required this.value}); + const ImageGravity({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/index_type.dart b/lib/src/enums/index_type.dart index b101d35f..8d86530d 100644 --- a/lib/src/enums/index_type.dart +++ b/lib/src/enums/index_type.dart @@ -1,13 +1,15 @@ part of '../../enums.dart'; enum IndexType { - key(value: 'key'), - fulltext(value: 'fulltext'), - unique(value: 'unique'); + key(value: 'key'), + fulltext(value: 'fulltext'), + unique(value: 'unique'); - const IndexType({required this.value}); + const IndexType({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/messaging_provider_type.dart b/lib/src/enums/messaging_provider_type.dart index c69bf01e..a6859648 100644 --- a/lib/src/enums/messaging_provider_type.dart +++ b/lib/src/enums/messaging_provider_type.dart @@ -1,13 +1,15 @@ part of '../../enums.dart'; enum MessagingProviderType { - email(value: 'email'), - sms(value: 'sms'), - push(value: 'push'); + email(value: 'email'), + sms(value: 'sms'), + push(value: 'push'); - const MessagingProviderType({required this.value}); + const MessagingProviderType({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/name.dart b/lib/src/enums/name.dart index cb35c288..638017f7 100644 --- a/lib/src/enums/name.dart +++ b/lib/src/enums/name.dart @@ -1,22 +1,24 @@ part of '../../enums.dart'; enum Name { - v1Database(value: 'v1-database'), - v1Deletes(value: 'v1-deletes'), - v1Audits(value: 'v1-audits'), - v1Mails(value: 'v1-mails'), - v1Functions(value: 'v1-functions'), - v1Usage(value: 'v1-usage'), - v1UsageDump(value: 'v1-usage-dump'), - v1Webhooks(value: 'v1-webhooks'), - v1Certificates(value: 'v1-certificates'), - v1Builds(value: 'v1-builds'), - v1Messaging(value: 'v1-messaging'), - v1Migrations(value: 'v1-migrations'); + v1Database(value: 'v1-database'), + v1Deletes(value: 'v1-deletes'), + v1Audits(value: 'v1-audits'), + v1Mails(value: 'v1-mails'), + v1Functions(value: 'v1-functions'), + v1Usage(value: 'v1-usage'), + v1UsageDump(value: 'v1-usage-dump'), + v1Webhooks(value: 'v1-webhooks'), + v1Certificates(value: 'v1-certificates'), + v1Builds(value: 'v1-builds'), + v1Messaging(value: 'v1-messaging'), + v1Migrations(value: 'v1-migrations'); - const Name({required this.value}); + const Name({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/o_auth_provider.dart b/lib/src/enums/o_auth_provider.dart index 2bc1a82a..b09e9df2 100644 --- a/lib/src/enums/o_auth_provider.dart +++ b/lib/src/enums/o_auth_provider.dart @@ -1,49 +1,51 @@ part of '../../enums.dart'; enum OAuthProvider { - amazon(value: 'amazon'), - apple(value: 'apple'), - auth0(value: 'auth0'), - authentik(value: 'authentik'), - autodesk(value: 'autodesk'), - bitbucket(value: 'bitbucket'), - bitly(value: 'bitly'), - box(value: 'box'), - dailymotion(value: 'dailymotion'), - discord(value: 'discord'), - disqus(value: 'disqus'), - dropbox(value: 'dropbox'), - etsy(value: 'etsy'), - facebook(value: 'facebook'), - github(value: 'github'), - gitlab(value: 'gitlab'), - google(value: 'google'), - linkedin(value: 'linkedin'), - microsoft(value: 'microsoft'), - notion(value: 'notion'), - oidc(value: 'oidc'), - okta(value: 'okta'), - paypal(value: 'paypal'), - paypalSandbox(value: 'paypalSandbox'), - podio(value: 'podio'), - salesforce(value: 'salesforce'), - slack(value: 'slack'), - spotify(value: 'spotify'), - stripe(value: 'stripe'), - tradeshift(value: 'tradeshift'), - tradeshiftBox(value: 'tradeshiftBox'), - twitch(value: 'twitch'), - wordpress(value: 'wordpress'), - yahoo(value: 'yahoo'), - yammer(value: 'yammer'), - yandex(value: 'yandex'), - zoho(value: 'zoho'), - zoom(value: 'zoom'), - mock(value: 'mock'); + amazon(value: 'amazon'), + apple(value: 'apple'), + auth0(value: 'auth0'), + authentik(value: 'authentik'), + autodesk(value: 'autodesk'), + bitbucket(value: 'bitbucket'), + bitly(value: 'bitly'), + box(value: 'box'), + dailymotion(value: 'dailymotion'), + discord(value: 'discord'), + disqus(value: 'disqus'), + dropbox(value: 'dropbox'), + etsy(value: 'etsy'), + facebook(value: 'facebook'), + github(value: 'github'), + gitlab(value: 'gitlab'), + google(value: 'google'), + linkedin(value: 'linkedin'), + microsoft(value: 'microsoft'), + notion(value: 'notion'), + oidc(value: 'oidc'), + okta(value: 'okta'), + paypal(value: 'paypal'), + paypalSandbox(value: 'paypalSandbox'), + podio(value: 'podio'), + salesforce(value: 'salesforce'), + slack(value: 'slack'), + spotify(value: 'spotify'), + stripe(value: 'stripe'), + tradeshift(value: 'tradeshift'), + tradeshiftBox(value: 'tradeshiftBox'), + twitch(value: 'twitch'), + wordpress(value: 'wordpress'), + yahoo(value: 'yahoo'), + yammer(value: 'yammer'), + yandex(value: 'yandex'), + zoho(value: 'zoho'), + zoom(value: 'zoom'), + mock(value: 'mock'); - const OAuthProvider({required this.value}); + const OAuthProvider({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/password_hash.dart b/lib/src/enums/password_hash.dart index 9d98c26a..510ee260 100644 --- a/lib/src/enums/password_hash.dart +++ b/lib/src/enums/password_hash.dart @@ -1,21 +1,23 @@ part of '../../enums.dart'; enum PasswordHash { - sha1(value: 'sha1'), - sha224(value: 'sha224'), - sha256(value: 'sha256'), - sha384(value: 'sha384'), - sha512224(value: 'sha512/224'), - sha512256(value: 'sha512/256'), - sha512(value: 'sha512'), - sha3224(value: 'sha3-224'), - sha3256(value: 'sha3-256'), - sha3384(value: 'sha3-384'), - sha3512(value: 'sha3-512'); + sha1(value: 'sha1'), + sha224(value: 'sha224'), + sha256(value: 'sha256'), + sha384(value: 'sha384'), + sha512224(value: 'sha512/224'), + sha512256(value: 'sha512/256'), + sha512(value: 'sha512'), + sha3224(value: 'sha3-224'), + sha3256(value: 'sha3-256'), + sha3384(value: 'sha3-384'), + sha3512(value: 'sha3-512'); - const PasswordHash({required this.value}); + const PasswordHash({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/relation_mutate.dart b/lib/src/enums/relation_mutate.dart index b215a8fa..9f4c1a85 100644 --- a/lib/src/enums/relation_mutate.dart +++ b/lib/src/enums/relation_mutate.dart @@ -1,13 +1,15 @@ part of '../../enums.dart'; enum RelationMutate { - cascade(value: 'cascade'), - restrict(value: 'restrict'), - setNull(value: 'setNull'); + cascade(value: 'cascade'), + restrict(value: 'restrict'), + setNull(value: 'setNull'); - const RelationMutate({required this.value}); + const RelationMutate({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/relationship_type.dart b/lib/src/enums/relationship_type.dart index 30efc944..301bc61d 100644 --- a/lib/src/enums/relationship_type.dart +++ b/lib/src/enums/relationship_type.dart @@ -1,14 +1,16 @@ part of '../../enums.dart'; enum RelationshipType { - oneToOne(value: 'oneToOne'), - manyToOne(value: 'manyToOne'), - manyToMany(value: 'manyToMany'), - oneToMany(value: 'oneToMany'); + oneToOne(value: 'oneToOne'), + manyToOne(value: 'manyToOne'), + manyToMany(value: 'manyToMany'), + oneToMany(value: 'oneToMany'); - const RelationshipType({required this.value}); + const RelationshipType({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/runtime.dart b/lib/src/enums/runtime.dart index ea94204e..6a0aec49 100644 --- a/lib/src/enums/runtime.dart +++ b/lib/src/enums/runtime.dart @@ -1,56 +1,61 @@ part of '../../enums.dart'; enum Runtime { - node145(value: 'node-14.5'), - node160(value: 'node-16.0'), - node180(value: 'node-18.0'), - node190(value: 'node-19.0'), - node200(value: 'node-20.0'), - node210(value: 'node-21.0'), - php80(value: 'php-8.0'), - php81(value: 'php-8.1'), - php82(value: 'php-8.2'), - php83(value: 'php-8.3'), - ruby30(value: 'ruby-3.0'), - ruby31(value: 'ruby-3.1'), - ruby32(value: 'ruby-3.2'), - ruby33(value: 'ruby-3.3'), - python38(value: 'python-3.8'), - python39(value: 'python-3.9'), - python310(value: 'python-3.10'), - python311(value: 'python-3.11'), - python312(value: 'python-3.12'), - pythonMl311(value: 'python-ml-3.11'), - deno140(value: 'deno-1.40'), - dart215(value: 'dart-2.15'), - dart216(value: 'dart-2.16'), - dart217(value: 'dart-2.17'), - dart218(value: 'dart-2.18'), - dart30(value: 'dart-3.0'), - dart31(value: 'dart-3.1'), - dart33(value: 'dart-3.3'), - dotnet31(value: 'dotnet-3.1'), - dotnet60(value: 'dotnet-6.0'), - dotnet70(value: 'dotnet-7.0'), - java80(value: 'java-8.0'), - java110(value: 'java-11.0'), - java170(value: 'java-17.0'), - java180(value: 'java-18.0'), - java210(value: 'java-21.0'), - swift55(value: 'swift-5.5'), - swift58(value: 'swift-5.8'), - swift59(value: 'swift-5.9'), - kotlin16(value: 'kotlin-1.6'), - kotlin18(value: 'kotlin-1.8'), - kotlin19(value: 'kotlin-1.9'), - cpp17(value: 'cpp-17'), - cpp20(value: 'cpp-20'), - bun10(value: 'bun-1.0'), - go123(value: 'go-1.23'); + node145(value: 'node-14.5'), + node160(value: 'node-16.0'), + node180(value: 'node-18.0'), + node190(value: 'node-19.0'), + node200(value: 'node-20.0'), + node210(value: 'node-21.0'), + php80(value: 'php-8.0'), + php81(value: 'php-8.1'), + php82(value: 'php-8.2'), + php83(value: 'php-8.3'), + ruby30(value: 'ruby-3.0'), + ruby31(value: 'ruby-3.1'), + ruby32(value: 'ruby-3.2'), + ruby33(value: 'ruby-3.3'), + python38(value: 'python-3.8'), + python39(value: 'python-3.9'), + python310(value: 'python-3.10'), + python311(value: 'python-3.11'), + python312(value: 'python-3.12'), + pythonMl311(value: 'python-ml-3.11'), + deno121(value: 'deno-1.21'), + deno124(value: 'deno-1.24'), + deno135(value: 'deno-1.35'), + deno140(value: 'deno-1.40'), + dart215(value: 'dart-2.15'), + dart216(value: 'dart-2.16'), + dart217(value: 'dart-2.17'), + dart218(value: 'dart-2.18'), + dart30(value: 'dart-3.0'), + dart31(value: 'dart-3.1'), + dart33(value: 'dart-3.3'), + dotnet31(value: 'dotnet-3.1'), + dotnet60(value: 'dotnet-6.0'), + dotnet70(value: 'dotnet-7.0'), + java80(value: 'java-8.0'), + java110(value: 'java-11.0'), + java170(value: 'java-17.0'), + java180(value: 'java-18.0'), + java210(value: 'java-21.0'), + swift55(value: 'swift-5.5'), + swift58(value: 'swift-5.8'), + swift59(value: 'swift-5.9'), + kotlin16(value: 'kotlin-1.6'), + kotlin18(value: 'kotlin-1.8'), + kotlin19(value: 'kotlin-1.9'), + cpp17(value: 'cpp-17'), + cpp20(value: 'cpp-20'), + bun10(value: 'bun-1.0'), + go123(value: 'go-1.23'); - const Runtime({required this.value}); + const Runtime({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/smtp_encryption.dart b/lib/src/enums/smtp_encryption.dart index cb6cee26..6c880ed6 100644 --- a/lib/src/enums/smtp_encryption.dart +++ b/lib/src/enums/smtp_encryption.dart @@ -1,13 +1,15 @@ part of '../../enums.dart'; enum SmtpEncryption { - none(value: 'none'), - ssl(value: 'ssl'), - tls(value: 'tls'); + none(value: 'none'), + ssl(value: 'ssl'), + tls(value: 'tls'); - const SmtpEncryption({required this.value}); + const SmtpEncryption({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/exception.dart b/lib/src/exception.dart index 679e27b8..f579bfb8 100644 --- a/lib/src/exception.dart +++ b/lib/src/exception.dart @@ -13,7 +13,7 @@ class AppwriteException implements Exception { /// Initializes an Appwrite Exception. AppwriteException([this.message = "", this.code, this.type, this.response]); - + /// Returns the error type, message, and code. @override String toString() { diff --git a/lib/src/input_file.dart b/lib/src/input_file.dart deleted file mode 100644 index c0be7c04..00000000 --- a/lib/src/input_file.dart +++ /dev/null @@ -1,48 +0,0 @@ -import 'exception.dart'; - -/// Helper class to handle files. -class InputFile { - late final String? path; - late final List? bytes; - final String? filename; - final String? contentType; - - @Deprecated('Use `InputFile.fromPath` or `InputFile.fromBytes` instead.') - InputFile({this.path, this.filename, this.contentType, this.bytes}) { - if (path == null && bytes == null) { - throw AppwriteException('One of `path` or `bytes` is required'); - } - } - - InputFile._({this.path, this.filename, this.contentType, this.bytes}) { - if (path == null && bytes == null) { - throw AppwriteException('One of `path` or `bytes` is required'); - } - } - - /// Provide a file using `path` - factory InputFile.fromPath({ - required String path, - String? filename, - String? contentType, - }) { - return InputFile._( - path: path, - filename: filename, - contentType: contentType, - ); - } - - /// Provide a file using `bytes` - factory InputFile.fromBytes({ - required List bytes, - required String filename, - String? contentType, - }) { - return InputFile._( - bytes: bytes, - filename: filename, - contentType: contentType, - ); - } -} diff --git a/lib/src/models/algo_argon2.dart b/lib/src/models/algo_argon2.dart index 4145f701..92fa2593 100644 --- a/lib/src/models/algo_argon2.dart +++ b/lib/src/models/algo_argon2.dart @@ -2,40 +2,40 @@ part of '../../models.dart'; /// AlgoArgon2 class AlgoArgon2 implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; + /// Memory used to compute hash. + final int memoryCost; + /// Amount of time consumed to compute hash + final int timeCost; + /// Number of threads used to compute hash. + final int threads; - /// Memory used to compute hash. - final int memoryCost; + AlgoArgon2({ + required this.type, + required this.memoryCost, + required this.timeCost, + required this.threads, + }); - /// Amount of time consumed to compute hash - final int timeCost; + factory AlgoArgon2.fromMap(Map map) { + return AlgoArgon2( + type: map['type'].toString(), + memoryCost: (map['memoryCost'] is String) ? + int.tryParse(map['memoryCost']) ?? 0:map['memoryCost'] ?? 0, + timeCost: (map['timeCost'] is String) ? + int.tryParse(map['timeCost']) ?? 0:map['timeCost'] ?? 0, + threads: (map['threads'] is String) ? + int.tryParse(map['threads']) ?? 0:map['threads'] ?? 0, + ); + } - /// Number of threads used to compute hash. - final int threads; - - AlgoArgon2({ - required this.type, - required this.memoryCost, - required this.timeCost, - required this.threads, - }); - - factory AlgoArgon2.fromMap(Map map) { - return AlgoArgon2( - type: map['type'].toString(), - memoryCost: map['memoryCost'], - timeCost: map['timeCost'], - threads: map['threads'], - ); - } - - Map toMap() { - return { - "type": type, - "memoryCost": memoryCost, - "timeCost": timeCost, - "threads": threads, - }; - } + Map toMap() { + return { + "type": type, + "memoryCost": memoryCost, + "timeCost": timeCost, + "threads": threads, + }; + } } diff --git a/lib/src/models/algo_bcrypt.dart b/lib/src/models/algo_bcrypt.dart index 2ba0c398..c9f67200 100644 --- a/lib/src/models/algo_bcrypt.dart +++ b/lib/src/models/algo_bcrypt.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoBcrypt class AlgoBcrypt implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoBcrypt({ - required this.type, - }); + AlgoBcrypt({ + required this.type, + }); - factory AlgoBcrypt.fromMap(Map map) { - return AlgoBcrypt( - type: map['type'].toString(), - ); - } + factory AlgoBcrypt.fromMap(Map map) { + return AlgoBcrypt( + type: map['type'].toString(), + ); + } - Map toMap() { - return { - "type": type, - }; - } + Map toMap() { + return { + "type": type, + }; + } } diff --git a/lib/src/models/algo_md5.dart b/lib/src/models/algo_md5.dart index 8bdfca6f..2fabb416 100644 --- a/lib/src/models/algo_md5.dart +++ b/lib/src/models/algo_md5.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoMD5 class AlgoMd5 implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoMd5({ - required this.type, - }); + AlgoMd5({ + required this.type, + }); - factory AlgoMd5.fromMap(Map map) { - return AlgoMd5( - type: map['type'].toString(), - ); - } + factory AlgoMd5.fromMap(Map map) { + return AlgoMd5( + type: map['type'].toString(), + ); + } - Map toMap() { - return { - "type": type, - }; - } + Map toMap() { + return { + "type": type, + }; + } } diff --git a/lib/src/models/algo_phpass.dart b/lib/src/models/algo_phpass.dart index 4f5f9179..fdcee07a 100644 --- a/lib/src/models/algo_phpass.dart +++ b/lib/src/models/algo_phpass.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoPHPass class AlgoPhpass implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoPhpass({ - required this.type, - }); + AlgoPhpass({ + required this.type, + }); - factory AlgoPhpass.fromMap(Map map) { - return AlgoPhpass( - type: map['type'].toString(), - ); - } + factory AlgoPhpass.fromMap(Map map) { + return AlgoPhpass( + type: map['type'].toString(), + ); + } - Map toMap() { - return { - "type": type, - }; - } + Map toMap() { + return { + "type": type, + }; + } } diff --git a/lib/src/models/algo_scrypt.dart b/lib/src/models/algo_scrypt.dart index fec6f65a..c3e55453 100644 --- a/lib/src/models/algo_scrypt.dart +++ b/lib/src/models/algo_scrypt.dart @@ -2,46 +2,46 @@ part of '../../models.dart'; /// AlgoScrypt class AlgoScrypt implements Model { - /// Algo type. - final String type; - - /// CPU complexity of computed hash. - final int costCpu; - - /// Memory complexity of computed hash. - final int costMemory; - - /// Parallelization of computed hash. - final int costParallel; - - /// Length used to compute hash. - final int length; - - AlgoScrypt({ - required this.type, - required this.costCpu, - required this.costMemory, - required this.costParallel, - required this.length, - }); - - factory AlgoScrypt.fromMap(Map map) { - return AlgoScrypt( - type: map['type'].toString(), - costCpu: map['costCpu'], - costMemory: map['costMemory'], - costParallel: map['costParallel'], - length: map['length'], - ); - } - - Map toMap() { - return { - "type": type, - "costCpu": costCpu, - "costMemory": costMemory, - "costParallel": costParallel, - "length": length, - }; - } + /// Algo type. + final String type; + /// CPU complexity of computed hash. + final int costCpu; + /// Memory complexity of computed hash. + final int costMemory; + /// Parallelization of computed hash. + final int costParallel; + /// Length used to compute hash. + final int length; + + AlgoScrypt({ + required this.type, + required this.costCpu, + required this.costMemory, + required this.costParallel, + required this.length, + }); + + factory AlgoScrypt.fromMap(Map map) { + return AlgoScrypt( + type: map['type'].toString(), + costCpu: (map['costCpu'] is String) ? + int.tryParse(map['costCpu']) ?? 0:map['costCpu'] ?? 0, + costMemory: (map['costMemory'] is String) ? + int.tryParse(map['costMemory']) ?? 0:map['costMemory'] ?? 0, + costParallel: (map['costParallel'] is String) ? + int.tryParse(map['costParallel']) ?? 0:map['costParallel'] ?? 0, + length: (map['length'] is String) ? + int.tryParse(map['length']) ?? 0:map['length'] ?? 0, + ); + } + + Map toMap() { + return { + "type": type, + "costCpu": costCpu, + "costMemory": costMemory, + "costParallel": costParallel, + "length": length, + }; + } } diff --git a/lib/src/models/algo_scrypt_modified.dart b/lib/src/models/algo_scrypt_modified.dart index 0e80700f..b10b14a6 100644 --- a/lib/src/models/algo_scrypt_modified.dart +++ b/lib/src/models/algo_scrypt_modified.dart @@ -2,40 +2,37 @@ part of '../../models.dart'; /// AlgoScryptModified class AlgoScryptModified implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; + /// Salt used to compute hash. + final String salt; + /// Separator used to compute hash. + final String saltSeparator; + /// Key used to compute hash. + final String signerKey; - /// Salt used to compute hash. - final String salt; + AlgoScryptModified({ + required this.type, + required this.salt, + required this.saltSeparator, + required this.signerKey, + }); - /// Separator used to compute hash. - final String saltSeparator; + factory AlgoScryptModified.fromMap(Map map) { + return AlgoScryptModified( + type: map['type'].toString(), + salt: map['salt'].toString(), + saltSeparator: map['saltSeparator'].toString(), + signerKey: map['signerKey'].toString(), + ); + } - /// Key used to compute hash. - final String signerKey; - - AlgoScryptModified({ - required this.type, - required this.salt, - required this.saltSeparator, - required this.signerKey, - }); - - factory AlgoScryptModified.fromMap(Map map) { - return AlgoScryptModified( - type: map['type'].toString(), - salt: map['salt'].toString(), - saltSeparator: map['saltSeparator'].toString(), - signerKey: map['signerKey'].toString(), - ); - } - - Map toMap() { - return { - "type": type, - "salt": salt, - "saltSeparator": saltSeparator, - "signerKey": signerKey, - }; - } + Map toMap() { + return { + "type": type, + "salt": salt, + "saltSeparator": saltSeparator, + "signerKey": signerKey, + }; + } } diff --git a/lib/src/models/algo_sha.dart b/lib/src/models/algo_sha.dart index 47068be0..5f3e1654 100644 --- a/lib/src/models/algo_sha.dart +++ b/lib/src/models/algo_sha.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoSHA class AlgoSha implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoSha({ - required this.type, - }); + AlgoSha({ + required this.type, + }); - factory AlgoSha.fromMap(Map map) { - return AlgoSha( - type: map['type'].toString(), - ); - } + factory AlgoSha.fromMap(Map map) { + return AlgoSha( + type: map['type'].toString(), + ); + } - Map toMap() { - return { - "type": type, - }; - } + Map toMap() { + return { + "type": type, + }; + } } diff --git a/lib/src/models/attribute_boolean.dart b/lib/src/models/attribute_boolean.dart index 0b8ca599..480c2042 100644 --- a/lib/src/models/attribute_boolean.dart +++ b/lib/src/models/attribute_boolean.dart @@ -2,58 +2,52 @@ part of '../../models.dart'; /// AttributeBoolean class AttributeBoolean implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final bool? xdefault; - - AttributeBoolean({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - this.xdefault, - }); - - factory AttributeBoolean.fromMap(Map map) { - return AttributeBoolean( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - xdefault: map['default'], - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final bool? xdefault; + + AttributeBoolean({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + this.xdefault, + }); + + factory AttributeBoolean.fromMap(Map map) { + return AttributeBoolean( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + xdefault: map['default'], + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_datetime.dart b/lib/src/models/attribute_datetime.dart index c4c96637..078a0723 100644 --- a/lib/src/models/attribute_datetime.dart +++ b/lib/src/models/attribute_datetime.dart @@ -2,64 +2,57 @@ part of '../../models.dart'; /// AttributeDatetime class AttributeDatetime implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// ISO 8601 format. - final String format; - - /// Default value for attribute when not provided. Only null is optional - final String? xdefault; - - AttributeDatetime({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.format, - this.xdefault, - }); - - factory AttributeDatetime.fromMap(Map map) { - return AttributeDatetime( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "format": format, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// ISO 8601 format. + final String format; + /// Default value for attribute when not provided. Only null is optional + final String? xdefault; + + AttributeDatetime({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.format, + this.xdefault, + }); + + factory AttributeDatetime.fromMap(Map map) { + return AttributeDatetime( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_email.dart b/lib/src/models/attribute_email.dart index 5d2fc8bd..08a67934 100644 --- a/lib/src/models/attribute_email.dart +++ b/lib/src/models/attribute_email.dart @@ -2,64 +2,57 @@ part of '../../models.dart'; /// AttributeEmail class AttributeEmail implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// String format. - final String format; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeEmail({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.format, - this.xdefault, - }); - - factory AttributeEmail.fromMap(Map map) { - return AttributeEmail( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "format": format, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// String format. + final String format; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeEmail({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.format, + this.xdefault, + }); + + factory AttributeEmail.fromMap(Map map) { + return AttributeEmail( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_enum.dart b/lib/src/models/attribute_enum.dart index 0017a44e..d461ecf4 100644 --- a/lib/src/models/attribute_enum.dart +++ b/lib/src/models/attribute_enum.dart @@ -2,70 +2,62 @@ part of '../../models.dart'; /// AttributeEnum class AttributeEnum implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Array of elements in enumerated type. - final List elements; - - /// String format. - final String format; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeEnum({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.elements, - required this.format, - this.xdefault, - }); - - factory AttributeEnum.fromMap(Map map) { - return AttributeEnum( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - elements: map['elements'] ?? [], - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "elements": elements, - "format": format, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Array of elements in enumerated type. + final List elements; + /// String format. + final String format; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeEnum({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.elements, + required this.format, + this.xdefault, + }); + + factory AttributeEnum.fromMap(Map map) { + return AttributeEnum( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + elements: map['elements'] ?? [], + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "elements": elements, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_float.dart b/lib/src/models/attribute_float.dart index 7c982afb..6d085aa4 100644 --- a/lib/src/models/attribute_float.dart +++ b/lib/src/models/attribute_float.dart @@ -2,70 +2,62 @@ part of '../../models.dart'; /// AttributeFloat class AttributeFloat implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Minimum value to enforce for new documents. - final double? min; - - /// Maximum value to enforce for new documents. - final double? max; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final double? xdefault; - - AttributeFloat({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - this.min, - this.max, - this.xdefault, - }); - - factory AttributeFloat.fromMap(Map map) { - return AttributeFloat( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - min: map['min']?.toDouble(), - max: map['max']?.toDouble(), - xdefault: map['default']?.toDouble(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "min": min, - "max": max, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Minimum value to enforce for new documents. + final double? min; + /// Maximum value to enforce for new documents. + final double? max; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final double? xdefault; + + AttributeFloat({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + this.min, + this.max, + this.xdefault, + }); + + factory AttributeFloat.fromMap(Map map) { + return AttributeFloat( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + min: map['min']?.toDouble(), + max: map['max']?.toDouble(), + xdefault: map['default']?.toDouble(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "min": min, + "max": max, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_integer.dart b/lib/src/models/attribute_integer.dart index 0316f777..83e36858 100644 --- a/lib/src/models/attribute_integer.dart +++ b/lib/src/models/attribute_integer.dart @@ -2,70 +2,65 @@ part of '../../models.dart'; /// AttributeInteger class AttributeInteger implements Model { - /// Attribute Key. - final String key; + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Minimum value to enforce for new documents. + final int? min; + /// Maximum value to enforce for new documents. + final int? max; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final int? xdefault; - /// Attribute type. - final String type; + AttributeInteger({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + this.min, + this.max, + this.xdefault, + }); - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; + factory AttributeInteger.fromMap(Map map) { + return AttributeInteger( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + min: (map['min'] is String) ? + int.tryParse(map['min']):map['min'], + max: (map['max'] is String) ? + int.tryParse(map['max']):map['max'], + xdefault: (map['default'] is String) ? + int.tryParse(map['default']):map['default'], + ); + } - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Minimum value to enforce for new documents. - final int? min; - - /// Maximum value to enforce for new documents. - final int? max; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final int? xdefault; - - AttributeInteger({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - this.min, - this.max, - this.xdefault, - }); - - factory AttributeInteger.fromMap(Map map) { - return AttributeInteger( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - min: map['min'], - max: map['max'], - xdefault: map['default'], - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "min": min, - "max": max, - "default": xdefault, - }; - } + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "min": min, + "max": max, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_ip.dart b/lib/src/models/attribute_ip.dart index a63dd566..960f7064 100644 --- a/lib/src/models/attribute_ip.dart +++ b/lib/src/models/attribute_ip.dart @@ -2,64 +2,57 @@ part of '../../models.dart'; /// AttributeIP class AttributeIp implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// String format. - final String format; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeIp({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.format, - this.xdefault, - }); - - factory AttributeIp.fromMap(Map map) { - return AttributeIp( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "format": format, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// String format. + final String format; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeIp({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.format, + this.xdefault, + }); + + factory AttributeIp.fromMap(Map map) { + return AttributeIp( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_list.dart b/lib/src/models/attribute_list.dart index 4d9846c1..e15a0b35 100644 --- a/lib/src/models/attribute_list.dart +++ b/lib/src/models/attribute_list.dart @@ -2,28 +2,28 @@ part of '../../models.dart'; /// Attributes List class AttributeList implements Model { - /// Total number of attributes in the given collection. - final int total; + /// Total number of attributes in the given collection. + final int total; + /// List of attributes. + final List attributes; - /// List of attributes. - final List attributes; + AttributeList({ + required this.total, + required this.attributes, + }); - AttributeList({ - required this.total, - required this.attributes, - }); + factory AttributeList.fromMap(Map map) { + return AttributeList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + attributes: map['attributes'] ?? [], + ); + } - factory AttributeList.fromMap(Map map) { - return AttributeList( - total: map['total'], - attributes: map['attributes'] ?? [], - ); - } - - Map toMap() { - return { - "total": total, - "attributes": attributes, - }; - } + Map toMap() { + return { + "total": total, + "attributes": attributes, + }; + } } diff --git a/lib/src/models/attribute_relationship.dart b/lib/src/models/attribute_relationship.dart index 0230d9f9..d22c30d4 100644 --- a/lib/src/models/attribute_relationship.dart +++ b/lib/src/models/attribute_relationship.dart @@ -2,88 +2,77 @@ part of '../../models.dart'; /// AttributeRelationship class AttributeRelationship implements Model { - /// Attribute Key. - final String key; + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// The ID of the related collection. + final String relatedCollection; + /// The type of the relationship. + final String relationType; + /// Is the relationship two-way? + final bool twoWay; + /// The key of the two-way relationship. + final String twoWayKey; + /// How deleting the parent document will propagate to child documents. + final String onDelete; + /// Whether this is the parent or child side of the relationship + final String side; - /// Attribute type. - final String type; + AttributeRelationship({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.relatedCollection, + required this.relationType, + required this.twoWay, + required this.twoWayKey, + required this.onDelete, + required this.side, + }); - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; + factory AttributeRelationship.fromMap(Map map) { + return AttributeRelationship( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + relatedCollection: map['relatedCollection'].toString(), + relationType: map['relationType'].toString(), + twoWay: map['twoWay'], + twoWayKey: map['twoWayKey'].toString(), + onDelete: map['onDelete'].toString(), + side: map['side'].toString(), + ); + } - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// The ID of the related collection. - final String relatedCollection; - - /// The type of the relationship. - final String relationType; - - /// Is the relationship two-way? - final bool twoWay; - - /// The key of the two-way relationship. - final String twoWayKey; - - /// How deleting the parent document will propagate to child documents. - final String onDelete; - - /// Whether this is the parent or child side of the relationship - final String side; - - AttributeRelationship({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.relatedCollection, - required this.relationType, - required this.twoWay, - required this.twoWayKey, - required this.onDelete, - required this.side, - }); - - factory AttributeRelationship.fromMap(Map map) { - return AttributeRelationship( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - relatedCollection: map['relatedCollection'].toString(), - relationType: map['relationType'].toString(), - twoWay: map['twoWay'], - twoWayKey: map['twoWayKey'].toString(), - onDelete: map['onDelete'].toString(), - side: map['side'].toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "relatedCollection": relatedCollection, - "relationType": relationType, - "twoWay": twoWay, - "twoWayKey": twoWayKey, - "onDelete": onDelete, - "side": side, - }; - } + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "relatedCollection": relatedCollection, + "relationType": relationType, + "twoWay": twoWay, + "twoWayKey": twoWayKey, + "onDelete": onDelete, + "side": side, + }; + } } diff --git a/lib/src/models/attribute_string.dart b/lib/src/models/attribute_string.dart index 86c8654b..c483317c 100644 --- a/lib/src/models/attribute_string.dart +++ b/lib/src/models/attribute_string.dart @@ -2,64 +2,58 @@ part of '../../models.dart'; /// AttributeString class AttributeString implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Attribute size. - final int size; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeString({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.size, - this.xdefault, - }); - - factory AttributeString.fromMap(Map map) { - return AttributeString( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - size: map['size'], - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "size": size, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Attribute size. + final int size; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeString({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.size, + this.xdefault, + }); + + factory AttributeString.fromMap(Map map) { + return AttributeString( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + size: (map['size'] is String) ? + int.tryParse(map['size']) ?? 0:map['size'] ?? 0, + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "size": size, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_url.dart b/lib/src/models/attribute_url.dart index 0a0d183f..691cfcf6 100644 --- a/lib/src/models/attribute_url.dart +++ b/lib/src/models/attribute_url.dart @@ -2,64 +2,57 @@ part of '../../models.dart'; /// AttributeURL class AttributeUrl implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// String format. - final String format; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeUrl({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.format, - this.xdefault, - }); - - factory AttributeUrl.fromMap(Map map) { - return AttributeUrl( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "format": format, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// String format. + final String format; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeUrl({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.format, + this.xdefault, + }); + + factory AttributeUrl.fromMap(Map map) { + return AttributeUrl( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/bucket.dart b/lib/src/models/bucket.dart index a3361589..b72c0392 100644 --- a/lib/src/models/bucket.dart +++ b/lib/src/models/bucket.dart @@ -2,88 +2,78 @@ part of '../../models.dart'; /// Bucket class Bucket implements Model { - /// Bucket ID. - final String $id; + /// Bucket ID. + final String $id; + /// Bucket creation time in ISO 8601 format. + final String $createdAt; + /// Bucket update date in ISO 8601 format. + final String $updatedAt; + /// Bucket permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List $permissions; + /// Whether file-level security is enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). + final bool fileSecurity; + /// Bucket name. + final String name; + /// Bucket enabled. + final bool enabled; + /// Maximum file size supported. + final int maximumFileSize; + /// Allowed file extensions. + final List allowedFileExtensions; + /// Compression algorithm choosen for compression. Will be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd). + final String compression; + /// Bucket is encrypted. + final bool encryption; + /// Virus scanning is enabled. + final bool antivirus; - /// Bucket creation time in ISO 8601 format. - final String $createdAt; + Bucket({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.fileSecurity, + required this.name, + required this.enabled, + required this.maximumFileSize, + required this.allowedFileExtensions, + required this.compression, + required this.encryption, + required this.antivirus, + }); - /// Bucket update date in ISO 8601 format. - final String $updatedAt; + factory Bucket.fromMap(Map map) { + return Bucket( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + fileSecurity: map['fileSecurity'], + name: map['name'].toString(), + enabled: map['enabled'], + maximumFileSize: (map['maximumFileSize'] is String) ? + int.tryParse(map['maximumFileSize']) ?? 0:map['maximumFileSize'] ?? 0, + allowedFileExtensions: map['allowedFileExtensions'] ?? [], + compression: map['compression'].toString(), + encryption: map['encryption'], + antivirus: map['antivirus'], + ); + } - /// Bucket permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List $permissions; - - /// Whether file-level security is enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). - final bool fileSecurity; - - /// Bucket name. - final String name; - - /// Bucket enabled. - final bool enabled; - - /// Maximum file size supported. - final int maximumFileSize; - - /// Allowed file extensions. - final List allowedFileExtensions; - - /// Compression algorithm choosen for compression. Will be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd). - final String compression; - - /// Bucket is encrypted. - final bool encryption; - - /// Virus scanning is enabled. - final bool antivirus; - - Bucket({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.fileSecurity, - required this.name, - required this.enabled, - required this.maximumFileSize, - required this.allowedFileExtensions, - required this.compression, - required this.encryption, - required this.antivirus, - }); - - factory Bucket.fromMap(Map map) { - return Bucket( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - fileSecurity: map['fileSecurity'], - name: map['name'].toString(), - enabled: map['enabled'], - maximumFileSize: map['maximumFileSize'], - allowedFileExtensions: map['allowedFileExtensions'] ?? [], - compression: map['compression'].toString(), - encryption: map['encryption'], - antivirus: map['antivirus'], - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "fileSecurity": fileSecurity, - "name": name, - "enabled": enabled, - "maximumFileSize": maximumFileSize, - "allowedFileExtensions": allowedFileExtensions, - "compression": compression, - "encryption": encryption, - "antivirus": antivirus, - }; - } + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "fileSecurity": fileSecurity, + "name": name, + "enabled": enabled, + "maximumFileSize": maximumFileSize, + "allowedFileExtensions": allowedFileExtensions, + "compression": compression, + "encryption": encryption, + "antivirus": antivirus, + }; + } } diff --git a/lib/src/models/bucket_list.dart b/lib/src/models/bucket_list.dart index 849aea4a..7687eb6e 100644 --- a/lib/src/models/bucket_list.dart +++ b/lib/src/models/bucket_list.dart @@ -2,28 +2,28 @@ part of '../../models.dart'; /// Buckets List class BucketList implements Model { - /// Total number of buckets documents that matched your query. - final int total; + /// Total number of buckets documents that matched your query. + final int total; + /// List of buckets. + final List buckets; - /// List of buckets. - final List buckets; + BucketList({ + required this.total, + required this.buckets, + }); - BucketList({ - required this.total, - required this.buckets, - }); + factory BucketList.fromMap(Map map) { + return BucketList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + buckets: List.from(map['buckets'].map((p) => Bucket.fromMap(p))), + ); + } - factory BucketList.fromMap(Map map) { - return BucketList( - total: map['total'], - buckets: List.from(map['buckets'].map((p) => Bucket.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "buckets": buckets.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "buckets": buckets.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/build.dart b/lib/src/models/build.dart index ea4a3137..4c12e283 100644 --- a/lib/src/models/build.dart +++ b/lib/src/models/build.dart @@ -2,70 +2,64 @@ part of '../../models.dart'; /// Build class Build implements Model { - /// Build ID. - final String $id; + /// Build ID. + final String $id; + /// The deployment that created this build. + final String deploymentId; + /// The build status. There are a few different types and each one means something different. \nFailed - The deployment build has failed. More details can usually be found in buildStderr\nReady - The deployment build was successful and the deployment is ready to be deployed\nProcessing - The deployment is currently waiting to have a build triggered\nBuilding - The deployment is currently being built + final String status; + /// The stdout of the build. + final String stdout; + /// The stderr of the build. + final String stderr; + /// The deployment creation date in ISO 8601 format. + final String startTime; + /// The time the build was finished in ISO 8601 format. + final String endTime; + /// The build duration in seconds. + final int duration; + /// The code size in bytes. + final int size; - /// The deployment that created this build. - final String deploymentId; + Build({ + required this.$id, + required this.deploymentId, + required this.status, + required this.stdout, + required this.stderr, + required this.startTime, + required this.endTime, + required this.duration, + required this.size, + }); - /// The build status. There are a few different types and each one means something different. \nFailed - The deployment build has failed. More details can usually be found in buildStderr\nReady - The deployment build was successful and the deployment is ready to be deployed\nProcessing - The deployment is currently waiting to have a build triggered\nBuilding - The deployment is currently being built - final String status; + factory Build.fromMap(Map map) { + return Build( + $id: map['\$id'].toString(), + deploymentId: map['deploymentId'].toString(), + status: map['status'].toString(), + stdout: map['stdout'].toString(), + stderr: map['stderr'].toString(), + startTime: map['startTime'].toString(), + endTime: map['endTime'].toString(), + duration: (map['duration'] is String) ? + int.tryParse(map['duration']) ?? 0:map['duration'] ?? 0, + size: (map['size'] is String) ? + int.tryParse(map['size']) ?? 0:map['size'] ?? 0, + ); + } - /// The stdout of the build. - final String stdout; - - /// The stderr of the build. - final String stderr; - - /// The deployment creation date in ISO 8601 format. - final String startTime; - - /// The time the build was finished in ISO 8601 format. - final String endTime; - - /// The build duration in seconds. - final int duration; - - /// The code size in bytes. - final int size; - - Build({ - required this.$id, - required this.deploymentId, - required this.status, - required this.stdout, - required this.stderr, - required this.startTime, - required this.endTime, - required this.duration, - required this.size, - }); - - factory Build.fromMap(Map map) { - return Build( - $id: map['\$id'].toString(), - deploymentId: map['deploymentId'].toString(), - status: map['status'].toString(), - stdout: map['stdout'].toString(), - stderr: map['stderr'].toString(), - startTime: map['startTime'].toString(), - endTime: map['endTime'].toString(), - duration: map['duration'], - size: map['size'], - ); - } - - Map toMap() { - return { - "\$id": $id, - "deploymentId": deploymentId, - "status": status, - "stdout": stdout, - "stderr": stderr, - "startTime": startTime, - "endTime": endTime, - "duration": duration, - "size": size, - }; - } + Map toMap() { + return { + "\$id": $id, + "deploymentId": deploymentId, + "status": status, + "stdout": stdout, + "stderr": stderr, + "startTime": startTime, + "endTime": endTime, + "duration": duration, + "size": size, + }; + } } diff --git a/lib/src/models/collection.dart b/lib/src/models/collection.dart index 2595cd2f..d4649f55 100644 --- a/lib/src/models/collection.dart +++ b/lib/src/models/collection.dart @@ -2,76 +2,67 @@ part of '../../models.dart'; /// Collection class Collection implements Model { - /// Collection ID. - final String $id; + /// Collection ID. + final String $id; + /// Collection creation date in ISO 8601 format. + final String $createdAt; + /// Collection update date in ISO 8601 format. + final String $updatedAt; + /// Collection permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List $permissions; + /// Database ID. + final String databaseId; + /// Collection name. + final String name; + /// Collection enabled. Can be 'enabled' or 'disabled'. When disabled, the collection is inaccessible to users, but remains accessible to Server SDKs using API keys. + final bool enabled; + /// Whether document-level permissions are enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). + final bool documentSecurity; + /// Collection attributes. + final List attributes; + /// Collection indexes. + final List indexes; - /// Collection creation date in ISO 8601 format. - final String $createdAt; + Collection({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.databaseId, + required this.name, + required this.enabled, + required this.documentSecurity, + required this.attributes, + required this.indexes, + }); - /// Collection update date in ISO 8601 format. - final String $updatedAt; + factory Collection.fromMap(Map map) { + return Collection( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + databaseId: map['databaseId'].toString(), + name: map['name'].toString(), + enabled: map['enabled'], + documentSecurity: map['documentSecurity'], + attributes: map['attributes'] ?? [], + indexes: List.from(map['indexes'].map((p) => Index.fromMap(p))), + ); + } - /// Collection permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List $permissions; - - /// Database ID. - final String databaseId; - - /// Collection name. - final String name; - - /// Collection enabled. Can be 'enabled' or 'disabled'. When disabled, the collection is inaccessible to users, but remains accessible to Server SDKs using API keys. - final bool enabled; - - /// Whether document-level permissions are enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). - final bool documentSecurity; - - /// Collection attributes. - final List attributes; - - /// Collection indexes. - final List indexes; - - Collection({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.databaseId, - required this.name, - required this.enabled, - required this.documentSecurity, - required this.attributes, - required this.indexes, - }); - - factory Collection.fromMap(Map map) { - return Collection( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - databaseId: map['databaseId'].toString(), - name: map['name'].toString(), - enabled: map['enabled'], - documentSecurity: map['documentSecurity'], - attributes: map['attributes'] ?? [], - indexes: List.from(map['indexes'].map((p) => Index.fromMap(p))), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "databaseId": databaseId, - "name": name, - "enabled": enabled, - "documentSecurity": documentSecurity, - "attributes": attributes, - "indexes": indexes.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "databaseId": databaseId, + "name": name, + "enabled": enabled, + "documentSecurity": documentSecurity, + "attributes": attributes, + "indexes": indexes.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/collection_list.dart b/lib/src/models/collection_list.dart index 3f50e4b6..732bbf89 100644 --- a/lib/src/models/collection_list.dart +++ b/lib/src/models/collection_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Collections List class CollectionList implements Model { - /// Total number of collections documents that matched your query. - final int total; + /// Total number of collections documents that matched your query. + final int total; + /// List of collections. + final List collections; - /// List of collections. - final List collections; + CollectionList({ + required this.total, + required this.collections, + }); - CollectionList({ - required this.total, - required this.collections, - }); + factory CollectionList.fromMap(Map map) { + return CollectionList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + collections: List.from(map['collections'].map((p) => Collection.fromMap(p))), + ); + } - factory CollectionList.fromMap(Map map) { - return CollectionList( - total: map['total'], - collections: List.from( - map['collections'].map((p) => Collection.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "collections": collections.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "collections": collections.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/continent.dart b/lib/src/models/continent.dart index 990b1064..e1772f0d 100644 --- a/lib/src/models/continent.dart +++ b/lib/src/models/continent.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Continent class Continent implements Model { - /// Continent name. - final String name; + /// Continent name. + final String name; + /// Continent two letter code. + final String code; - /// Continent two letter code. - final String code; + Continent({ + required this.name, + required this.code, + }); - Continent({ - required this.name, - required this.code, - }); + factory Continent.fromMap(Map map) { + return Continent( + name: map['name'].toString(), + code: map['code'].toString(), + ); + } - factory Continent.fromMap(Map map) { - return Continent( - name: map['name'].toString(), - code: map['code'].toString(), - ); - } - - Map toMap() { - return { - "name": name, - "code": code, - }; - } + Map toMap() { + return { + "name": name, + "code": code, + }; + } } diff --git a/lib/src/models/continent_list.dart b/lib/src/models/continent_list.dart index fb4ee6f6..d6c60999 100644 --- a/lib/src/models/continent_list.dart +++ b/lib/src/models/continent_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Continents List class ContinentList implements Model { - /// Total number of continents documents that matched your query. - final int total; + /// Total number of continents documents that matched your query. + final int total; + /// List of continents. + final List continents; - /// List of continents. - final List continents; + ContinentList({ + required this.total, + required this.continents, + }); - ContinentList({ - required this.total, - required this.continents, - }); + factory ContinentList.fromMap(Map map) { + return ContinentList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + continents: List.from(map['continents'].map((p) => Continent.fromMap(p))), + ); + } - factory ContinentList.fromMap(Map map) { - return ContinentList( - total: map['total'], - continents: List.from( - map['continents'].map((p) => Continent.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "continents": continents.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "continents": continents.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/country.dart b/lib/src/models/country.dart index d11c55db..b8757434 100644 --- a/lib/src/models/country.dart +++ b/lib/src/models/country.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Country class Country implements Model { - /// Country name. - final String name; + /// Country name. + final String name; + /// Country two-character ISO 3166-1 alpha code. + final String code; - /// Country two-character ISO 3166-1 alpha code. - final String code; + Country({ + required this.name, + required this.code, + }); - Country({ - required this.name, - required this.code, - }); + factory Country.fromMap(Map map) { + return Country( + name: map['name'].toString(), + code: map['code'].toString(), + ); + } - factory Country.fromMap(Map map) { - return Country( - name: map['name'].toString(), - code: map['code'].toString(), - ); - } - - Map toMap() { - return { - "name": name, - "code": code, - }; - } + Map toMap() { + return { + "name": name, + "code": code, + }; + } } diff --git a/lib/src/models/country_list.dart b/lib/src/models/country_list.dart index a62f926d..996b6aff 100644 --- a/lib/src/models/country_list.dart +++ b/lib/src/models/country_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Countries List class CountryList implements Model { - /// Total number of countries documents that matched your query. - final int total; + /// Total number of countries documents that matched your query. + final int total; + /// List of countries. + final List countries; - /// List of countries. - final List countries; + CountryList({ + required this.total, + required this.countries, + }); - CountryList({ - required this.total, - required this.countries, - }); + factory CountryList.fromMap(Map map) { + return CountryList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + countries: List.from(map['countries'].map((p) => Country.fromMap(p))), + ); + } - factory CountryList.fromMap(Map map) { - return CountryList( - total: map['total'], - countries: - List.from(map['countries'].map((p) => Country.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "countries": countries.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "countries": countries.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/currency.dart b/lib/src/models/currency.dart index 27eef0c1..1d0a3ed5 100644 --- a/lib/src/models/currency.dart +++ b/lib/src/models/currency.dart @@ -2,58 +2,53 @@ part of '../../models.dart'; /// Currency class Currency implements Model { - /// Currency symbol. - final String symbol; - - /// Currency name. - final String name; - - /// Currency native symbol. - final String symbolNative; - - /// Number of decimal digits. - final int decimalDigits; - - /// Currency digit rounding. - final double rounding; - - /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format. - final String code; - - /// Currency plural name - final String namePlural; - - Currency({ - required this.symbol, - required this.name, - required this.symbolNative, - required this.decimalDigits, - required this.rounding, - required this.code, - required this.namePlural, - }); - - factory Currency.fromMap(Map map) { - return Currency( - symbol: map['symbol'].toString(), - name: map['name'].toString(), - symbolNative: map['symbolNative'].toString(), - decimalDigits: map['decimalDigits'], - rounding: map['rounding'].toDouble(), - code: map['code'].toString(), - namePlural: map['namePlural'].toString(), - ); - } - - Map toMap() { - return { - "symbol": symbol, - "name": name, - "symbolNative": symbolNative, - "decimalDigits": decimalDigits, - "rounding": rounding, - "code": code, - "namePlural": namePlural, - }; - } + /// Currency symbol. + final String symbol; + /// Currency name. + final String name; + /// Currency native symbol. + final String symbolNative; + /// Number of decimal digits. + final int decimalDigits; + /// Currency digit rounding. + final double rounding; + /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format. + final String code; + /// Currency plural name + final String namePlural; + + Currency({ + required this.symbol, + required this.name, + required this.symbolNative, + required this.decimalDigits, + required this.rounding, + required this.code, + required this.namePlural, + }); + + factory Currency.fromMap(Map map) { + return Currency( + symbol: map['symbol'].toString(), + name: map['name'].toString(), + symbolNative: map['symbolNative'].toString(), + decimalDigits: (map['decimalDigits'] is String) ? + int.tryParse(map['decimalDigits']) ?? 0:map['decimalDigits'] ?? 0, + rounding: map['rounding'].toDouble(), + code: map['code'].toString(), + namePlural: map['namePlural'].toString(), + ); + } + + Map toMap() { + return { + "symbol": symbol, + "name": name, + "symbolNative": symbolNative, + "decimalDigits": decimalDigits, + "rounding": rounding, + "code": code, + "namePlural": namePlural, + }; + } } diff --git a/lib/src/models/currency_list.dart b/lib/src/models/currency_list.dart index e912ca0a..c1cd94e1 100644 --- a/lib/src/models/currency_list.dart +++ b/lib/src/models/currency_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Currencies List class CurrencyList implements Model { - /// Total number of currencies documents that matched your query. - final int total; + /// Total number of currencies documents that matched your query. + final int total; + /// List of currencies. + final List currencies; - /// List of currencies. - final List currencies; + CurrencyList({ + required this.total, + required this.currencies, + }); - CurrencyList({ - required this.total, - required this.currencies, - }); + factory CurrencyList.fromMap(Map map) { + return CurrencyList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + currencies: List.from(map['currencies'].map((p) => Currency.fromMap(p))), + ); + } - factory CurrencyList.fromMap(Map map) { - return CurrencyList( - total: map['total'], - currencies: List.from( - map['currencies'].map((p) => Currency.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "currencies": currencies.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "currencies": currencies.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/database.dart b/lib/src/models/database.dart index 298a46a3..8eb9253b 100644 --- a/lib/src/models/database.dart +++ b/lib/src/models/database.dart @@ -2,46 +2,42 @@ part of '../../models.dart'; /// Database class Database implements Model { - /// Database ID. - final String $id; - - /// Database name. - final String name; - - /// Database creation date in ISO 8601 format. - final String $createdAt; - - /// Database update date in ISO 8601 format. - final String $updatedAt; - - /// If database is enabled. Can be 'enabled' or 'disabled'. When disabled, the database is inaccessible to users, but remains accessible to Server SDKs using API keys. - final bool enabled; - - Database({ - required this.$id, - required this.name, - required this.$createdAt, - required this.$updatedAt, - required this.enabled, - }); - - factory Database.fromMap(Map map) { - return Database( - $id: map['\$id'].toString(), - name: map['name'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - enabled: map['enabled'], - ); - } - - Map toMap() { - return { - "\$id": $id, - "name": name, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "enabled": enabled, - }; - } + /// Database ID. + final String $id; + /// Database name. + final String name; + /// Database creation date in ISO 8601 format. + final String $createdAt; + /// Database update date in ISO 8601 format. + final String $updatedAt; + /// If database is enabled. Can be 'enabled' or 'disabled'. When disabled, the database is inaccessible to users, but remains accessible to Server SDKs using API keys. + final bool enabled; + + Database({ + required this.$id, + required this.name, + required this.$createdAt, + required this.$updatedAt, + required this.enabled, + }); + + factory Database.fromMap(Map map) { + return Database( + $id: map['\$id'].toString(), + name: map['name'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + enabled: map['enabled'], + ); + } + + Map toMap() { + return { + "\$id": $id, + "name": name, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "enabled": enabled, + }; + } } diff --git a/lib/src/models/database_list.dart b/lib/src/models/database_list.dart index 0ac639f0..861b3c4f 100644 --- a/lib/src/models/database_list.dart +++ b/lib/src/models/database_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Databases List class DatabaseList implements Model { - /// Total number of databases documents that matched your query. - final int total; + /// Total number of databases documents that matched your query. + final int total; + /// List of databases. + final List databases; - /// List of databases. - final List databases; + DatabaseList({ + required this.total, + required this.databases, + }); - DatabaseList({ - required this.total, - required this.databases, - }); + factory DatabaseList.fromMap(Map map) { + return DatabaseList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + databases: List.from(map['databases'].map((p) => Database.fromMap(p))), + ); + } - factory DatabaseList.fromMap(Map map) { - return DatabaseList( - total: map['total'], - databases: - List.from(map['databases'].map((p) => Database.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "databases": databases.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "databases": databases.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/deployment.dart b/lib/src/models/deployment.dart index f01fb11e..1c066b55 100644 --- a/lib/src/models/deployment.dart +++ b/lib/src/models/deployment.dart @@ -2,160 +2,140 @@ part of '../../models.dart'; /// Deployment class Deployment implements Model { - /// Deployment ID. - final String $id; - - /// Deployment creation date in ISO 8601 format. - final String $createdAt; - - /// Deployment update date in ISO 8601 format. - final String $updatedAt; - - /// Type of deployment. - final String type; - - /// Resource ID. - final String resourceId; - - /// Resource type. - final String resourceType; - - /// The entrypoint file to use to execute the deployment code. - final String entrypoint; - - /// The code size in bytes. - final int size; - - /// The build output size in bytes. - final int buildSize; - - /// The current build ID. - final String buildId; - - /// Whether the deployment should be automatically activated. - final bool activate; - - /// The deployment status. Possible values are "processing", "building", "waiting", "ready", and "failed". - final String status; - - /// The build logs. - final String buildLogs; - - /// The current build time in seconds. - final int buildTime; - - /// The name of the vcs provider repository - final String providerRepositoryName; - - /// The name of the vcs provider repository owner - final String providerRepositoryOwner; - - /// The url of the vcs provider repository - final String providerRepositoryUrl; - - /// The branch of the vcs repository - final String providerBranch; - - /// The commit hash of the vcs commit - final String providerCommitHash; - - /// The url of vcs commit author - final String providerCommitAuthorUrl; - - /// The name of vcs commit author - final String providerCommitAuthor; - - /// The commit message - final String providerCommitMessage; - - /// The url of the vcs commit - final String providerCommitUrl; - - /// The branch of the vcs repository - final String providerBranchUrl; - - Deployment({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.type, - required this.resourceId, - required this.resourceType, - required this.entrypoint, - required this.size, - required this.buildSize, - required this.buildId, - required this.activate, - required this.status, - required this.buildLogs, - required this.buildTime, - required this.providerRepositoryName, - required this.providerRepositoryOwner, - required this.providerRepositoryUrl, - required this.providerBranch, - required this.providerCommitHash, - required this.providerCommitAuthorUrl, - required this.providerCommitAuthor, - required this.providerCommitMessage, - required this.providerCommitUrl, - required this.providerBranchUrl, - }); - - factory Deployment.fromMap(Map map) { - return Deployment( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - type: map['type'].toString(), - resourceId: map['resourceId'].toString(), - resourceType: map['resourceType'].toString(), - entrypoint: map['entrypoint'].toString(), - size: map['size'], - buildSize: map['buildSize'], - buildId: map['buildId'].toString(), - activate: map['activate'], - status: map['status'].toString(), - buildLogs: map['buildLogs'].toString(), - buildTime: map['buildTime'], - providerRepositoryName: map['providerRepositoryName'].toString(), - providerRepositoryOwner: map['providerRepositoryOwner'].toString(), - providerRepositoryUrl: map['providerRepositoryUrl'].toString(), - providerBranch: map['providerBranch'].toString(), - providerCommitHash: map['providerCommitHash'].toString(), - providerCommitAuthorUrl: map['providerCommitAuthorUrl'].toString(), - providerCommitAuthor: map['providerCommitAuthor'].toString(), - providerCommitMessage: map['providerCommitMessage'].toString(), - providerCommitUrl: map['providerCommitUrl'].toString(), - providerBranchUrl: map['providerBranchUrl'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "type": type, - "resourceId": resourceId, - "resourceType": resourceType, - "entrypoint": entrypoint, - "size": size, - "buildSize": buildSize, - "buildId": buildId, - "activate": activate, - "status": status, - "buildLogs": buildLogs, - "buildTime": buildTime, - "providerRepositoryName": providerRepositoryName, - "providerRepositoryOwner": providerRepositoryOwner, - "providerRepositoryUrl": providerRepositoryUrl, - "providerBranch": providerBranch, - "providerCommitHash": providerCommitHash, - "providerCommitAuthorUrl": providerCommitAuthorUrl, - "providerCommitAuthor": providerCommitAuthor, - "providerCommitMessage": providerCommitMessage, - "providerCommitUrl": providerCommitUrl, - "providerBranchUrl": providerBranchUrl, - }; - } + /// Deployment ID. + final String $id; + /// Deployment creation date in ISO 8601 format. + final String $createdAt; + /// Deployment update date in ISO 8601 format. + final String $updatedAt; + /// Type of deployment. + final String type; + /// Resource ID. + final String resourceId; + /// Resource type. + final String resourceType; + /// The entrypoint file to use to execute the deployment code. + final String entrypoint; + /// The code size in bytes. + final int size; + /// The build output size in bytes. + final int buildSize; + /// The current build ID. + final String buildId; + /// Whether the deployment should be automatically activated. + final bool activate; + /// The deployment status. Possible values are "processing", "building", "waiting", "ready", and "failed". + final String status; + /// The build logs. + final String buildLogs; + /// The current build time in seconds. + final int buildTime; + /// The name of the vcs provider repository + final String providerRepositoryName; + /// The name of the vcs provider repository owner + final String providerRepositoryOwner; + /// The url of the vcs provider repository + final String providerRepositoryUrl; + /// The branch of the vcs repository + final String providerBranch; + /// The commit hash of the vcs commit + final String providerCommitHash; + /// The url of vcs commit author + final String providerCommitAuthorUrl; + /// The name of vcs commit author + final String providerCommitAuthor; + /// The commit message + final String providerCommitMessage; + /// The url of the vcs commit + final String providerCommitUrl; + /// The branch of the vcs repository + final String providerBranchUrl; + + Deployment({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.type, + required this.resourceId, + required this.resourceType, + required this.entrypoint, + required this.size, + required this.buildSize, + required this.buildId, + required this.activate, + required this.status, + required this.buildLogs, + required this.buildTime, + required this.providerRepositoryName, + required this.providerRepositoryOwner, + required this.providerRepositoryUrl, + required this.providerBranch, + required this.providerCommitHash, + required this.providerCommitAuthorUrl, + required this.providerCommitAuthor, + required this.providerCommitMessage, + required this.providerCommitUrl, + required this.providerBranchUrl, + }); + + factory Deployment.fromMap(Map map) { + return Deployment( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + type: map['type'].toString(), + resourceId: map['resourceId'].toString(), + resourceType: map['resourceType'].toString(), + entrypoint: map['entrypoint'].toString(), + size: (map['size'] is String) ? + int.tryParse(map['size']) ?? 0:map['size'] ?? 0, + buildSize: (map['buildSize'] is String) ? + int.tryParse(map['buildSize']) ?? 0:map['buildSize'] ?? 0, + buildId: map['buildId'].toString(), + activate: map['activate'], + status: map['status'].toString(), + buildLogs: map['buildLogs'].toString(), + buildTime: (map['buildTime'] is String) ? + int.tryParse(map['buildTime']) ?? 0:map['buildTime'] ?? 0, + providerRepositoryName: map['providerRepositoryName'].toString(), + providerRepositoryOwner: map['providerRepositoryOwner'].toString(), + providerRepositoryUrl: map['providerRepositoryUrl'].toString(), + providerBranch: map['providerBranch'].toString(), + providerCommitHash: map['providerCommitHash'].toString(), + providerCommitAuthorUrl: map['providerCommitAuthorUrl'].toString(), + providerCommitAuthor: map['providerCommitAuthor'].toString(), + providerCommitMessage: map['providerCommitMessage'].toString(), + providerCommitUrl: map['providerCommitUrl'].toString(), + providerBranchUrl: map['providerBranchUrl'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "type": type, + "resourceId": resourceId, + "resourceType": resourceType, + "entrypoint": entrypoint, + "size": size, + "buildSize": buildSize, + "buildId": buildId, + "activate": activate, + "status": status, + "buildLogs": buildLogs, + "buildTime": buildTime, + "providerRepositoryName": providerRepositoryName, + "providerRepositoryOwner": providerRepositoryOwner, + "providerRepositoryUrl": providerRepositoryUrl, + "providerBranch": providerBranch, + "providerCommitHash": providerCommitHash, + "providerCommitAuthorUrl": providerCommitAuthorUrl, + "providerCommitAuthor": providerCommitAuthor, + "providerCommitMessage": providerCommitMessage, + "providerCommitUrl": providerCommitUrl, + "providerBranchUrl": providerBranchUrl, + }; + } } diff --git a/lib/src/models/deployment_list.dart b/lib/src/models/deployment_list.dart index 03e03c98..ddc014f9 100644 --- a/lib/src/models/deployment_list.dart +++ b/lib/src/models/deployment_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Deployments List class DeploymentList implements Model { - /// Total number of deployments documents that matched your query. - final int total; + /// Total number of deployments documents that matched your query. + final int total; + /// List of deployments. + final List deployments; - /// List of deployments. - final List deployments; + DeploymentList({ + required this.total, + required this.deployments, + }); - DeploymentList({ - required this.total, - required this.deployments, - }); + factory DeploymentList.fromMap(Map map) { + return DeploymentList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + deployments: List.from(map['deployments'].map((p) => Deployment.fromMap(p))), + ); + } - factory DeploymentList.fromMap(Map map) { - return DeploymentList( - total: map['total'], - deployments: List.from( - map['deployments'].map((p) => Deployment.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "deployments": deployments.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "deployments": deployments.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/document.dart b/lib/src/models/document.dart index 6406f06a..d5b8c77e 100644 --- a/lib/src/models/document.dart +++ b/lib/src/models/document.dart @@ -2,58 +2,53 @@ part of '../../models.dart'; /// Document class Document implements Model { - /// Document ID. - final String $id; - - /// Collection ID. - final String $collectionId; - - /// Database ID. - final String $databaseId; - - /// Document creation date in ISO 8601 format. - final String $createdAt; - - /// Document update date in ISO 8601 format. - final String $updatedAt; - - /// Document permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List $permissions; - final Map data; - - Document({ - required this.$id, - required this.$collectionId, - required this.$databaseId, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.data, - }); - - factory Document.fromMap(Map map) { - return Document( - $id: map['\$id'].toString(), - $collectionId: map['\$collectionId'].toString(), - $databaseId: map['\$databaseId'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - data: map, - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$collectionId": $collectionId, - "\$databaseId": $databaseId, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "data": data, - }; - } - - T convertTo(T Function(Map) fromJson) => fromJson(data); + /// Document ID. + final String $id; + /// Collection ID. + final String $collectionId; + /// Database ID. + final String $databaseId; + /// Document creation date in ISO 8601 format. + final String $createdAt; + /// Document update date in ISO 8601 format. + final String $updatedAt; + /// Document permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List $permissions; + final Map data; + + Document({ + required this.$id, + required this.$collectionId, + required this.$databaseId, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.data, + }); + + factory Document.fromMap(Map map) { + return Document( + $id: map['\$id'].toString(), + $collectionId: map['\$collectionId'].toString(), + $databaseId: map['\$databaseId'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + data: map, + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$collectionId": $collectionId, + "\$databaseId": $databaseId, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "data": data, + }; + } + + T convertTo(T Function(Map) fromJson) => fromJson(data); } diff --git a/lib/src/models/document_list.dart b/lib/src/models/document_list.dart index b4fd20eb..c418b48e 100644 --- a/lib/src/models/document_list.dart +++ b/lib/src/models/document_list.dart @@ -2,32 +2,31 @@ part of '../../models.dart'; /// Documents List class DocumentList implements Model { - /// Total number of documents documents that matched your query. - final int total; + /// Total number of documents documents that matched your query. + final int total; + /// List of documents. + final List documents; - /// List of documents. - final List documents; + DocumentList({ + required this.total, + required this.documents, + }); - DocumentList({ - required this.total, - required this.documents, - }); + factory DocumentList.fromMap(Map map) { + return DocumentList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + documents: List.from(map['documents'].map((p) => Document.fromMap(p))), + ); + } - factory DocumentList.fromMap(Map map) { - return DocumentList( - total: map['total'], - documents: - List.from(map['documents'].map((p) => Document.fromMap(p))), - ); - } + Map toMap() { + return { + "total": total, + "documents": documents.map((p) => p.toMap()).toList(), + }; + } - Map toMap() { - return { - "total": total, - "documents": documents.map((p) => p.toMap()).toList(), - }; - } - - List convertTo(T Function(Map) fromJson) => - documents.map((d) => d.convertTo(fromJson)).toList(); + List convertTo(T Function(Map) fromJson) => + documents.map((d) => d.convertTo(fromJson)).toList(); } diff --git a/lib/src/models/execution.dart b/lib/src/models/execution.dart index 40886cd7..aff3e0b3 100644 --- a/lib/src/models/execution.dart +++ b/lib/src/models/execution.dart @@ -2,120 +2,103 @@ part of '../../models.dart'; /// Execution class Execution implements Model { - /// Execution ID. - final String $id; - - /// Execution creation date in ISO 8601 format. - final String $createdAt; - - /// Execution upate date in ISO 8601 format. - final String $updatedAt; - - /// Execution roles. - final List $permissions; - - /// Function ID. - final String functionId; - - /// The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`. - final String trigger; - - /// The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`. - final String status; - - /// HTTP request method type. - final String requestMethod; - - /// HTTP request path and query. - final String requestPath; - - /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. - final List requestHeaders; - - /// HTTP response status code. - final int responseStatusCode; - - /// HTTP response body. This will return empty unless execution is created as synchronous. - final String responseBody; - - /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. - final List responseHeaders; - - /// Function logs. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. - final String logs; - - /// Function errors. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. - final String errors; - - /// Function execution duration in seconds. - final double duration; - - /// The scheduled time for execution. If left empty, execution will be queued immediately. - final String? scheduledAt; - - Execution({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.functionId, - required this.trigger, - required this.status, - required this.requestMethod, - required this.requestPath, - required this.requestHeaders, - required this.responseStatusCode, - required this.responseBody, - required this.responseHeaders, - required this.logs, - required this.errors, - required this.duration, - this.scheduledAt, - }); - - factory Execution.fromMap(Map map) { - return Execution( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - functionId: map['functionId'].toString(), - trigger: map['trigger'].toString(), - status: map['status'].toString(), - requestMethod: map['requestMethod'].toString(), - requestPath: map['requestPath'].toString(), - requestHeaders: List.from( - map['requestHeaders'].map((p) => Headers.fromMap(p))), - responseStatusCode: map['responseStatusCode'], - responseBody: map['responseBody'].toString(), - responseHeaders: List.from( - map['responseHeaders'].map((p) => Headers.fromMap(p))), - logs: map['logs'].toString(), - errors: map['errors'].toString(), - duration: map['duration'].toDouble(), - scheduledAt: map['scheduledAt']?.toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "functionId": functionId, - "trigger": trigger, - "status": status, - "requestMethod": requestMethod, - "requestPath": requestPath, - "requestHeaders": requestHeaders.map((p) => p.toMap()).toList(), - "responseStatusCode": responseStatusCode, - "responseBody": responseBody, - "responseHeaders": responseHeaders.map((p) => p.toMap()).toList(), - "logs": logs, - "errors": errors, - "duration": duration, - "scheduledAt": scheduledAt, - }; - } + /// Execution ID. + final String $id; + /// Execution creation date in ISO 8601 format. + final String $createdAt; + /// Execution upate date in ISO 8601 format. + final String $updatedAt; + /// Execution roles. + final List $permissions; + /// Function ID. + final String functionId; + /// The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`. + final String trigger; + /// The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`. + final String status; + /// HTTP request method type. + final String requestMethod; + /// HTTP request path and query. + final String requestPath; + /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. + final List requestHeaders; + /// HTTP response status code. + final int responseStatusCode; + /// HTTP response body. This will return empty unless execution is created as synchronous. + final String responseBody; + /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. + final List responseHeaders; + /// Function logs. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. + final String logs; + /// Function errors. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. + final String errors; + /// Function execution duration in seconds. + final double duration; + /// The scheduled time for execution. If left empty, execution will be queued immediately. + final String? scheduledAt; + + Execution({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.functionId, + required this.trigger, + required this.status, + required this.requestMethod, + required this.requestPath, + required this.requestHeaders, + required this.responseStatusCode, + required this.responseBody, + required this.responseHeaders, + required this.logs, + required this.errors, + required this.duration, + this.scheduledAt, + }); + + factory Execution.fromMap(Map map) { + return Execution( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + functionId: map['functionId'].toString(), + trigger: map['trigger'].toString(), + status: map['status'].toString(), + requestMethod: map['requestMethod'].toString(), + requestPath: map['requestPath'].toString(), + requestHeaders: List.from(map['requestHeaders'].map((p) => Headers.fromMap(p))), + responseStatusCode: (map['responseStatusCode'] is String) ? + int.tryParse(map['responseStatusCode']) ?? 0:map['responseStatusCode'] ?? 0, + responseBody: map['responseBody'].toString(), + responseHeaders: List.from(map['responseHeaders'].map((p) => Headers.fromMap(p))), + logs: map['logs'].toString(), + errors: map['errors'].toString(), + duration: map['duration'].toDouble(), + scheduledAt: map['scheduledAt']?.toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "functionId": functionId, + "trigger": trigger, + "status": status, + "requestMethod": requestMethod, + "requestPath": requestPath, + "requestHeaders": requestHeaders.map((p) => p.toMap()).toList(), + "responseStatusCode": responseStatusCode, + "responseBody": responseBody, + "responseHeaders": responseHeaders.map((p) => p.toMap()).toList(), + "logs": logs, + "errors": errors, + "duration": duration, + "scheduledAt": scheduledAt, + }; + } } diff --git a/lib/src/models/execution_list.dart b/lib/src/models/execution_list.dart index 32e40531..ba66f150 100644 --- a/lib/src/models/execution_list.dart +++ b/lib/src/models/execution_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Executions List class ExecutionList implements Model { - /// Total number of executions documents that matched your query. - final int total; + /// Total number of executions documents that matched your query. + final int total; + /// List of executions. + final List executions; - /// List of executions. - final List executions; + ExecutionList({ + required this.total, + required this.executions, + }); - ExecutionList({ - required this.total, - required this.executions, - }); + factory ExecutionList.fromMap(Map map) { + return ExecutionList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + executions: List.from(map['executions'].map((p) => Execution.fromMap(p))), + ); + } - factory ExecutionList.fromMap(Map map) { - return ExecutionList( - total: map['total'], - executions: List.from( - map['executions'].map((p) => Execution.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "executions": executions.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "executions": executions.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/file.dart b/lib/src/models/file.dart index 2e6b9d8f..34b9e6cf 100644 --- a/lib/src/models/file.dart +++ b/lib/src/models/file.dart @@ -2,82 +2,75 @@ part of '../../models.dart'; /// File class File implements Model { - /// File ID. - final String $id; + /// File ID. + final String $id; + /// Bucket ID. + final String bucketId; + /// File creation date in ISO 8601 format. + final String $createdAt; + /// File update date in ISO 8601 format. + final String $updatedAt; + /// File permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List $permissions; + /// File name. + final String name; + /// File MD5 signature. + final String signature; + /// File mime type. + final String mimeType; + /// File original size in bytes. + final int sizeOriginal; + /// Total number of chunks available + final int chunksTotal; + /// Total number of chunks uploaded + final int chunksUploaded; - /// Bucket ID. - final String bucketId; + File({ + required this.$id, + required this.bucketId, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.name, + required this.signature, + required this.mimeType, + required this.sizeOriginal, + required this.chunksTotal, + required this.chunksUploaded, + }); - /// File creation date in ISO 8601 format. - final String $createdAt; + factory File.fromMap(Map map) { + return File( + $id: map['\$id'].toString(), + bucketId: map['bucketId'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + name: map['name'].toString(), + signature: map['signature'].toString(), + mimeType: map['mimeType'].toString(), + sizeOriginal: (map['sizeOriginal'] is String) ? + int.tryParse(map['sizeOriginal']) ?? 0:map['sizeOriginal'] ?? 0, + chunksTotal: (map['chunksTotal'] is String) ? + int.tryParse(map['chunksTotal']) ?? 0:map['chunksTotal'] ?? 0, + chunksUploaded: (map['chunksUploaded'] is String) ? + int.tryParse(map['chunksUploaded']) ?? 0:map['chunksUploaded'] ?? 0, + ); + } - /// File update date in ISO 8601 format. - final String $updatedAt; - - /// File permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List $permissions; - - /// File name. - final String name; - - /// File MD5 signature. - final String signature; - - /// File mime type. - final String mimeType; - - /// File original size in bytes. - final int sizeOriginal; - - /// Total number of chunks available - final int chunksTotal; - - /// Total number of chunks uploaded - final int chunksUploaded; - - File({ - required this.$id, - required this.bucketId, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.name, - required this.signature, - required this.mimeType, - required this.sizeOriginal, - required this.chunksTotal, - required this.chunksUploaded, - }); - - factory File.fromMap(Map map) { - return File( - $id: map['\$id'].toString(), - bucketId: map['bucketId'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - name: map['name'].toString(), - signature: map['signature'].toString(), - mimeType: map['mimeType'].toString(), - sizeOriginal: map['sizeOriginal'], - chunksTotal: map['chunksTotal'], - chunksUploaded: map['chunksUploaded'], - ); - } - - Map toMap() { - return { - "\$id": $id, - "bucketId": bucketId, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "name": name, - "signature": signature, - "mimeType": mimeType, - "sizeOriginal": sizeOriginal, - "chunksTotal": chunksTotal, - "chunksUploaded": chunksUploaded, - }; - } + Map toMap() { + return { + "\$id": $id, + "bucketId": bucketId, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "name": name, + "signature": signature, + "mimeType": mimeType, + "sizeOriginal": sizeOriginal, + "chunksTotal": chunksTotal, + "chunksUploaded": chunksUploaded, + }; + } } diff --git a/lib/src/models/file_list.dart b/lib/src/models/file_list.dart index 3b695c93..cf7a0ced 100644 --- a/lib/src/models/file_list.dart +++ b/lib/src/models/file_list.dart @@ -2,28 +2,28 @@ part of '../../models.dart'; /// Files List class FileList implements Model { - /// Total number of files documents that matched your query. - final int total; + /// Total number of files documents that matched your query. + final int total; + /// List of files. + final List files; - /// List of files. - final List files; + FileList({ + required this.total, + required this.files, + }); - FileList({ - required this.total, - required this.files, - }); + factory FileList.fromMap(Map map) { + return FileList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + files: List.from(map['files'].map((p) => File.fromMap(p))), + ); + } - factory FileList.fromMap(Map map) { - return FileList( - total: map['total'], - files: List.from(map['files'].map((p) => File.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "files": files.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "files": files.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/function.dart b/lib/src/models/function.dart index ff856ccd..870bd5df 100644 --- a/lib/src/models/function.dart +++ b/lib/src/models/function.dart @@ -2,160 +2,138 @@ part of '../../models.dart'; /// Function class Func implements Model { - /// Function ID. - final String $id; - - /// Function creation date in ISO 8601 format. - final String $createdAt; - - /// Function update date in ISO 8601 format. - final String $updatedAt; - - /// Execution permissions. - final List execute; - - /// Function name. - final String name; - - /// Function enabled. - final bool enabled; - - /// Is the function deployed with the latest configuration? This is set to false if you've changed an environment variables, entrypoint, commands, or other settings that needs redeploy to be applied. When the value is false, redeploy the function to update it with the latest configuration. - final bool live; - - /// Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project. - final bool logging; - - /// Function execution runtime. - final String runtime; - - /// Function's active deployment ID. - final String deployment; - - /// Allowed permission scopes. - final List scopes; - - /// Function variables. - final List vars; - - /// Function trigger events. - final List events; - - /// Function execution schedult in CRON format. - final String schedule; - - /// Function execution timeout in seconds. - final int timeout; - - /// The entrypoint file used to execute the deployment. - final String entrypoint; - - /// The build command used to build the deployment. - final String commands; - - /// Version of Open Runtimes used for the function. - final String version; - - /// Function VCS (Version Control System) installation id. - final String installationId; - - /// VCS (Version Control System) Repository ID - final String providerRepositoryId; - - /// VCS (Version Control System) branch name - final String providerBranch; - - /// Path to function in VCS (Version Control System) repository - final String providerRootDirectory; - - /// Is VCS (Version Control System) connection is in silent mode? When in silence mode, no comments will be posted on the repository pull or merge requests - final bool providerSilentMode; - - /// Machine specification for builds and executions. - final String specification; - - Func({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.execute, - required this.name, - required this.enabled, - required this.live, - required this.logging, - required this.runtime, - required this.deployment, - required this.scopes, - required this.vars, - required this.events, - required this.schedule, - required this.timeout, - required this.entrypoint, - required this.commands, - required this.version, - required this.installationId, - required this.providerRepositoryId, - required this.providerBranch, - required this.providerRootDirectory, - required this.providerSilentMode, - required this.specification, - }); - - factory Func.fromMap(Map map) { - return Func( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - execute: map['execute'] ?? [], - name: map['name'].toString(), - enabled: map['enabled'], - live: map['live'], - logging: map['logging'], - runtime: map['runtime'].toString(), - deployment: map['deployment'].toString(), - scopes: map['scopes'] ?? [], - vars: List.from(map['vars'].map((p) => Variable.fromMap(p))), - events: map['events'] ?? [], - schedule: map['schedule'].toString(), - timeout: map['timeout'], - entrypoint: map['entrypoint'].toString(), - commands: map['commands'].toString(), - version: map['version'].toString(), - installationId: map['installationId'].toString(), - providerRepositoryId: map['providerRepositoryId'].toString(), - providerBranch: map['providerBranch'].toString(), - providerRootDirectory: map['providerRootDirectory'].toString(), - providerSilentMode: map['providerSilentMode'], - specification: map['specification'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "execute": execute, - "name": name, - "enabled": enabled, - "live": live, - "logging": logging, - "runtime": runtime, - "deployment": deployment, - "scopes": scopes, - "vars": vars.map((p) => p.toMap()).toList(), - "events": events, - "schedule": schedule, - "timeout": timeout, - "entrypoint": entrypoint, - "commands": commands, - "version": version, - "installationId": installationId, - "providerRepositoryId": providerRepositoryId, - "providerBranch": providerBranch, - "providerRootDirectory": providerRootDirectory, - "providerSilentMode": providerSilentMode, - "specification": specification, - }; - } + /// Function ID. + final String $id; + /// Function creation date in ISO 8601 format. + final String $createdAt; + /// Function update date in ISO 8601 format. + final String $updatedAt; + /// Execution permissions. + final List execute; + /// Function name. + final String name; + /// Function enabled. + final bool enabled; + /// Is the function deployed with the latest configuration? This is set to false if you've changed an environment variables, entrypoint, commands, or other settings that needs redeploy to be applied. When the value is false, redeploy the function to update it with the latest configuration. + final bool live; + /// Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project. + final bool logging; + /// Function execution runtime. + final String runtime; + /// Function's active deployment ID. + final String deployment; + /// Allowed permission scopes. + final List scopes; + /// Function variables. + final List vars; + /// Function trigger events. + final List events; + /// Function execution schedult in CRON format. + final String schedule; + /// Function execution timeout in seconds. + final int timeout; + /// The entrypoint file used to execute the deployment. + final String entrypoint; + /// The build command used to build the deployment. + final String commands; + /// Version of Open Runtimes used for the function. + final String version; + /// Function VCS (Version Control System) installation id. + final String installationId; + /// VCS (Version Control System) Repository ID + final String providerRepositoryId; + /// VCS (Version Control System) branch name + final String providerBranch; + /// Path to function in VCS (Version Control System) repository + final String providerRootDirectory; + /// Is VCS (Version Control System) connection is in silent mode? When in silence mode, no comments will be posted on the repository pull or merge requests + final bool providerSilentMode; + /// Machine specification for builds and executions. + final String specification; + + Func({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.execute, + required this.name, + required this.enabled, + required this.live, + required this.logging, + required this.runtime, + required this.deployment, + required this.scopes, + required this.vars, + required this.events, + required this.schedule, + required this.timeout, + required this.entrypoint, + required this.commands, + required this.version, + required this.installationId, + required this.providerRepositoryId, + required this.providerBranch, + required this.providerRootDirectory, + required this.providerSilentMode, + required this.specification, + }); + + factory Func.fromMap(Map map) { + return Func( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + execute: map['execute'] ?? [], + name: map['name'].toString(), + enabled: map['enabled'], + live: map['live'], + logging: map['logging'], + runtime: map['runtime'].toString(), + deployment: map['deployment'].toString(), + scopes: map['scopes'] ?? [], + vars: List.from(map['vars'].map((p) => Variable.fromMap(p))), + events: map['events'] ?? [], + schedule: map['schedule'].toString(), + timeout: (map['timeout'] is String) ? + int.tryParse(map['timeout']) ?? 0:map['timeout'] ?? 0, + entrypoint: map['entrypoint'].toString(), + commands: map['commands'].toString(), + version: map['version'].toString(), + installationId: map['installationId'].toString(), + providerRepositoryId: map['providerRepositoryId'].toString(), + providerBranch: map['providerBranch'].toString(), + providerRootDirectory: map['providerRootDirectory'].toString(), + providerSilentMode: map['providerSilentMode'], + specification: map['specification'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "execute": execute, + "name": name, + "enabled": enabled, + "live": live, + "logging": logging, + "runtime": runtime, + "deployment": deployment, + "scopes": scopes, + "vars": vars.map((p) => p.toMap()).toList(), + "events": events, + "schedule": schedule, + "timeout": timeout, + "entrypoint": entrypoint, + "commands": commands, + "version": version, + "installationId": installationId, + "providerRepositoryId": providerRepositoryId, + "providerBranch": providerBranch, + "providerRootDirectory": providerRootDirectory, + "providerSilentMode": providerSilentMode, + "specification": specification, + }; + } } diff --git a/lib/src/models/function_list.dart b/lib/src/models/function_list.dart index 5c53b276..712e459e 100644 --- a/lib/src/models/function_list.dart +++ b/lib/src/models/function_list.dart @@ -2,28 +2,28 @@ part of '../../models.dart'; /// Functions List class FunctionList implements Model { - /// Total number of functions documents that matched your query. - final int total; + /// Total number of functions documents that matched your query. + final int total; + /// List of functions. + final List functions; - /// List of functions. - final List functions; + FunctionList({ + required this.total, + required this.functions, + }); - FunctionList({ - required this.total, - required this.functions, - }); + factory FunctionList.fromMap(Map map) { + return FunctionList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + functions: List.from(map['functions'].map((p) => Func.fromMap(p))), + ); + } - factory FunctionList.fromMap(Map map) { - return FunctionList( - total: map['total'], - functions: List.from(map['functions'].map((p) => Func.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "functions": functions.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "functions": functions.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/headers.dart b/lib/src/models/headers.dart index 22494998..f03c5ce4 100644 --- a/lib/src/models/headers.dart +++ b/lib/src/models/headers.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Headers class Headers implements Model { - /// Header name. - final String name; + /// Header name. + final String name; + /// Header value. + final String value; - /// Header value. - final String value; + Headers({ + required this.name, + required this.value, + }); - Headers({ - required this.name, - required this.value, - }); + factory Headers.fromMap(Map map) { + return Headers( + name: map['name'].toString(), + value: map['value'].toString(), + ); + } - factory Headers.fromMap(Map map) { - return Headers( - name: map['name'].toString(), - value: map['value'].toString(), - ); - } - - Map toMap() { - return { - "name": name, - "value": value, - }; - } + Map toMap() { + return { + "name": name, + "value": value, + }; + } } diff --git a/lib/src/models/health_antivirus.dart b/lib/src/models/health_antivirus.dart index aabc7d85..48b8ad32 100644 --- a/lib/src/models/health_antivirus.dart +++ b/lib/src/models/health_antivirus.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Health Antivirus class HealthAntivirus implements Model { - /// Antivirus version. - final String version; + /// Antivirus version. + final String version; + /// Antivirus status. Possible values can are: `disabled`, `offline`, `online` + final String status; - /// Antivirus status. Possible values can are: `disabled`, `offline`, `online` - final String status; + HealthAntivirus({ + required this.version, + required this.status, + }); - HealthAntivirus({ - required this.version, - required this.status, - }); + factory HealthAntivirus.fromMap(Map map) { + return HealthAntivirus( + version: map['version'].toString(), + status: map['status'].toString(), + ); + } - factory HealthAntivirus.fromMap(Map map) { - return HealthAntivirus( - version: map['version'].toString(), - status: map['status'].toString(), - ); - } - - Map toMap() { - return { - "version": version, - "status": status, - }; - } + Map toMap() { + return { + "version": version, + "status": status, + }; + } } diff --git a/lib/src/models/health_certificate.dart b/lib/src/models/health_certificate.dart index d412eba9..3409d8e7 100644 --- a/lib/src/models/health_certificate.dart +++ b/lib/src/models/health_certificate.dart @@ -2,52 +2,47 @@ part of '../../models.dart'; /// Health Certificate class HealthCertificate implements Model { - /// Certificate name - final String name; - - /// Subject SN - final String subjectSN; - - /// Issuer organisation - final String issuerOrganisation; - - /// Valid from - final String validFrom; - - /// Valid to - final String validTo; - - /// Signature type SN - final String signatureTypeSN; - - HealthCertificate({ - required this.name, - required this.subjectSN, - required this.issuerOrganisation, - required this.validFrom, - required this.validTo, - required this.signatureTypeSN, - }); - - factory HealthCertificate.fromMap(Map map) { - return HealthCertificate( - name: map['name'].toString(), - subjectSN: map['subjectSN'].toString(), - issuerOrganisation: map['issuerOrganisation'].toString(), - validFrom: map['validFrom'].toString(), - validTo: map['validTo'].toString(), - signatureTypeSN: map['signatureTypeSN'].toString(), - ); - } - - Map toMap() { - return { - "name": name, - "subjectSN": subjectSN, - "issuerOrganisation": issuerOrganisation, - "validFrom": validFrom, - "validTo": validTo, - "signatureTypeSN": signatureTypeSN, - }; - } + /// Certificate name + final String name; + /// Subject SN + final String subjectSN; + /// Issuer organisation + final String issuerOrganisation; + /// Valid from + final String validFrom; + /// Valid to + final String validTo; + /// Signature type SN + final String signatureTypeSN; + + HealthCertificate({ + required this.name, + required this.subjectSN, + required this.issuerOrganisation, + required this.validFrom, + required this.validTo, + required this.signatureTypeSN, + }); + + factory HealthCertificate.fromMap(Map map) { + return HealthCertificate( + name: map['name'].toString(), + subjectSN: map['subjectSN'].toString(), + issuerOrganisation: map['issuerOrganisation'].toString(), + validFrom: map['validFrom'].toString(), + validTo: map['validTo'].toString(), + signatureTypeSN: map['signatureTypeSN'].toString(), + ); + } + + Map toMap() { + return { + "name": name, + "subjectSN": subjectSN, + "issuerOrganisation": issuerOrganisation, + "validFrom": validFrom, + "validTo": validTo, + "signatureTypeSN": signatureTypeSN, + }; + } } diff --git a/lib/src/models/health_queue.dart b/lib/src/models/health_queue.dart index 8b3aa1b6..8267e5bc 100644 --- a/lib/src/models/health_queue.dart +++ b/lib/src/models/health_queue.dart @@ -2,22 +2,23 @@ part of '../../models.dart'; /// Health Queue class HealthQueue implements Model { - /// Amount of actions in the queue. - final int size; + /// Amount of actions in the queue. + final int size; - HealthQueue({ - required this.size, - }); + HealthQueue({ + required this.size, + }); - factory HealthQueue.fromMap(Map map) { - return HealthQueue( - size: map['size'], - ); - } + factory HealthQueue.fromMap(Map map) { + return HealthQueue( + size: (map['size'] is String) ? + int.tryParse(map['size']) ?? 0:map['size'] ?? 0, + ); + } - Map toMap() { - return { - "size": size, - }; - } + Map toMap() { + return { + "size": size, + }; + } } diff --git a/lib/src/models/health_status.dart b/lib/src/models/health_status.dart index b22b2c8a..dbbcfef8 100644 --- a/lib/src/models/health_status.dart +++ b/lib/src/models/health_status.dart @@ -2,34 +2,33 @@ part of '../../models.dart'; /// Health Status class HealthStatus implements Model { - /// Name of the service. - final String name; + /// Name of the service. + final String name; + /// Duration in milliseconds how long the health check took. + final int ping; + /// Service status. Possible values can are: `pass`, `fail` + final String status; - /// Duration in milliseconds how long the health check took. - final int ping; + HealthStatus({ + required this.name, + required this.ping, + required this.status, + }); - /// Service status. Possible values can are: `pass`, `fail` - final String status; + factory HealthStatus.fromMap(Map map) { + return HealthStatus( + name: map['name'].toString(), + ping: (map['ping'] is String) ? + int.tryParse(map['ping']) ?? 0:map['ping'] ?? 0, + status: map['status'].toString(), + ); + } - HealthStatus({ - required this.name, - required this.ping, - required this.status, - }); - - factory HealthStatus.fromMap(Map map) { - return HealthStatus( - name: map['name'].toString(), - ping: map['ping'], - status: map['status'].toString(), - ); - } - - Map toMap() { - return { - "name": name, - "ping": ping, - "status": status, - }; - } + Map toMap() { + return { + "name": name, + "ping": ping, + "status": status, + }; + } } diff --git a/lib/src/models/health_time.dart b/lib/src/models/health_time.dart index 0ed15f0a..49b00a9d 100644 --- a/lib/src/models/health_time.dart +++ b/lib/src/models/health_time.dart @@ -2,34 +2,35 @@ part of '../../models.dart'; /// Health Time class HealthTime implements Model { - /// Current unix timestamp on trustful remote server. - final int remoteTime; + /// Current unix timestamp on trustful remote server. + final int remoteTime; + /// Current unix timestamp of local server where Appwrite runs. + final int localTime; + /// Difference of unix remote and local timestamps in milliseconds. + final int diff; - /// Current unix timestamp of local server where Appwrite runs. - final int localTime; + HealthTime({ + required this.remoteTime, + required this.localTime, + required this.diff, + }); - /// Difference of unix remote and local timestamps in milliseconds. - final int diff; + factory HealthTime.fromMap(Map map) { + return HealthTime( + remoteTime: (map['remoteTime'] is String) ? + int.tryParse(map['remoteTime']) ?? 0:map['remoteTime'] ?? 0, + localTime: (map['localTime'] is String) ? + int.tryParse(map['localTime']) ?? 0:map['localTime'] ?? 0, + diff: (map['diff'] is String) ? + int.tryParse(map['diff']) ?? 0:map['diff'] ?? 0, + ); + } - HealthTime({ - required this.remoteTime, - required this.localTime, - required this.diff, - }); - - factory HealthTime.fromMap(Map map) { - return HealthTime( - remoteTime: map['remoteTime'], - localTime: map['localTime'], - diff: map['diff'], - ); - } - - Map toMap() { - return { - "remoteTime": remoteTime, - "localTime": localTime, - "diff": diff, - }; - } + Map toMap() { + return { + "remoteTime": remoteTime, + "localTime": localTime, + "diff": diff, + }; + } } diff --git a/lib/src/models/identity.dart b/lib/src/models/identity.dart index 807bdfd0..632dc3db 100644 --- a/lib/src/models/identity.dart +++ b/lib/src/models/identity.dart @@ -2,76 +2,67 @@ part of '../../models.dart'; /// Identity class Identity implements Model { - /// Identity ID. - final String $id; + /// Identity ID. + final String $id; + /// Identity creation date in ISO 8601 format. + final String $createdAt; + /// Identity update date in ISO 8601 format. + final String $updatedAt; + /// User ID. + final String userId; + /// Identity Provider. + final String provider; + /// ID of the User in the Identity Provider. + final String providerUid; + /// Email of the User in the Identity Provider. + final String providerEmail; + /// Identity Provider Access Token. + final String providerAccessToken; + /// The date of when the access token expires in ISO 8601 format. + final String providerAccessTokenExpiry; + /// Identity Provider Refresh Token. + final String providerRefreshToken; - /// Identity creation date in ISO 8601 format. - final String $createdAt; + Identity({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.userId, + required this.provider, + required this.providerUid, + required this.providerEmail, + required this.providerAccessToken, + required this.providerAccessTokenExpiry, + required this.providerRefreshToken, + }); - /// Identity update date in ISO 8601 format. - final String $updatedAt; + factory Identity.fromMap(Map map) { + return Identity( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + userId: map['userId'].toString(), + provider: map['provider'].toString(), + providerUid: map['providerUid'].toString(), + providerEmail: map['providerEmail'].toString(), + providerAccessToken: map['providerAccessToken'].toString(), + providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), + providerRefreshToken: map['providerRefreshToken'].toString(), + ); + } - /// User ID. - final String userId; - - /// Identity Provider. - final String provider; - - /// ID of the User in the Identity Provider. - final String providerUid; - - /// Email of the User in the Identity Provider. - final String providerEmail; - - /// Identity Provider Access Token. - final String providerAccessToken; - - /// The date of when the access token expires in ISO 8601 format. - final String providerAccessTokenExpiry; - - /// Identity Provider Refresh Token. - final String providerRefreshToken; - - Identity({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.userId, - required this.provider, - required this.providerUid, - required this.providerEmail, - required this.providerAccessToken, - required this.providerAccessTokenExpiry, - required this.providerRefreshToken, - }); - - factory Identity.fromMap(Map map) { - return Identity( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - userId: map['userId'].toString(), - provider: map['provider'].toString(), - providerUid: map['providerUid'].toString(), - providerEmail: map['providerEmail'].toString(), - providerAccessToken: map['providerAccessToken'].toString(), - providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), - providerRefreshToken: map['providerRefreshToken'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "userId": userId, - "provider": provider, - "providerUid": providerUid, - "providerEmail": providerEmail, - "providerAccessToken": providerAccessToken, - "providerAccessTokenExpiry": providerAccessTokenExpiry, - "providerRefreshToken": providerRefreshToken, - }; - } + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "userId": userId, + "provider": provider, + "providerUid": providerUid, + "providerEmail": providerEmail, + "providerAccessToken": providerAccessToken, + "providerAccessTokenExpiry": providerAccessTokenExpiry, + "providerRefreshToken": providerRefreshToken, + }; + } } diff --git a/lib/src/models/identity_list.dart b/lib/src/models/identity_list.dart index eab513d8..77b9d8c7 100644 --- a/lib/src/models/identity_list.dart +++ b/lib/src/models/identity_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Identities List class IdentityList implements Model { - /// Total number of identities documents that matched your query. - final int total; + /// Total number of identities documents that matched your query. + final int total; + /// List of identities. + final List identities; - /// List of identities. - final List identities; + IdentityList({ + required this.total, + required this.identities, + }); - IdentityList({ - required this.total, - required this.identities, - }); + factory IdentityList.fromMap(Map map) { + return IdentityList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + identities: List.from(map['identities'].map((p) => Identity.fromMap(p))), + ); + } - factory IdentityList.fromMap(Map map) { - return IdentityList( - total: map['total'], - identities: List.from( - map['identities'].map((p) => Identity.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "identities": identities.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "identities": identities.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/index.dart b/lib/src/models/index.dart index deb2f92e..9a4a1f9f 100644 --- a/lib/src/models/index.dart +++ b/lib/src/models/index.dart @@ -2,52 +2,47 @@ part of '../../models.dart'; /// Index class Index implements Model { - /// Index Key. - final String key; - - /// Index type. - final String type; - - /// Index status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an index. - final String error; - - /// Index attributes. - final List attributes; - - /// Index orders. - final List? orders; - - Index({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.attributes, - this.orders, - }); - - factory Index.fromMap(Map map) { - return Index( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - attributes: map['attributes'] ?? [], - orders: map['orders'], - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "attributes": attributes, - "orders": orders, - }; - } + /// Index Key. + final String key; + /// Index type. + final String type; + /// Index status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an index. + final String error; + /// Index attributes. + final List attributes; + /// Index orders. + final List? orders; + + Index({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.attributes, + this.orders, + }); + + factory Index.fromMap(Map map) { + return Index( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + attributes: map['attributes'] ?? [], + orders: map['orders'], + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "attributes": attributes, + "orders": orders, + }; + } } diff --git a/lib/src/models/index_list.dart b/lib/src/models/index_list.dart index 4b9ec280..dbf66137 100644 --- a/lib/src/models/index_list.dart +++ b/lib/src/models/index_list.dart @@ -2,28 +2,28 @@ part of '../../models.dart'; /// Indexes List class IndexList implements Model { - /// Total number of indexes documents that matched your query. - final int total; + /// Total number of indexes documents that matched your query. + final int total; + /// List of indexes. + final List indexes; - /// List of indexes. - final List indexes; + IndexList({ + required this.total, + required this.indexes, + }); - IndexList({ - required this.total, - required this.indexes, - }); + factory IndexList.fromMap(Map map) { + return IndexList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + indexes: List.from(map['indexes'].map((p) => Index.fromMap(p))), + ); + } - factory IndexList.fromMap(Map map) { - return IndexList( - total: map['total'], - indexes: List.from(map['indexes'].map((p) => Index.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "indexes": indexes.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "indexes": indexes.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/jwt.dart b/lib/src/models/jwt.dart index e2e31bd2..1b4ff7de 100644 --- a/lib/src/models/jwt.dart +++ b/lib/src/models/jwt.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// JWT class Jwt implements Model { - /// JWT encoded string. - final String jwt; + /// JWT encoded string. + final String jwt; - Jwt({ - required this.jwt, - }); + Jwt({ + required this.jwt, + }); - factory Jwt.fromMap(Map map) { - return Jwt( - jwt: map['jwt'].toString(), - ); - } + factory Jwt.fromMap(Map map) { + return Jwt( + jwt: map['jwt'].toString(), + ); + } - Map toMap() { - return { - "jwt": jwt, - }; - } + Map toMap() { + return { + "jwt": jwt, + }; + } } diff --git a/lib/src/models/language.dart b/lib/src/models/language.dart index b6ec6121..6d26c461 100644 --- a/lib/src/models/language.dart +++ b/lib/src/models/language.dart @@ -2,34 +2,32 @@ part of '../../models.dart'; /// Language class Language implements Model { - /// Language name. - final String name; + /// Language name. + final String name; + /// Language two-character ISO 639-1 codes. + final String code; + /// Language native name. + final String nativeName; - /// Language two-character ISO 639-1 codes. - final String code; + Language({ + required this.name, + required this.code, + required this.nativeName, + }); - /// Language native name. - final String nativeName; + factory Language.fromMap(Map map) { + return Language( + name: map['name'].toString(), + code: map['code'].toString(), + nativeName: map['nativeName'].toString(), + ); + } - Language({ - required this.name, - required this.code, - required this.nativeName, - }); - - factory Language.fromMap(Map map) { - return Language( - name: map['name'].toString(), - code: map['code'].toString(), - nativeName: map['nativeName'].toString(), - ); - } - - Map toMap() { - return { - "name": name, - "code": code, - "nativeName": nativeName, - }; - } + Map toMap() { + return { + "name": name, + "code": code, + "nativeName": nativeName, + }; + } } diff --git a/lib/src/models/language_list.dart b/lib/src/models/language_list.dart index 29f49481..fd4824fb 100644 --- a/lib/src/models/language_list.dart +++ b/lib/src/models/language_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Languages List class LanguageList implements Model { - /// Total number of languages documents that matched your query. - final int total; + /// Total number of languages documents that matched your query. + final int total; + /// List of languages. + final List languages; - /// List of languages. - final List languages; + LanguageList({ + required this.total, + required this.languages, + }); - LanguageList({ - required this.total, - required this.languages, - }); + factory LanguageList.fromMap(Map map) { + return LanguageList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + languages: List.from(map['languages'].map((p) => Language.fromMap(p))), + ); + } - factory LanguageList.fromMap(Map map) { - return LanguageList( - total: map['total'], - languages: - List.from(map['languages'].map((p) => Language.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "languages": languages.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "languages": languages.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/locale.dart b/lib/src/models/locale.dart index 084475bf..0f0fd7f2 100644 --- a/lib/src/models/locale.dart +++ b/lib/src/models/locale.dart @@ -2,58 +2,52 @@ part of '../../models.dart'; /// Locale class Locale implements Model { - /// User IP address. - final String ip; - - /// Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format - final String countryCode; - - /// Country name. This field support localization. - final String country; - - /// Continent code. A two character continent code "AF" for Africa, "AN" for Antarctica, "AS" for Asia, "EU" for Europe, "NA" for North America, "OC" for Oceania, and "SA" for South America. - final String continentCode; - - /// Continent name. This field support localization. - final String continent; - - /// True if country is part of the European Union. - final bool eu; - - /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format - final String currency; - - Locale({ - required this.ip, - required this.countryCode, - required this.country, - required this.continentCode, - required this.continent, - required this.eu, - required this.currency, - }); - - factory Locale.fromMap(Map map) { - return Locale( - ip: map['ip'].toString(), - countryCode: map['countryCode'].toString(), - country: map['country'].toString(), - continentCode: map['continentCode'].toString(), - continent: map['continent'].toString(), - eu: map['eu'], - currency: map['currency'].toString(), - ); - } - - Map toMap() { - return { - "ip": ip, - "countryCode": countryCode, - "country": country, - "continentCode": continentCode, - "continent": continent, - "eu": eu, - "currency": currency, - }; - } + /// User IP address. + final String ip; + /// Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format + final String countryCode; + /// Country name. This field support localization. + final String country; + /// Continent code. A two character continent code "AF" for Africa, "AN" for Antarctica, "AS" for Asia, "EU" for Europe, "NA" for North America, "OC" for Oceania, and "SA" for South America. + final String continentCode; + /// Continent name. This field support localization. + final String continent; + /// True if country is part of the European Union. + final bool eu; + /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format + final String currency; + + Locale({ + required this.ip, + required this.countryCode, + required this.country, + required this.continentCode, + required this.continent, + required this.eu, + required this.currency, + }); + + factory Locale.fromMap(Map map) { + return Locale( + ip: map['ip'].toString(), + countryCode: map['countryCode'].toString(), + country: map['country'].toString(), + continentCode: map['continentCode'].toString(), + continent: map['continent'].toString(), + eu: map['eu'], + currency: map['currency'].toString(), + ); + } + + Map toMap() { + return { + "ip": ip, + "countryCode": countryCode, + "country": country, + "continentCode": continentCode, + "continent": continent, + "eu": eu, + "currency": currency, + }; + } } diff --git a/lib/src/models/locale_code.dart b/lib/src/models/locale_code.dart index 678e40c4..eebce199 100644 --- a/lib/src/models/locale_code.dart +++ b/lib/src/models/locale_code.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// LocaleCode class LocaleCode implements Model { - /// Locale codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) - final String code; + /// Locale codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) + final String code; + /// Locale name + final String name; - /// Locale name - final String name; + LocaleCode({ + required this.code, + required this.name, + }); - LocaleCode({ - required this.code, - required this.name, - }); + factory LocaleCode.fromMap(Map map) { + return LocaleCode( + code: map['code'].toString(), + name: map['name'].toString(), + ); + } - factory LocaleCode.fromMap(Map map) { - return LocaleCode( - code: map['code'].toString(), - name: map['name'].toString(), - ); - } - - Map toMap() { - return { - "code": code, - "name": name, - }; - } + Map toMap() { + return { + "code": code, + "name": name, + }; + } } diff --git a/lib/src/models/locale_code_list.dart b/lib/src/models/locale_code_list.dart index c3f4e4be..9ed7f657 100644 --- a/lib/src/models/locale_code_list.dart +++ b/lib/src/models/locale_code_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Locale codes list class LocaleCodeList implements Model { - /// Total number of localeCodes documents that matched your query. - final int total; + /// Total number of localeCodes documents that matched your query. + final int total; + /// List of localeCodes. + final List localeCodes; - /// List of localeCodes. - final List localeCodes; + LocaleCodeList({ + required this.total, + required this.localeCodes, + }); - LocaleCodeList({ - required this.total, - required this.localeCodes, - }); + factory LocaleCodeList.fromMap(Map map) { + return LocaleCodeList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + localeCodes: List.from(map['localeCodes'].map((p) => LocaleCode.fromMap(p))), + ); + } - factory LocaleCodeList.fromMap(Map map) { - return LocaleCodeList( - total: map['total'], - localeCodes: List.from( - map['localeCodes'].map((p) => LocaleCode.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "localeCodes": localeCodes.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "localeCodes": localeCodes.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/log.dart b/lib/src/models/log.dart index 7fb3f364..41cda2ca 100644 --- a/lib/src/models/log.dart +++ b/lib/src/models/log.dart @@ -2,142 +2,122 @@ part of '../../models.dart'; /// Log class Log implements Model { - /// Event name. - final String event; - - /// User ID. - final String userId; - - /// User Email. - final String userEmail; - - /// User Name. - final String userName; - - /// API mode when event triggered. - final String mode; - - /// IP session in use when the session was created. - final String ip; - - /// Log creation date in ISO 8601 format. - final String time; - - /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). - final String osCode; - - /// Operating system name. - final String osName; - - /// Operating system version. - final String osVersion; - - /// Client type. - final String clientType; - - /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). - final String clientCode; - - /// Client name. - final String clientName; - - /// Client version. - final String clientVersion; - - /// Client engine name. - final String clientEngine; - - /// Client engine name. - final String clientEngineVersion; - - /// Device name. - final String deviceName; - - /// Device brand name. - final String deviceBrand; - - /// Device model name. - final String deviceModel; - - /// Country two-character ISO 3166-1 alpha code. - final String countryCode; - - /// Country name. - final String countryName; - - Log({ - required this.event, - required this.userId, - required this.userEmail, - required this.userName, - required this.mode, - required this.ip, - required this.time, - required this.osCode, - required this.osName, - required this.osVersion, - required this.clientType, - required this.clientCode, - required this.clientName, - required this.clientVersion, - required this.clientEngine, - required this.clientEngineVersion, - required this.deviceName, - required this.deviceBrand, - required this.deviceModel, - required this.countryCode, - required this.countryName, - }); - - factory Log.fromMap(Map map) { - return Log( - event: map['event'].toString(), - userId: map['userId'].toString(), - userEmail: map['userEmail'].toString(), - userName: map['userName'].toString(), - mode: map['mode'].toString(), - ip: map['ip'].toString(), - time: map['time'].toString(), - osCode: map['osCode'].toString(), - osName: map['osName'].toString(), - osVersion: map['osVersion'].toString(), - clientType: map['clientType'].toString(), - clientCode: map['clientCode'].toString(), - clientName: map['clientName'].toString(), - clientVersion: map['clientVersion'].toString(), - clientEngine: map['clientEngine'].toString(), - clientEngineVersion: map['clientEngineVersion'].toString(), - deviceName: map['deviceName'].toString(), - deviceBrand: map['deviceBrand'].toString(), - deviceModel: map['deviceModel'].toString(), - countryCode: map['countryCode'].toString(), - countryName: map['countryName'].toString(), - ); - } - - Map toMap() { - return { - "event": event, - "userId": userId, - "userEmail": userEmail, - "userName": userName, - "mode": mode, - "ip": ip, - "time": time, - "osCode": osCode, - "osName": osName, - "osVersion": osVersion, - "clientType": clientType, - "clientCode": clientCode, - "clientName": clientName, - "clientVersion": clientVersion, - "clientEngine": clientEngine, - "clientEngineVersion": clientEngineVersion, - "deviceName": deviceName, - "deviceBrand": deviceBrand, - "deviceModel": deviceModel, - "countryCode": countryCode, - "countryName": countryName, - }; - } + /// Event name. + final String event; + /// User ID. + final String userId; + /// User Email. + final String userEmail; + /// User Name. + final String userName; + /// API mode when event triggered. + final String mode; + /// IP session in use when the session was created. + final String ip; + /// Log creation date in ISO 8601 format. + final String time; + /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). + final String osCode; + /// Operating system name. + final String osName; + /// Operating system version. + final String osVersion; + /// Client type. + final String clientType; + /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). + final String clientCode; + /// Client name. + final String clientName; + /// Client version. + final String clientVersion; + /// Client engine name. + final String clientEngine; + /// Client engine name. + final String clientEngineVersion; + /// Device name. + final String deviceName; + /// Device brand name. + final String deviceBrand; + /// Device model name. + final String deviceModel; + /// Country two-character ISO 3166-1 alpha code. + final String countryCode; + /// Country name. + final String countryName; + + Log({ + required this.event, + required this.userId, + required this.userEmail, + required this.userName, + required this.mode, + required this.ip, + required this.time, + required this.osCode, + required this.osName, + required this.osVersion, + required this.clientType, + required this.clientCode, + required this.clientName, + required this.clientVersion, + required this.clientEngine, + required this.clientEngineVersion, + required this.deviceName, + required this.deviceBrand, + required this.deviceModel, + required this.countryCode, + required this.countryName, + }); + + factory Log.fromMap(Map map) { + return Log( + event: map['event'].toString(), + userId: map['userId'].toString(), + userEmail: map['userEmail'].toString(), + userName: map['userName'].toString(), + mode: map['mode'].toString(), + ip: map['ip'].toString(), + time: map['time'].toString(), + osCode: map['osCode'].toString(), + osName: map['osName'].toString(), + osVersion: map['osVersion'].toString(), + clientType: map['clientType'].toString(), + clientCode: map['clientCode'].toString(), + clientName: map['clientName'].toString(), + clientVersion: map['clientVersion'].toString(), + clientEngine: map['clientEngine'].toString(), + clientEngineVersion: map['clientEngineVersion'].toString(), + deviceName: map['deviceName'].toString(), + deviceBrand: map['deviceBrand'].toString(), + deviceModel: map['deviceModel'].toString(), + countryCode: map['countryCode'].toString(), + countryName: map['countryName'].toString(), + ); + } + + Map toMap() { + return { + "event": event, + "userId": userId, + "userEmail": userEmail, + "userName": userName, + "mode": mode, + "ip": ip, + "time": time, + "osCode": osCode, + "osName": osName, + "osVersion": osVersion, + "clientType": clientType, + "clientCode": clientCode, + "clientName": clientName, + "clientVersion": clientVersion, + "clientEngine": clientEngine, + "clientEngineVersion": clientEngineVersion, + "deviceName": deviceName, + "deviceBrand": deviceBrand, + "deviceModel": deviceModel, + "countryCode": countryCode, + "countryName": countryName, + }; + } } diff --git a/lib/src/models/log_list.dart b/lib/src/models/log_list.dart index a686897c..c7d6000c 100644 --- a/lib/src/models/log_list.dart +++ b/lib/src/models/log_list.dart @@ -2,28 +2,28 @@ part of '../../models.dart'; /// Logs List class LogList implements Model { - /// Total number of logs documents that matched your query. - final int total; + /// Total number of logs documents that matched your query. + final int total; + /// List of logs. + final List logs; - /// List of logs. - final List logs; + LogList({ + required this.total, + required this.logs, + }); - LogList({ - required this.total, - required this.logs, - }); + factory LogList.fromMap(Map map) { + return LogList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + logs: List.from(map['logs'].map((p) => Log.fromMap(p))), + ); + } - factory LogList.fromMap(Map map) { - return LogList( - total: map['total'], - logs: List.from(map['logs'].map((p) => Log.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "logs": logs.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "logs": logs.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/membership.dart b/lib/src/models/membership.dart index fb3fb523..283f4ee5 100644 --- a/lib/src/models/membership.dart +++ b/lib/src/models/membership.dart @@ -2,94 +2,82 @@ part of '../../models.dart'; /// Membership class Membership implements Model { - /// Membership ID. - final String $id; - - /// Membership creation date in ISO 8601 format. - final String $createdAt; - - /// Membership update date in ISO 8601 format. - final String $updatedAt; - - /// User ID. - final String userId; - - /// User name. - final String userName; - - /// User email address. - final String userEmail; - - /// Team ID. - final String teamId; - - /// Team name. - final String teamName; - - /// Date, the user has been invited to join the team in ISO 8601 format. - final String invited; - - /// Date, the user has accepted the invitation to join the team in ISO 8601 format. - final String joined; - - /// User confirmation status, true if the user has joined the team or false otherwise. - final bool confirm; - - /// Multi factor authentication status, true if the user has MFA enabled or false otherwise. - final bool mfa; - - /// User list of roles - final List roles; - - Membership({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.userId, - required this.userName, - required this.userEmail, - required this.teamId, - required this.teamName, - required this.invited, - required this.joined, - required this.confirm, - required this.mfa, - required this.roles, - }); - - factory Membership.fromMap(Map map) { - return Membership( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - userId: map['userId'].toString(), - userName: map['userName'].toString(), - userEmail: map['userEmail'].toString(), - teamId: map['teamId'].toString(), - teamName: map['teamName'].toString(), - invited: map['invited'].toString(), - joined: map['joined'].toString(), - confirm: map['confirm'], - mfa: map['mfa'], - roles: map['roles'] ?? [], - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "userId": userId, - "userName": userName, - "userEmail": userEmail, - "teamId": teamId, - "teamName": teamName, - "invited": invited, - "joined": joined, - "confirm": confirm, - "mfa": mfa, - "roles": roles, - }; - } + /// Membership ID. + final String $id; + /// Membership creation date in ISO 8601 format. + final String $createdAt; + /// Membership update date in ISO 8601 format. + final String $updatedAt; + /// User ID. + final String userId; + /// User name. + final String userName; + /// User email address. + final String userEmail; + /// Team ID. + final String teamId; + /// Team name. + final String teamName; + /// Date, the user has been invited to join the team in ISO 8601 format. + final String invited; + /// Date, the user has accepted the invitation to join the team in ISO 8601 format. + final String joined; + /// User confirmation status, true if the user has joined the team or false otherwise. + final bool confirm; + /// Multi factor authentication status, true if the user has MFA enabled or false otherwise. + final bool mfa; + /// User list of roles + final List roles; + + Membership({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.userId, + required this.userName, + required this.userEmail, + required this.teamId, + required this.teamName, + required this.invited, + required this.joined, + required this.confirm, + required this.mfa, + required this.roles, + }); + + factory Membership.fromMap(Map map) { + return Membership( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + userId: map['userId'].toString(), + userName: map['userName'].toString(), + userEmail: map['userEmail'].toString(), + teamId: map['teamId'].toString(), + teamName: map['teamName'].toString(), + invited: map['invited'].toString(), + joined: map['joined'].toString(), + confirm: map['confirm'], + mfa: map['mfa'], + roles: map['roles'] ?? [], + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "userId": userId, + "userName": userName, + "userEmail": userEmail, + "teamId": teamId, + "teamName": teamName, + "invited": invited, + "joined": joined, + "confirm": confirm, + "mfa": mfa, + "roles": roles, + }; + } } diff --git a/lib/src/models/membership_list.dart b/lib/src/models/membership_list.dart index ee65133b..f5302cbf 100644 --- a/lib/src/models/membership_list.dart +++ b/lib/src/models/membership_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Memberships List class MembershipList implements Model { - /// Total number of memberships documents that matched your query. - final int total; + /// Total number of memberships documents that matched your query. + final int total; + /// List of memberships. + final List memberships; - /// List of memberships. - final List memberships; + MembershipList({ + required this.total, + required this.memberships, + }); - MembershipList({ - required this.total, - required this.memberships, - }); + factory MembershipList.fromMap(Map map) { + return MembershipList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + memberships: List.from(map['memberships'].map((p) => Membership.fromMap(p))), + ); + } - factory MembershipList.fromMap(Map map) { - return MembershipList( - total: map['total'], - memberships: List.from( - map['memberships'].map((p) => Membership.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "memberships": memberships.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "memberships": memberships.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/message.dart b/lib/src/models/message.dart index 0e528bad..381ab216 100644 --- a/lib/src/models/message.dart +++ b/lib/src/models/message.dart @@ -2,94 +2,83 @@ part of '../../models.dart'; /// Message class Message implements Model { - /// Message ID. - final String $id; - - /// Message creation time in ISO 8601 format. - final String $createdAt; - - /// Message update date in ISO 8601 format. - final String $updatedAt; - - /// Message provider type. - final String providerType; - - /// Topic IDs set as recipients. - final List topics; - - /// User IDs set as recipients. - final List users; - - /// Target IDs set as recipients. - final List targets; - - /// The scheduled time for message. - final String? scheduledAt; - - /// The time when the message was delivered. - final String? deliveredAt; - - /// Delivery errors if any. - final List? deliveryErrors; - - /// Number of recipients the message was delivered to. - final int deliveredTotal; - - /// Data of the message. - final Map data; - - /// Status of delivery. - final String status; - - Message({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.providerType, - required this.topics, - required this.users, - required this.targets, - this.scheduledAt, - this.deliveredAt, - this.deliveryErrors, - required this.deliveredTotal, - required this.data, - required this.status, - }); - - factory Message.fromMap(Map map) { - return Message( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - providerType: map['providerType'].toString(), - topics: map['topics'] ?? [], - users: map['users'] ?? [], - targets: map['targets'] ?? [], - scheduledAt: map['scheduledAt']?.toString(), - deliveredAt: map['deliveredAt']?.toString(), - deliveryErrors: map['deliveryErrors'], - deliveredTotal: map['deliveredTotal'], - data: map['data'], - status: map['status'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "providerType": providerType, - "topics": topics, - "users": users, - "targets": targets, - "scheduledAt": scheduledAt, - "deliveredAt": deliveredAt, - "deliveryErrors": deliveryErrors, - "deliveredTotal": deliveredTotal, - "data": data, - "status": status, - }; - } + /// Message ID. + final String $id; + /// Message creation time in ISO 8601 format. + final String $createdAt; + /// Message update date in ISO 8601 format. + final String $updatedAt; + /// Message provider type. + final String providerType; + /// Topic IDs set as recipients. + final List topics; + /// User IDs set as recipients. + final List users; + /// Target IDs set as recipients. + final List targets; + /// The scheduled time for message. + final String? scheduledAt; + /// The time when the message was delivered. + final String? deliveredAt; + /// Delivery errors if any. + final List? deliveryErrors; + /// Number of recipients the message was delivered to. + final int deliveredTotal; + /// Data of the message. + final Map data; + /// Status of delivery. + final String status; + + Message({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.providerType, + required this.topics, + required this.users, + required this.targets, + this.scheduledAt, + this.deliveredAt, + this.deliveryErrors, + required this.deliveredTotal, + required this.data, + required this.status, + }); + + factory Message.fromMap(Map map) { + return Message( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + providerType: map['providerType'].toString(), + topics: map['topics'] ?? [], + users: map['users'] ?? [], + targets: map['targets'] ?? [], + scheduledAt: map['scheduledAt']?.toString(), + deliveredAt: map['deliveredAt']?.toString(), + deliveryErrors: map['deliveryErrors'], + deliveredTotal: (map['deliveredTotal'] is String) ? + int.tryParse(map['deliveredTotal']) ?? 0:map['deliveredTotal'] ?? 0, + data: map['data'], + status: map['status'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "providerType": providerType, + "topics": topics, + "users": users, + "targets": targets, + "scheduledAt": scheduledAt, + "deliveredAt": deliveredAt, + "deliveryErrors": deliveryErrors, + "deliveredTotal": deliveredTotal, + "data": data, + "status": status, + }; + } } diff --git a/lib/src/models/message_list.dart b/lib/src/models/message_list.dart index 4960c39d..220d3c52 100644 --- a/lib/src/models/message_list.dart +++ b/lib/src/models/message_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Message list class MessageList implements Model { - /// Total number of messages documents that matched your query. - final int total; + /// Total number of messages documents that matched your query. + final int total; + /// List of messages. + final List messages; - /// List of messages. - final List messages; + MessageList({ + required this.total, + required this.messages, + }); - MessageList({ - required this.total, - required this.messages, - }); + factory MessageList.fromMap(Map map) { + return MessageList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + messages: List.from(map['messages'].map((p) => Message.fromMap(p))), + ); + } - factory MessageList.fromMap(Map map) { - return MessageList( - total: map['total'], - messages: - List.from(map['messages'].map((p) => Message.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "messages": messages.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "messages": messages.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/mfa_challenge.dart b/lib/src/models/mfa_challenge.dart index 96bf3c65..043ff286 100644 --- a/lib/src/models/mfa_challenge.dart +++ b/lib/src/models/mfa_challenge.dart @@ -2,40 +2,37 @@ part of '../../models.dart'; /// MFA Challenge class MfaChallenge implements Model { - /// Token ID. - final String $id; + /// Token ID. + final String $id; + /// Token creation date in ISO 8601 format. + final String $createdAt; + /// User ID. + final String userId; + /// Token expiration date in ISO 8601 format. + final String expire; - /// Token creation date in ISO 8601 format. - final String $createdAt; + MfaChallenge({ + required this.$id, + required this.$createdAt, + required this.userId, + required this.expire, + }); - /// User ID. - final String userId; + factory MfaChallenge.fromMap(Map map) { + return MfaChallenge( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + userId: map['userId'].toString(), + expire: map['expire'].toString(), + ); + } - /// Token expiration date in ISO 8601 format. - final String expire; - - MfaChallenge({ - required this.$id, - required this.$createdAt, - required this.userId, - required this.expire, - }); - - factory MfaChallenge.fromMap(Map map) { - return MfaChallenge( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - userId: map['userId'].toString(), - expire: map['expire'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "userId": userId, - "expire": expire, - }; - } + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "userId": userId, + "expire": expire, + }; + } } diff --git a/lib/src/models/mfa_factors.dart b/lib/src/models/mfa_factors.dart index c930a23e..f453e870 100644 --- a/lib/src/models/mfa_factors.dart +++ b/lib/src/models/mfa_factors.dart @@ -2,40 +2,37 @@ part of '../../models.dart'; /// MFAFactors class MfaFactors implements Model { - /// Can TOTP be used for MFA challenge for this account. - final bool totp; + /// Can TOTP be used for MFA challenge for this account. + final bool totp; + /// Can phone (SMS) be used for MFA challenge for this account. + final bool phone; + /// Can email be used for MFA challenge for this account. + final bool email; + /// Can recovery code be used for MFA challenge for this account. + final bool recoveryCode; - /// Can phone (SMS) be used for MFA challenge for this account. - final bool phone; + MfaFactors({ + required this.totp, + required this.phone, + required this.email, + required this.recoveryCode, + }); - /// Can email be used for MFA challenge for this account. - final bool email; + factory MfaFactors.fromMap(Map map) { + return MfaFactors( + totp: map['totp'], + phone: map['phone'], + email: map['email'], + recoveryCode: map['recoveryCode'], + ); + } - /// Can recovery code be used for MFA challenge for this account. - final bool recoveryCode; - - MfaFactors({ - required this.totp, - required this.phone, - required this.email, - required this.recoveryCode, - }); - - factory MfaFactors.fromMap(Map map) { - return MfaFactors( - totp: map['totp'], - phone: map['phone'], - email: map['email'], - recoveryCode: map['recoveryCode'], - ); - } - - Map toMap() { - return { - "totp": totp, - "phone": phone, - "email": email, - "recoveryCode": recoveryCode, - }; - } + Map toMap() { + return { + "totp": totp, + "phone": phone, + "email": email, + "recoveryCode": recoveryCode, + }; + } } diff --git a/lib/src/models/mfa_recovery_codes.dart b/lib/src/models/mfa_recovery_codes.dart index 83483901..68402443 100644 --- a/lib/src/models/mfa_recovery_codes.dart +++ b/lib/src/models/mfa_recovery_codes.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// MFA Recovery Codes class MfaRecoveryCodes implements Model { - /// Recovery codes. - final List recoveryCodes; + /// Recovery codes. + final List recoveryCodes; - MfaRecoveryCodes({ - required this.recoveryCodes, - }); + MfaRecoveryCodes({ + required this.recoveryCodes, + }); - factory MfaRecoveryCodes.fromMap(Map map) { - return MfaRecoveryCodes( - recoveryCodes: map['recoveryCodes'] ?? [], - ); - } + factory MfaRecoveryCodes.fromMap(Map map) { + return MfaRecoveryCodes( + recoveryCodes: map['recoveryCodes'] ?? [], + ); + } - Map toMap() { - return { - "recoveryCodes": recoveryCodes, - }; - } + Map toMap() { + return { + "recoveryCodes": recoveryCodes, + }; + } } diff --git a/lib/src/models/mfa_type.dart b/lib/src/models/mfa_type.dart index 0573166e..87064007 100644 --- a/lib/src/models/mfa_type.dart +++ b/lib/src/models/mfa_type.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// MFAType class MfaType implements Model { - /// Secret token used for TOTP factor. - final String secret; + /// Secret token used for TOTP factor. + final String secret; + /// URI for authenticator apps. + final String uri; - /// URI for authenticator apps. - final String uri; + MfaType({ + required this.secret, + required this.uri, + }); - MfaType({ - required this.secret, - required this.uri, - }); + factory MfaType.fromMap(Map map) { + return MfaType( + secret: map['secret'].toString(), + uri: map['uri'].toString(), + ); + } - factory MfaType.fromMap(Map map) { - return MfaType( - secret: map['secret'].toString(), - uri: map['uri'].toString(), - ); - } - - Map toMap() { - return { - "secret": secret, - "uri": uri, - }; - } + Map toMap() { + return { + "secret": secret, + "uri": uri, + }; + } } diff --git a/lib/src/models/model.dart b/lib/src/models/model.dart index f810a35b..48e5b84a 100644 --- a/lib/src/models/model.dart +++ b/lib/src/models/model.dart @@ -2,4 +2,4 @@ part of '../../models.dart'; abstract class Model { Map toMap(); -} +} \ No newline at end of file diff --git a/lib/src/models/phone.dart b/lib/src/models/phone.dart index 40f7bcd2..24f7260d 100644 --- a/lib/src/models/phone.dart +++ b/lib/src/models/phone.dart @@ -2,34 +2,32 @@ part of '../../models.dart'; /// Phone class Phone implements Model { - /// Phone code. - final String code; + /// Phone code. + final String code; + /// Country two-character ISO 3166-1 alpha code. + final String countryCode; + /// Country name. + final String countryName; - /// Country two-character ISO 3166-1 alpha code. - final String countryCode; + Phone({ + required this.code, + required this.countryCode, + required this.countryName, + }); - /// Country name. - final String countryName; + factory Phone.fromMap(Map map) { + return Phone( + code: map['code'].toString(), + countryCode: map['countryCode'].toString(), + countryName: map['countryName'].toString(), + ); + } - Phone({ - required this.code, - required this.countryCode, - required this.countryName, - }); - - factory Phone.fromMap(Map map) { - return Phone( - code: map['code'].toString(), - countryCode: map['countryCode'].toString(), - countryName: map['countryName'].toString(), - ); - } - - Map toMap() { - return { - "code": code, - "countryCode": countryCode, - "countryName": countryName, - }; - } + Map toMap() { + return { + "code": code, + "countryCode": countryCode, + "countryName": countryName, + }; + } } diff --git a/lib/src/models/phone_list.dart b/lib/src/models/phone_list.dart index 1ae5a351..f00a91d3 100644 --- a/lib/src/models/phone_list.dart +++ b/lib/src/models/phone_list.dart @@ -2,28 +2,28 @@ part of '../../models.dart'; /// Phones List class PhoneList implements Model { - /// Total number of phones documents that matched your query. - final int total; + /// Total number of phones documents that matched your query. + final int total; + /// List of phones. + final List phones; - /// List of phones. - final List phones; + PhoneList({ + required this.total, + required this.phones, + }); - PhoneList({ - required this.total, - required this.phones, - }); + factory PhoneList.fromMap(Map map) { + return PhoneList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + phones: List.from(map['phones'].map((p) => Phone.fromMap(p))), + ); + } - factory PhoneList.fromMap(Map map) { - return PhoneList( - total: map['total'], - phones: List.from(map['phones'].map((p) => Phone.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "phones": phones.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "phones": phones.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/preferences.dart b/lib/src/models/preferences.dart index 3549cff0..3c62f86d 100644 --- a/lib/src/models/preferences.dart +++ b/lib/src/models/preferences.dart @@ -2,23 +2,23 @@ part of '../../models.dart'; /// Preferences class Preferences implements Model { - final Map data; + final Map data; - Preferences({ - required this.data, - }); + Preferences({ + required this.data, + }); - factory Preferences.fromMap(Map map) { - return Preferences( - data: map, - ); - } + factory Preferences.fromMap(Map map) { + return Preferences( + data: map, + ); + } - Map toMap() { - return { - "data": data, - }; - } + Map toMap() { + return { + "data": data, + }; + } - T convertTo(T Function(Map) fromJson) => fromJson(data); + T convertTo(T Function(Map) fromJson) => fromJson(data); } diff --git a/lib/src/models/provider.dart b/lib/src/models/provider.dart index 1a762f85..ba0855de 100644 --- a/lib/src/models/provider.dart +++ b/lib/src/models/provider.dart @@ -2,70 +2,62 @@ part of '../../models.dart'; /// Provider class Provider implements Model { - /// Provider ID. - final String $id; - - /// Provider creation time in ISO 8601 format. - final String $createdAt; - - /// Provider update date in ISO 8601 format. - final String $updatedAt; - - /// The name for the provider instance. - final String name; - - /// The name of the provider service. - final String provider; - - /// Is provider enabled? - final bool enabled; - - /// Type of provider. - final String type; - - /// Provider credentials. - final Map credentials; - - /// Provider options. - final Map? options; - - Provider({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.provider, - required this.enabled, - required this.type, - required this.credentials, - this.options, - }); - - factory Provider.fromMap(Map map) { - return Provider( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - provider: map['provider'].toString(), - enabled: map['enabled'], - type: map['type'].toString(), - credentials: map['credentials'], - options: map['options'], - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "provider": provider, - "enabled": enabled, - "type": type, - "credentials": credentials, - "options": options, - }; - } + /// Provider ID. + final String $id; + /// Provider creation time in ISO 8601 format. + final String $createdAt; + /// Provider update date in ISO 8601 format. + final String $updatedAt; + /// The name for the provider instance. + final String name; + /// The name of the provider service. + final String provider; + /// Is provider enabled? + final bool enabled; + /// Type of provider. + final String type; + /// Provider credentials. + final Map credentials; + /// Provider options. + final Map? options; + + Provider({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.provider, + required this.enabled, + required this.type, + required this.credentials, + this.options, + }); + + factory Provider.fromMap(Map map) { + return Provider( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + provider: map['provider'].toString(), + enabled: map['enabled'], + type: map['type'].toString(), + credentials: map['credentials'], + options: map['options'], + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "provider": provider, + "enabled": enabled, + "type": type, + "credentials": credentials, + "options": options, + }; + } } diff --git a/lib/src/models/provider_list.dart b/lib/src/models/provider_list.dart index a4f980f6..fe6d41d0 100644 --- a/lib/src/models/provider_list.dart +++ b/lib/src/models/provider_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Provider list class ProviderList implements Model { - /// Total number of providers documents that matched your query. - final int total; + /// Total number of providers documents that matched your query. + final int total; + /// List of providers. + final List providers; - /// List of providers. - final List providers; + ProviderList({ + required this.total, + required this.providers, + }); - ProviderList({ - required this.total, - required this.providers, - }); + factory ProviderList.fromMap(Map map) { + return ProviderList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + providers: List.from(map['providers'].map((p) => Provider.fromMap(p))), + ); + } - factory ProviderList.fromMap(Map map) { - return ProviderList( - total: map['total'], - providers: - List.from(map['providers'].map((p) => Provider.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "providers": providers.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "providers": providers.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/runtime.dart b/lib/src/models/runtime.dart index c99f3541..acda5a4f 100644 --- a/lib/src/models/runtime.dart +++ b/lib/src/models/runtime.dart @@ -2,64 +2,57 @@ part of '../../models.dart'; /// Runtime class Runtime implements Model { - /// Runtime ID. - final String $id; - - /// Parent runtime key. - final String key; - - /// Runtime Name. - final String name; - - /// Runtime version. - final String version; - - /// Base Docker image used to build the runtime. - final String base; - - /// Image name of Docker Hub. - final String image; - - /// Name of the logo image. - final String logo; - - /// List of supported architectures. - final List supports; - - Runtime({ - required this.$id, - required this.key, - required this.name, - required this.version, - required this.base, - required this.image, - required this.logo, - required this.supports, - }); - - factory Runtime.fromMap(Map map) { - return Runtime( - $id: map['\$id'].toString(), - key: map['key'].toString(), - name: map['name'].toString(), - version: map['version'].toString(), - base: map['base'].toString(), - image: map['image'].toString(), - logo: map['logo'].toString(), - supports: map['supports'] ?? [], - ); - } - - Map toMap() { - return { - "\$id": $id, - "key": key, - "name": name, - "version": version, - "base": base, - "image": image, - "logo": logo, - "supports": supports, - }; - } + /// Runtime ID. + final String $id; + /// Parent runtime key. + final String key; + /// Runtime Name. + final String name; + /// Runtime version. + final String version; + /// Base Docker image used to build the runtime. + final String base; + /// Image name of Docker Hub. + final String image; + /// Name of the logo image. + final String logo; + /// List of supported architectures. + final List supports; + + Runtime({ + required this.$id, + required this.key, + required this.name, + required this.version, + required this.base, + required this.image, + required this.logo, + required this.supports, + }); + + factory Runtime.fromMap(Map map) { + return Runtime( + $id: map['\$id'].toString(), + key: map['key'].toString(), + name: map['name'].toString(), + version: map['version'].toString(), + base: map['base'].toString(), + image: map['image'].toString(), + logo: map['logo'].toString(), + supports: map['supports'] ?? [], + ); + } + + Map toMap() { + return { + "\$id": $id, + "key": key, + "name": name, + "version": version, + "base": base, + "image": image, + "logo": logo, + "supports": supports, + }; + } } diff --git a/lib/src/models/runtime_list.dart b/lib/src/models/runtime_list.dart index 7845cd8b..8ee86986 100644 --- a/lib/src/models/runtime_list.dart +++ b/lib/src/models/runtime_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Runtimes List class RuntimeList implements Model { - /// Total number of runtimes documents that matched your query. - final int total; + /// Total number of runtimes documents that matched your query. + final int total; + /// List of runtimes. + final List runtimes; - /// List of runtimes. - final List runtimes; + RuntimeList({ + required this.total, + required this.runtimes, + }); - RuntimeList({ - required this.total, - required this.runtimes, - }); + factory RuntimeList.fromMap(Map map) { + return RuntimeList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + runtimes: List.from(map['runtimes'].map((p) => Runtime.fromMap(p))), + ); + } - factory RuntimeList.fromMap(Map map) { - return RuntimeList( - total: map['total'], - runtimes: - List.from(map['runtimes'].map((p) => Runtime.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "runtimes": runtimes.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "runtimes": runtimes.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/session.dart b/lib/src/models/session.dart index 1f55d400..10566f44 100644 --- a/lib/src/models/session.dart +++ b/lib/src/models/session.dart @@ -2,190 +2,162 @@ part of '../../models.dart'; /// Session class Session implements Model { - /// Session ID. - final String $id; - - /// Session creation date in ISO 8601 format. - final String $createdAt; - - /// Session update date in ISO 8601 format. - final String $updatedAt; - - /// User ID. - final String userId; - - /// Session expiration date in ISO 8601 format. - final String expire; - - /// Session Provider. - final String provider; - - /// Session Provider User ID. - final String providerUid; - - /// Session Provider Access Token. - final String providerAccessToken; - - /// The date of when the access token expires in ISO 8601 format. - final String providerAccessTokenExpiry; - - /// Session Provider Refresh Token. - final String providerRefreshToken; - - /// IP in use when the session was created. - final String ip; - - /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). - final String osCode; - - /// Operating system name. - final String osName; - - /// Operating system version. - final String osVersion; - - /// Client type. - final String clientType; - - /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). - final String clientCode; - - /// Client name. - final String clientName; - - /// Client version. - final String clientVersion; - - /// Client engine name. - final String clientEngine; - - /// Client engine name. - final String clientEngineVersion; - - /// Device name. - final String deviceName; - - /// Device brand name. - final String deviceBrand; - - /// Device model name. - final String deviceModel; - - /// Country two-character ISO 3166-1 alpha code. - final String countryCode; - - /// Country name. - final String countryName; - - /// Returns true if this the current user session. - final bool current; - - /// Returns a list of active session factors. - final List factors; - - /// Secret used to authenticate the user. Only included if the request was made with an API key - final String secret; - - /// Most recent date in ISO 8601 format when the session successfully passed MFA challenge. - final String mfaUpdatedAt; - - Session({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.userId, - required this.expire, - required this.provider, - required this.providerUid, - required this.providerAccessToken, - required this.providerAccessTokenExpiry, - required this.providerRefreshToken, - required this.ip, - required this.osCode, - required this.osName, - required this.osVersion, - required this.clientType, - required this.clientCode, - required this.clientName, - required this.clientVersion, - required this.clientEngine, - required this.clientEngineVersion, - required this.deviceName, - required this.deviceBrand, - required this.deviceModel, - required this.countryCode, - required this.countryName, - required this.current, - required this.factors, - required this.secret, - required this.mfaUpdatedAt, - }); - - factory Session.fromMap(Map map) { - return Session( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - userId: map['userId'].toString(), - expire: map['expire'].toString(), - provider: map['provider'].toString(), - providerUid: map['providerUid'].toString(), - providerAccessToken: map['providerAccessToken'].toString(), - providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), - providerRefreshToken: map['providerRefreshToken'].toString(), - ip: map['ip'].toString(), - osCode: map['osCode'].toString(), - osName: map['osName'].toString(), - osVersion: map['osVersion'].toString(), - clientType: map['clientType'].toString(), - clientCode: map['clientCode'].toString(), - clientName: map['clientName'].toString(), - clientVersion: map['clientVersion'].toString(), - clientEngine: map['clientEngine'].toString(), - clientEngineVersion: map['clientEngineVersion'].toString(), - deviceName: map['deviceName'].toString(), - deviceBrand: map['deviceBrand'].toString(), - deviceModel: map['deviceModel'].toString(), - countryCode: map['countryCode'].toString(), - countryName: map['countryName'].toString(), - current: map['current'], - factors: map['factors'] ?? [], - secret: map['secret'].toString(), - mfaUpdatedAt: map['mfaUpdatedAt'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "userId": userId, - "expire": expire, - "provider": provider, - "providerUid": providerUid, - "providerAccessToken": providerAccessToken, - "providerAccessTokenExpiry": providerAccessTokenExpiry, - "providerRefreshToken": providerRefreshToken, - "ip": ip, - "osCode": osCode, - "osName": osName, - "osVersion": osVersion, - "clientType": clientType, - "clientCode": clientCode, - "clientName": clientName, - "clientVersion": clientVersion, - "clientEngine": clientEngine, - "clientEngineVersion": clientEngineVersion, - "deviceName": deviceName, - "deviceBrand": deviceBrand, - "deviceModel": deviceModel, - "countryCode": countryCode, - "countryName": countryName, - "current": current, - "factors": factors, - "secret": secret, - "mfaUpdatedAt": mfaUpdatedAt, - }; - } + /// Session ID. + final String $id; + /// Session creation date in ISO 8601 format. + final String $createdAt; + /// Session update date in ISO 8601 format. + final String $updatedAt; + /// User ID. + final String userId; + /// Session expiration date in ISO 8601 format. + final String expire; + /// Session Provider. + final String provider; + /// Session Provider User ID. + final String providerUid; + /// Session Provider Access Token. + final String providerAccessToken; + /// The date of when the access token expires in ISO 8601 format. + final String providerAccessTokenExpiry; + /// Session Provider Refresh Token. + final String providerRefreshToken; + /// IP in use when the session was created. + final String ip; + /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). + final String osCode; + /// Operating system name. + final String osName; + /// Operating system version. + final String osVersion; + /// Client type. + final String clientType; + /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). + final String clientCode; + /// Client name. + final String clientName; + /// Client version. + final String clientVersion; + /// Client engine name. + final String clientEngine; + /// Client engine name. + final String clientEngineVersion; + /// Device name. + final String deviceName; + /// Device brand name. + final String deviceBrand; + /// Device model name. + final String deviceModel; + /// Country two-character ISO 3166-1 alpha code. + final String countryCode; + /// Country name. + final String countryName; + /// Returns true if this the current user session. + final bool current; + /// Returns a list of active session factors. + final List factors; + /// Secret used to authenticate the user. Only included if the request was made with an API key + final String secret; + /// Most recent date in ISO 8601 format when the session successfully passed MFA challenge. + final String mfaUpdatedAt; + + Session({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.userId, + required this.expire, + required this.provider, + required this.providerUid, + required this.providerAccessToken, + required this.providerAccessTokenExpiry, + required this.providerRefreshToken, + required this.ip, + required this.osCode, + required this.osName, + required this.osVersion, + required this.clientType, + required this.clientCode, + required this.clientName, + required this.clientVersion, + required this.clientEngine, + required this.clientEngineVersion, + required this.deviceName, + required this.deviceBrand, + required this.deviceModel, + required this.countryCode, + required this.countryName, + required this.current, + required this.factors, + required this.secret, + required this.mfaUpdatedAt, + }); + + factory Session.fromMap(Map map) { + return Session( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + userId: map['userId'].toString(), + expire: map['expire'].toString(), + provider: map['provider'].toString(), + providerUid: map['providerUid'].toString(), + providerAccessToken: map['providerAccessToken'].toString(), + providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), + providerRefreshToken: map['providerRefreshToken'].toString(), + ip: map['ip'].toString(), + osCode: map['osCode'].toString(), + osName: map['osName'].toString(), + osVersion: map['osVersion'].toString(), + clientType: map['clientType'].toString(), + clientCode: map['clientCode'].toString(), + clientName: map['clientName'].toString(), + clientVersion: map['clientVersion'].toString(), + clientEngine: map['clientEngine'].toString(), + clientEngineVersion: map['clientEngineVersion'].toString(), + deviceName: map['deviceName'].toString(), + deviceBrand: map['deviceBrand'].toString(), + deviceModel: map['deviceModel'].toString(), + countryCode: map['countryCode'].toString(), + countryName: map['countryName'].toString(), + current: map['current'], + factors: map['factors'] ?? [], + secret: map['secret'].toString(), + mfaUpdatedAt: map['mfaUpdatedAt'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "userId": userId, + "expire": expire, + "provider": provider, + "providerUid": providerUid, + "providerAccessToken": providerAccessToken, + "providerAccessTokenExpiry": providerAccessTokenExpiry, + "providerRefreshToken": providerRefreshToken, + "ip": ip, + "osCode": osCode, + "osName": osName, + "osVersion": osVersion, + "clientType": clientType, + "clientCode": clientCode, + "clientName": clientName, + "clientVersion": clientVersion, + "clientEngine": clientEngine, + "clientEngineVersion": clientEngineVersion, + "deviceName": deviceName, + "deviceBrand": deviceBrand, + "deviceModel": deviceModel, + "countryCode": countryCode, + "countryName": countryName, + "current": current, + "factors": factors, + "secret": secret, + "mfaUpdatedAt": mfaUpdatedAt, + }; + } } diff --git a/lib/src/models/session_list.dart b/lib/src/models/session_list.dart index e4739c9b..f17b963d 100644 --- a/lib/src/models/session_list.dart +++ b/lib/src/models/session_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Sessions List class SessionList implements Model { - /// Total number of sessions documents that matched your query. - final int total; + /// Total number of sessions documents that matched your query. + final int total; + /// List of sessions. + final List sessions; - /// List of sessions. - final List sessions; + SessionList({ + required this.total, + required this.sessions, + }); - SessionList({ - required this.total, - required this.sessions, - }); + factory SessionList.fromMap(Map map) { + return SessionList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + sessions: List.from(map['sessions'].map((p) => Session.fromMap(p))), + ); + } - factory SessionList.fromMap(Map map) { - return SessionList( - total: map['total'], - sessions: - List.from(map['sessions'].map((p) => Session.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "sessions": sessions.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "sessions": sessions.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/specification.dart b/lib/src/models/specification.dart index cf2fb838..97b359f2 100644 --- a/lib/src/models/specification.dart +++ b/lib/src/models/specification.dart @@ -2,40 +2,38 @@ part of '../../models.dart'; /// Specification class Specification implements Model { - /// Memory size in MB. - final int memory; + /// Memory size in MB. + final int memory; + /// Number of CPUs. + final double cpus; + /// Is size enabled. + final bool enabled; + /// Size slug. + final String slug; - /// Number of CPUs. - final double cpus; + Specification({ + required this.memory, + required this.cpus, + required this.enabled, + required this.slug, + }); - /// Is size enabled. - final bool enabled; + factory Specification.fromMap(Map map) { + return Specification( + memory: (map['memory'] is String) ? + int.tryParse(map['memory']) ?? 0:map['memory'] ?? 0, + cpus: map['cpus'].toDouble(), + enabled: map['enabled'], + slug: map['slug'].toString(), + ); + } - /// Size slug. - final String slug; - - Specification({ - required this.memory, - required this.cpus, - required this.enabled, - required this.slug, - }); - - factory Specification.fromMap(Map map) { - return Specification( - memory: map['memory'], - cpus: map['cpus'].toDouble(), - enabled: map['enabled'], - slug: map['slug'].toString(), - ); - } - - Map toMap() { - return { - "memory": memory, - "cpus": cpus, - "enabled": enabled, - "slug": slug, - }; - } + Map toMap() { + return { + "memory": memory, + "cpus": cpus, + "enabled": enabled, + "slug": slug, + }; + } } diff --git a/lib/src/models/specification_list.dart b/lib/src/models/specification_list.dart index c66d5ac3..1b7d3a69 100644 --- a/lib/src/models/specification_list.dart +++ b/lib/src/models/specification_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Specifications List class SpecificationList implements Model { - /// Total number of specifications documents that matched your query. - final int total; + /// Total number of specifications documents that matched your query. + final int total; + /// List of specifications. + final List specifications; - /// List of specifications. - final List specifications; + SpecificationList({ + required this.total, + required this.specifications, + }); - SpecificationList({ - required this.total, - required this.specifications, - }); + factory SpecificationList.fromMap(Map map) { + return SpecificationList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + specifications: List.from(map['specifications'].map((p) => Specification.fromMap(p))), + ); + } - factory SpecificationList.fromMap(Map map) { - return SpecificationList( - total: map['total'], - specifications: List.from( - map['specifications'].map((p) => Specification.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "specifications": specifications.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "specifications": specifications.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/subscriber.dart b/lib/src/models/subscriber.dart index 0c926297..97bdb018 100644 --- a/lib/src/models/subscriber.dart +++ b/lib/src/models/subscriber.dart @@ -2,70 +2,62 @@ part of '../../models.dart'; /// Subscriber class Subscriber implements Model { - /// Subscriber ID. - final String $id; - - /// Subscriber creation time in ISO 8601 format. - final String $createdAt; - - /// Subscriber update date in ISO 8601 format. - final String $updatedAt; - - /// Target ID. - final String targetId; - - /// Target. - final Target target; - - /// Topic ID. - final String userId; - - /// User Name. - final String userName; - - /// Topic ID. - final String topicId; - - /// The target provider type. Can be one of the following: `email`, `sms` or `push`. - final String providerType; - - Subscriber({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.targetId, - required this.target, - required this.userId, - required this.userName, - required this.topicId, - required this.providerType, - }); - - factory Subscriber.fromMap(Map map) { - return Subscriber( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - targetId: map['targetId'].toString(), - target: Target.fromMap(map['target']), - userId: map['userId'].toString(), - userName: map['userName'].toString(), - topicId: map['topicId'].toString(), - providerType: map['providerType'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "targetId": targetId, - "target": target.toMap(), - "userId": userId, - "userName": userName, - "topicId": topicId, - "providerType": providerType, - }; - } + /// Subscriber ID. + final String $id; + /// Subscriber creation time in ISO 8601 format. + final String $createdAt; + /// Subscriber update date in ISO 8601 format. + final String $updatedAt; + /// Target ID. + final String targetId; + /// Target. + final Target target; + /// Topic ID. + final String userId; + /// User Name. + final String userName; + /// Topic ID. + final String topicId; + /// The target provider type. Can be one of the following: `email`, `sms` or `push`. + final String providerType; + + Subscriber({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.targetId, + required this.target, + required this.userId, + required this.userName, + required this.topicId, + required this.providerType, + }); + + factory Subscriber.fromMap(Map map) { + return Subscriber( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + targetId: map['targetId'].toString(), + target: Target.fromMap(map['target']), + userId: map['userId'].toString(), + userName: map['userName'].toString(), + topicId: map['topicId'].toString(), + providerType: map['providerType'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "targetId": targetId, + "target": target.toMap(), + "userId": userId, + "userName": userName, + "topicId": topicId, + "providerType": providerType, + }; + } } diff --git a/lib/src/models/subscriber_list.dart b/lib/src/models/subscriber_list.dart index 14577a7e..dc6724cf 100644 --- a/lib/src/models/subscriber_list.dart +++ b/lib/src/models/subscriber_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Subscriber list class SubscriberList implements Model { - /// Total number of subscribers documents that matched your query. - final int total; + /// Total number of subscribers documents that matched your query. + final int total; + /// List of subscribers. + final List subscribers; - /// List of subscribers. - final List subscribers; + SubscriberList({ + required this.total, + required this.subscribers, + }); - SubscriberList({ - required this.total, - required this.subscribers, - }); + factory SubscriberList.fromMap(Map map) { + return SubscriberList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + subscribers: List.from(map['subscribers'].map((p) => Subscriber.fromMap(p))), + ); + } - factory SubscriberList.fromMap(Map map) { - return SubscriberList( - total: map['total'], - subscribers: List.from( - map['subscribers'].map((p) => Subscriber.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "subscribers": subscribers.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "subscribers": subscribers.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/target.dart b/lib/src/models/target.dart index 68460126..50134304 100644 --- a/lib/src/models/target.dart +++ b/lib/src/models/target.dart @@ -2,64 +2,57 @@ part of '../../models.dart'; /// Target class Target implements Model { - /// Target ID. - final String $id; - - /// Target creation time in ISO 8601 format. - final String $createdAt; - - /// Target update date in ISO 8601 format. - final String $updatedAt; - - /// Target Name. - final String name; - - /// User ID. - final String userId; - - /// Provider ID. - final String? providerId; - - /// The target provider type. Can be one of the following: `email`, `sms` or `push`. - final String providerType; - - /// The target identifier. - final String identifier; - - Target({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.userId, - this.providerId, - required this.providerType, - required this.identifier, - }); - - factory Target.fromMap(Map map) { - return Target( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - userId: map['userId'].toString(), - providerId: map['providerId']?.toString(), - providerType: map['providerType'].toString(), - identifier: map['identifier'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "userId": userId, - "providerId": providerId, - "providerType": providerType, - "identifier": identifier, - }; - } + /// Target ID. + final String $id; + /// Target creation time in ISO 8601 format. + final String $createdAt; + /// Target update date in ISO 8601 format. + final String $updatedAt; + /// Target Name. + final String name; + /// User ID. + final String userId; + /// Provider ID. + final String? providerId; + /// The target provider type. Can be one of the following: `email`, `sms` or `push`. + final String providerType; + /// The target identifier. + final String identifier; + + Target({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.userId, + this.providerId, + required this.providerType, + required this.identifier, + }); + + factory Target.fromMap(Map map) { + return Target( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + userId: map['userId'].toString(), + providerId: map['providerId']?.toString(), + providerType: map['providerType'].toString(), + identifier: map['identifier'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "userId": userId, + "providerId": providerId, + "providerType": providerType, + "identifier": identifier, + }; + } } diff --git a/lib/src/models/target_list.dart b/lib/src/models/target_list.dart index 8b0ef79d..bc859bee 100644 --- a/lib/src/models/target_list.dart +++ b/lib/src/models/target_list.dart @@ -2,28 +2,28 @@ part of '../../models.dart'; /// Target list class TargetList implements Model { - /// Total number of targets documents that matched your query. - final int total; + /// Total number of targets documents that matched your query. + final int total; + /// List of targets. + final List targets; - /// List of targets. - final List targets; + TargetList({ + required this.total, + required this.targets, + }); - TargetList({ - required this.total, - required this.targets, - }); + factory TargetList.fromMap(Map map) { + return TargetList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + targets: List.from(map['targets'].map((p) => Target.fromMap(p))), + ); + } - factory TargetList.fromMap(Map map) { - return TargetList( - total: map['total'], - targets: List.from(map['targets'].map((p) => Target.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "targets": targets.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "targets": targets.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/team.dart b/lib/src/models/team.dart index 43df33a8..118be8dd 100644 --- a/lib/src/models/team.dart +++ b/lib/src/models/team.dart @@ -2,52 +2,48 @@ part of '../../models.dart'; /// Team class Team implements Model { - /// Team ID. - final String $id; - - /// Team creation date in ISO 8601 format. - final String $createdAt; - - /// Team update date in ISO 8601 format. - final String $updatedAt; - - /// Team name. - final String name; - - /// Total number of team members. - final int total; - - /// Team preferences as a key-value object - final Preferences prefs; - - Team({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.total, - required this.prefs, - }); - - factory Team.fromMap(Map map) { - return Team( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - total: map['total'], - prefs: Preferences.fromMap(map['prefs']), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "total": total, - "prefs": prefs.toMap(), - }; - } + /// Team ID. + final String $id; + /// Team creation date in ISO 8601 format. + final String $createdAt; + /// Team update date in ISO 8601 format. + final String $updatedAt; + /// Team name. + final String name; + /// Total number of team members. + final int total; + /// Team preferences as a key-value object + final Preferences prefs; + + Team({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.total, + required this.prefs, + }); + + factory Team.fromMap(Map map) { + return Team( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + prefs: Preferences.fromMap(map['prefs']), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "total": total, + "prefs": prefs.toMap(), + }; + } } diff --git a/lib/src/models/team_list.dart b/lib/src/models/team_list.dart index 817e944f..f011ce95 100644 --- a/lib/src/models/team_list.dart +++ b/lib/src/models/team_list.dart @@ -2,28 +2,28 @@ part of '../../models.dart'; /// Teams List class TeamList implements Model { - /// Total number of teams documents that matched your query. - final int total; + /// Total number of teams documents that matched your query. + final int total; + /// List of teams. + final List teams; - /// List of teams. - final List teams; + TeamList({ + required this.total, + required this.teams, + }); - TeamList({ - required this.total, - required this.teams, - }); + factory TeamList.fromMap(Map map) { + return TeamList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + teams: List.from(map['teams'].map((p) => Team.fromMap(p))), + ); + } - factory TeamList.fromMap(Map map) { - return TeamList( - total: map['total'], - teams: List.from(map['teams'].map((p) => Team.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "teams": teams.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "teams": teams.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/token.dart b/lib/src/models/token.dart index 35115467..217006c0 100644 --- a/lib/src/models/token.dart +++ b/lib/src/models/token.dart @@ -2,52 +2,47 @@ part of '../../models.dart'; /// Token class Token implements Model { - /// Token ID. - final String $id; - - /// Token creation date in ISO 8601 format. - final String $createdAt; - - /// User ID. - final String userId; - - /// Token secret key. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. - final String secret; - - /// Token expiration date in ISO 8601 format. - final String expire; - - /// Security phrase of a token. Empty if security phrase was not requested when creating a token. It includes randomly generated phrase which is also sent in the external resource such as email. - final String phrase; - - Token({ - required this.$id, - required this.$createdAt, - required this.userId, - required this.secret, - required this.expire, - required this.phrase, - }); - - factory Token.fromMap(Map map) { - return Token( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - userId: map['userId'].toString(), - secret: map['secret'].toString(), - expire: map['expire'].toString(), - phrase: map['phrase'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "userId": userId, - "secret": secret, - "expire": expire, - "phrase": phrase, - }; - } + /// Token ID. + final String $id; + /// Token creation date in ISO 8601 format. + final String $createdAt; + /// User ID. + final String userId; + /// Token secret key. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. + final String secret; + /// Token expiration date in ISO 8601 format. + final String expire; + /// Security phrase of a token. Empty if security phrase was not requested when creating a token. It includes randomly generated phrase which is also sent in the external resource such as email. + final String phrase; + + Token({ + required this.$id, + required this.$createdAt, + required this.userId, + required this.secret, + required this.expire, + required this.phrase, + }); + + factory Token.fromMap(Map map) { + return Token( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + userId: map['userId'].toString(), + secret: map['secret'].toString(), + expire: map['expire'].toString(), + phrase: map['phrase'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "userId": userId, + "secret": secret, + "expire": expire, + "phrase": phrase, + }; + } } diff --git a/lib/src/models/topic.dart b/lib/src/models/topic.dart index d7c7168c..bb9ddc3f 100644 --- a/lib/src/models/topic.dart +++ b/lib/src/models/topic.dart @@ -2,64 +2,60 @@ part of '../../models.dart'; /// Topic class Topic implements Model { - /// Topic ID. - final String $id; - - /// Topic creation time in ISO 8601 format. - final String $createdAt; - - /// Topic update date in ISO 8601 format. - final String $updatedAt; - - /// The name of the topic. - final String name; - - /// Total count of email subscribers subscribed to the topic. - final int emailTotal; - - /// Total count of SMS subscribers subscribed to the topic. - final int smsTotal; - - /// Total count of push subscribers subscribed to the topic. - final int pushTotal; - - /// Subscribe permissions. - final List subscribe; - - Topic({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.emailTotal, - required this.smsTotal, - required this.pushTotal, - required this.subscribe, - }); - - factory Topic.fromMap(Map map) { - return Topic( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - emailTotal: map['emailTotal'], - smsTotal: map['smsTotal'], - pushTotal: map['pushTotal'], - subscribe: map['subscribe'] ?? [], - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "emailTotal": emailTotal, - "smsTotal": smsTotal, - "pushTotal": pushTotal, - "subscribe": subscribe, - }; - } + /// Topic ID. + final String $id; + /// Topic creation time in ISO 8601 format. + final String $createdAt; + /// Topic update date in ISO 8601 format. + final String $updatedAt; + /// The name of the topic. + final String name; + /// Total count of email subscribers subscribed to the topic. + final int emailTotal; + /// Total count of SMS subscribers subscribed to the topic. + final int smsTotal; + /// Total count of push subscribers subscribed to the topic. + final int pushTotal; + /// Subscribe permissions. + final List subscribe; + + Topic({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.emailTotal, + required this.smsTotal, + required this.pushTotal, + required this.subscribe, + }); + + factory Topic.fromMap(Map map) { + return Topic( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + emailTotal: (map['emailTotal'] is String) ? + int.tryParse(map['emailTotal']) ?? 0:map['emailTotal'] ?? 0, + smsTotal: (map['smsTotal'] is String) ? + int.tryParse(map['smsTotal']) ?? 0:map['smsTotal'] ?? 0, + pushTotal: (map['pushTotal'] is String) ? + int.tryParse(map['pushTotal']) ?? 0:map['pushTotal'] ?? 0, + subscribe: map['subscribe'] ?? [], + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "emailTotal": emailTotal, + "smsTotal": smsTotal, + "pushTotal": pushTotal, + "subscribe": subscribe, + }; + } } diff --git a/lib/src/models/topic_list.dart b/lib/src/models/topic_list.dart index be78a61f..64e6598f 100644 --- a/lib/src/models/topic_list.dart +++ b/lib/src/models/topic_list.dart @@ -2,28 +2,28 @@ part of '../../models.dart'; /// Topic list class TopicList implements Model { - /// Total number of topics documents that matched your query. - final int total; + /// Total number of topics documents that matched your query. + final int total; + /// List of topics. + final List topics; - /// List of topics. - final List topics; + TopicList({ + required this.total, + required this.topics, + }); - TopicList({ - required this.total, - required this.topics, - }); + factory TopicList.fromMap(Map map) { + return TopicList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + topics: List.from(map['topics'].map((p) => Topic.fromMap(p))), + ); + } - factory TopicList.fromMap(Map map) { - return TopicList( - total: map['total'], - topics: List.from(map['topics'].map((p) => Topic.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "topics": topics.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "topics": topics.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/user.dart b/lib/src/models/user.dart index 889005cf..5937ff55 100644 --- a/lib/src/models/user.dart +++ b/lib/src/models/user.dart @@ -2,130 +2,112 @@ part of '../../models.dart'; /// User class User implements Model { - /// User ID. - final String $id; - - /// User creation date in ISO 8601 format. - final String $createdAt; - - /// User update date in ISO 8601 format. - final String $updatedAt; - - /// User name. - final String name; - - /// Hashed user password. - final String? password; - - /// Password hashing algorithm. - final String? hash; - - /// Password hashing algorithm configuration. - final Map? hashOptions; - - /// User registration date in ISO 8601 format. - final String registration; - - /// User status. Pass `true` for enabled and `false` for disabled. - final bool status; - - /// Labels for the user. - final List labels; - - /// Password update time in ISO 8601 format. - final String passwordUpdate; - - /// User email address. - final String email; - - /// User phone number in E.164 format. - final String phone; - - /// Email verification status. - final bool emailVerification; - - /// Phone verification status. - final bool phoneVerification; - - /// Multi factor authentication status. - final bool mfa; - - /// User preferences as a key-value object - final Preferences prefs; - - /// A user-owned message receiver. A single user may have multiple e.g. emails, phones, and a browser. Each target is registered with a single provider. - final List targets; - - /// Most recent access date in ISO 8601 format. This attribute is only updated again after 24 hours. - final String accessedAt; - - User({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - this.password, - this.hash, - this.hashOptions, - required this.registration, - required this.status, - required this.labels, - required this.passwordUpdate, - required this.email, - required this.phone, - required this.emailVerification, - required this.phoneVerification, - required this.mfa, - required this.prefs, - required this.targets, - required this.accessedAt, - }); - - factory User.fromMap(Map map) { - return User( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - password: map['password']?.toString(), - hash: map['hash']?.toString(), - hashOptions: map['hashOptions'], - registration: map['registration'].toString(), - status: map['status'], - labels: map['labels'] ?? [], - passwordUpdate: map['passwordUpdate'].toString(), - email: map['email'].toString(), - phone: map['phone'].toString(), - emailVerification: map['emailVerification'], - phoneVerification: map['phoneVerification'], - mfa: map['mfa'], - prefs: Preferences.fromMap(map['prefs']), - targets: List.from(map['targets'].map((p) => Target.fromMap(p))), - accessedAt: map['accessedAt'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "password": password, - "hash": hash, - "hashOptions": hashOptions, - "registration": registration, - "status": status, - "labels": labels, - "passwordUpdate": passwordUpdate, - "email": email, - "phone": phone, - "emailVerification": emailVerification, - "phoneVerification": phoneVerification, - "mfa": mfa, - "prefs": prefs.toMap(), - "targets": targets.map((p) => p.toMap()).toList(), - "accessedAt": accessedAt, - }; - } + /// User ID. + final String $id; + /// User creation date in ISO 8601 format. + final String $createdAt; + /// User update date in ISO 8601 format. + final String $updatedAt; + /// User name. + final String name; + /// Hashed user password. + final String? password; + /// Password hashing algorithm. + final String? hash; + /// Password hashing algorithm configuration. + final Map? hashOptions; + /// User registration date in ISO 8601 format. + final String registration; + /// User status. Pass `true` for enabled and `false` for disabled. + final bool status; + /// Labels for the user. + final List labels; + /// Password update time in ISO 8601 format. + final String passwordUpdate; + /// User email address. + final String email; + /// User phone number in E.164 format. + final String phone; + /// Email verification status. + final bool emailVerification; + /// Phone verification status. + final bool phoneVerification; + /// Multi factor authentication status. + final bool mfa; + /// User preferences as a key-value object + final Preferences prefs; + /// A user-owned message receiver. A single user may have multiple e.g. emails, phones, and a browser. Each target is registered with a single provider. + final List targets; + /// Most recent access date in ISO 8601 format. This attribute is only updated again after 24 hours. + final String accessedAt; + + User({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + this.password, + this.hash, + this.hashOptions, + required this.registration, + required this.status, + required this.labels, + required this.passwordUpdate, + required this.email, + required this.phone, + required this.emailVerification, + required this.phoneVerification, + required this.mfa, + required this.prefs, + required this.targets, + required this.accessedAt, + }); + + factory User.fromMap(Map map) { + return User( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + password: map['password']?.toString(), + hash: map['hash']?.toString(), + hashOptions: map['hashOptions'], + registration: map['registration'].toString(), + status: map['status'], + labels: map['labels'] ?? [], + passwordUpdate: map['passwordUpdate'].toString(), + email: map['email'].toString(), + phone: map['phone'].toString(), + emailVerification: map['emailVerification'], + phoneVerification: map['phoneVerification'], + mfa: map['mfa'], + prefs: Preferences.fromMap(map['prefs']), + targets: List.from(map['targets'].map((p) => Target.fromMap(p))), + accessedAt: map['accessedAt'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "password": password, + "hash": hash, + "hashOptions": hashOptions, + "registration": registration, + "status": status, + "labels": labels, + "passwordUpdate": passwordUpdate, + "email": email, + "phone": phone, + "emailVerification": emailVerification, + "phoneVerification": phoneVerification, + "mfa": mfa, + "prefs": prefs.toMap(), + "targets": targets.map((p) => p.toMap()).toList(), + "accessedAt": accessedAt, + }; + } } diff --git a/lib/src/models/user_list.dart b/lib/src/models/user_list.dart index a9a78f63..92d926b0 100644 --- a/lib/src/models/user_list.dart +++ b/lib/src/models/user_list.dart @@ -2,28 +2,28 @@ part of '../../models.dart'; /// Users List class UserList implements Model { - /// Total number of users documents that matched your query. - final int total; + /// Total number of users documents that matched your query. + final int total; + /// List of users. + final List users; - /// List of users. - final List users; + UserList({ + required this.total, + required this.users, + }); - UserList({ - required this.total, - required this.users, - }); + factory UserList.fromMap(Map map) { + return UserList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + users: List.from(map['users'].map((p) => User.fromMap(p))), + ); + } - factory UserList.fromMap(Map map) { - return UserList( - total: map['total'], - users: List.from(map['users'].map((p) => User.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "users": users.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "users": users.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/variable.dart b/lib/src/models/variable.dart index a233010a..83526877 100644 --- a/lib/src/models/variable.dart +++ b/lib/src/models/variable.dart @@ -2,58 +2,52 @@ part of '../../models.dart'; /// Variable class Variable implements Model { - /// Variable ID. - final String $id; - - /// Variable creation date in ISO 8601 format. - final String $createdAt; - - /// Variable creation date in ISO 8601 format. - final String $updatedAt; - - /// Variable key. - final String key; - - /// Variable value. - final String value; - - /// Service to which the variable belongs. Possible values are "project", "function" - final String resourceType; - - /// ID of resource to which the variable belongs. If resourceType is "project", it is empty. If resourceType is "function", it is ID of the function. - final String resourceId; - - Variable({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.key, - required this.value, - required this.resourceType, - required this.resourceId, - }); - - factory Variable.fromMap(Map map) { - return Variable( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - key: map['key'].toString(), - value: map['value'].toString(), - resourceType: map['resourceType'].toString(), - resourceId: map['resourceId'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "key": key, - "value": value, - "resourceType": resourceType, - "resourceId": resourceId, - }; - } + /// Variable ID. + final String $id; + /// Variable creation date in ISO 8601 format. + final String $createdAt; + /// Variable creation date in ISO 8601 format. + final String $updatedAt; + /// Variable key. + final String key; + /// Variable value. + final String value; + /// Service to which the variable belongs. Possible values are "project", "function" + final String resourceType; + /// ID of resource to which the variable belongs. If resourceType is "project", it is empty. If resourceType is "function", it is ID of the function. + final String resourceId; + + Variable({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.key, + required this.value, + required this.resourceType, + required this.resourceId, + }); + + factory Variable.fromMap(Map map) { + return Variable( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + key: map['key'].toString(), + value: map['value'].toString(), + resourceType: map['resourceType'].toString(), + resourceId: map['resourceId'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "key": key, + "value": value, + "resourceType": resourceType, + "resourceId": resourceId, + }; + } } diff --git a/lib/src/models/variable_list.dart b/lib/src/models/variable_list.dart index b2f550a6..6883a928 100644 --- a/lib/src/models/variable_list.dart +++ b/lib/src/models/variable_list.dart @@ -2,29 +2,28 @@ part of '../../models.dart'; /// Variables List class VariableList implements Model { - /// Total number of variables documents that matched your query. - final int total; + /// Total number of variables documents that matched your query. + final int total; + /// List of variables. + final List variables; - /// List of variables. - final List variables; + VariableList({ + required this.total, + required this.variables, + }); - VariableList({ - required this.total, - required this.variables, - }); + factory VariableList.fromMap(Map map) { + return VariableList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + variables: List.from(map['variables'].map((p) => Variable.fromMap(p))), + ); + } - factory VariableList.fromMap(Map map) { - return VariableList( - total: map['total'], - variables: - List.from(map['variables'].map((p) => Variable.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "variables": variables.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "variables": variables.map((p) => p.toMap()).toList(), + }; + } } diff --git a/pubspec.yaml b/pubspec.yaml index 60a75d22..67617bac 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,14 +1,17 @@ name: dart_appwrite -version: 12.1.0 +version: 13.0.0-rc1 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-dart issue_tracker: https://github.com/appwrite/sdk-generator/issues documentation: https://appwrite.io/support environment: - sdk: '>=2.17.0 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: http: '>=0.13.6 <2.0.0' + http_parser: ^4.1.0 + mime: ^1.0.6 + string_scanner: ^1.3.0 dev_dependencies: lints: ^4.0.0 diff --git a/test/services/functions_test.dart b/test/services/functions_test.dart index 31bce002..3eccc76a 100644 --- a/test/services/functions_test.dart +++ b/test/services/functions_test.dart @@ -298,7 +298,7 @@ void main() { final response = await functions.createDeployment( functionId: '', - code: InputFile.fromPath(path: './image.png'), + code: Payload.fromPath(path: './image.png'), activate: true, ); expect(response, isA()); @@ -494,8 +494,12 @@ void main() { 'duration': 0.4,}; - when(client.call( - HttpMethod.post, + when(client.chunkedUpload( + path: argThat(isNotNull), + params: argThat(isNotNull), + paramName: argThat(isNotNull), + idParamName: argThat(isNotNull), + headers: argThat(isNotNull), )).thenAnswer((_) async => Response(data: data)); diff --git a/test/services/storage_test.dart b/test/services/storage_test.dart index c2a81fab..682a8dbc 100644 --- a/test/services/storage_test.dart +++ b/test/services/storage_test.dart @@ -215,7 +215,7 @@ void main() { final response = await storage.createFile( bucketId: '', fileId: '', - file: InputFile.fromPath(path: './image.png'), + file: Payload.fromPath(path: './image.png'), ); expect(response, isA()); diff --git a/test/src/input_file_test.dart b/test/src/input_file_test.dart deleted file mode 100644 index ccbd4387..00000000 --- a/test/src/input_file_test.dart +++ /dev/null @@ -1,47 +0,0 @@ -import 'package:test/test.dart'; -import 'package:dart_appwrite/src/exception.dart'; -import 'package:dart_appwrite/src/input_file.dart'; - -void main() { - group('InputFile', () { - test('throws exception when neither path nor bytes are provided', () { - expect( - () => InputFile(), - throwsA(isA().having( - (e) => e.message, - 'message', - 'One of `path` or `bytes` is required', - )), - ); - }); - - test('throws exception when path and bytes are both null', () { - expect( - () => InputFile(path: null, bytes: null), - throwsA(isA().having( - (e) => e.message, - 'message', - 'One of `path` or `bytes` is required', - )), - ); - }); - - test('creates InputFile from path', () { - final inputFile = InputFile.fromPath(path: '/path/to/file'); - - expect(inputFile.path, '/path/to/file'); - expect(inputFile.filename, isNull); - expect(inputFile.contentType, isNull); - expect(inputFile.bytes, isNull); - }); - - test('creates InputFile from bytes', () { - final inputFile = InputFile.fromBytes(bytes: [1, 2, 3], filename: 'file.txt'); - - expect(inputFile.path, isNull); - expect(inputFile.filename, 'file.txt'); - expect(inputFile.contentType, isNull); - expect(inputFile.bytes, [1, 2, 3]); - }); - }); -} diff --git a/test/src/payload_test.dart b/test/src/payload_test.dart new file mode 100644 index 00000000..9a1b575e --- /dev/null +++ b/test/src/payload_test.dart @@ -0,0 +1,23 @@ +import 'package:test/test.dart'; +import 'package:dart_appwrite/src/exception.dart'; +import 'package:dart_appwrite/payload.dart'; + +void main() { + group('Payload', () { + test('creates Payload from path', () { + final payload = Payload.fromFile(path: '/path/to/file'); + + expect(payload.path, '/path/to/file'); + expect(payload.filename, isNull); + expect(payload.data, isNull); + }); + + test('creates Payload from binary', () { + final payload = Payload.fromBinary(data: [1, 2, 3], filename: 'file.txt'); + + expect(payload.path, isNull); + expect(payload.filename, 'file.txt'); + expect(payload.data, [1, 2, 3]); + }); + }); +} From a2ce8454d30d810da2950730a8b797ab05bc4cbf Mon Sep 17 00:00:00 2001 From: Meldiron Date: Wed, 18 Sep 2024 15:37:33 +0000 Subject: [PATCH 2/7] Commit from GitHub Actions (Format and push) --- lib/client_browser.dart | 2 +- lib/client_io.dart | 2 +- lib/dart_appwrite.dart | 2 +- lib/id.dart | 3 +- lib/payload.dart | 6 +- lib/query.dart | 45 +- lib/role.dart | 106 +- lib/services/account.dart | 2243 ++++++++--------- lib/services/avatars.dart | 404 +-- lib/services/databases.dart | 2367 ++++++++++-------- lib/services/functions.dart | 1263 +++++----- lib/services/graphql.dart | 94 +- lib/services/health.dart | 929 ++++--- lib/services/locale.dart | 270 +- lib/services/messaging.dart | 2619 ++++++++++---------- lib/services/storage.dart | 732 +++--- lib/services/teams.dart | 684 +++-- lib/services/users.dart | 2072 ++++++++-------- lib/src/client.dart | 7 +- lib/src/client_base.dart | 6 +- lib/src/client_browser.dart | 101 +- lib/src/client_io.dart | 101 +- lib/src/client_mixin.dart | 49 +- lib/src/enums/authentication_factor.dart | 18 +- lib/src/enums/authenticator_type.dart | 12 +- lib/src/enums/browser.dart | 38 +- lib/src/enums/compression.dart | 16 +- lib/src/enums/credit_card.dart | 42 +- lib/src/enums/execution_method.dart | 22 +- lib/src/enums/flag.dart | 400 ++- lib/src/enums/image_format.dart | 20 +- lib/src/enums/image_gravity.dart | 28 +- lib/src/enums/index_type.dart | 16 +- lib/src/enums/messaging_provider_type.dart | 16 +- lib/src/enums/name.dart | 34 +- lib/src/enums/o_auth_provider.dart | 88 +- lib/src/enums/password_hash.dart | 32 +- lib/src/enums/relation_mutate.dart | 16 +- lib/src/enums/relationship_type.dart | 18 +- lib/src/enums/runtime.dart | 108 +- lib/src/enums/smtp_encryption.dart | 16 +- lib/src/exception.dart | 2 +- lib/src/models/algo_argon2.dart | 72 +- lib/src/models/algo_bcrypt.dart | 30 +- lib/src/models/algo_md5.dart | 30 +- lib/src/models/algo_phpass.dart | 30 +- lib/src/models/algo_scrypt.dart | 92 +- lib/src/models/algo_scrypt_modified.dart | 63 +- lib/src/models/algo_sha.dart | 30 +- lib/src/models/attribute_boolean.dart | 102 +- lib/src/models/attribute_datetime.dart | 113 +- lib/src/models/attribute_email.dart | 113 +- lib/src/models/attribute_enum.dart | 124 +- lib/src/models/attribute_float.dart | 124 +- lib/src/models/attribute_integer.dart | 123 +- lib/src/models/attribute_ip.dart | 113 +- lib/src/models/attribute_list.dart | 44 +- lib/src/models/attribute_relationship.dart | 151 +- lib/src/models/attribute_string.dart | 116 +- lib/src/models/attribute_url.dart | 113 +- lib/src/models/bucket.dart | 154 +- lib/src/models/bucket_list.dart | 44 +- lib/src/models/build.dart | 124 +- lib/src/models/collection.dart | 129 +- lib/src/models/collection_list.dart | 45 +- lib/src/models/continent.dart | 41 +- lib/src/models/continent_list.dart | 45 +- lib/src/models/country.dart | 41 +- lib/src/models/country_list.dart | 45 +- lib/src/models/currency.dart | 105 +- lib/src/models/currency_list.dart | 45 +- lib/src/models/database.dart | 80 +- lib/src/models/database_list.dart | 45 +- lib/src/models/deployment.dart | 298 ++- lib/src/models/deployment_list.dart | 45 +- lib/src/models/document.dart | 103 +- lib/src/models/document_list.dart | 49 +- lib/src/models/execution.dart | 217 +- lib/src/models/execution_list.dart | 45 +- lib/src/models/file.dart | 149 +- lib/src/models/file_list.dart | 44 +- lib/src/models/function.dart | 292 ++- lib/src/models/function_list.dart | 44 +- lib/src/models/headers.dart | 41 +- lib/src/models/health_antivirus.dart | 41 +- lib/src/models/health_certificate.dart | 91 +- lib/src/models/health_queue.dart | 33 +- lib/src/models/health_status.dart | 55 +- lib/src/models/health_time.dart | 61 +- lib/src/models/identity.dart | 129 +- lib/src/models/identity_list.dart | 45 +- lib/src/models/index.dart | 91 +- lib/src/models/index_list.dart | 44 +- lib/src/models/jwt.dart | 30 +- lib/src/models/language.dart | 52 +- lib/src/models/language_list.dart | 45 +- lib/src/models/locale.dart | 102 +- lib/src/models/locale_code.dart | 41 +- lib/src/models/locale_code_list.dart | 45 +- lib/src/models/log.dart | 256 +- lib/src/models/log_list.dart | 44 +- lib/src/models/membership.dart | 168 +- lib/src/models/membership_list.dart | 45 +- lib/src/models/message.dart | 171 +- lib/src/models/message_list.dart | 45 +- lib/src/models/mfa_challenge.dart | 63 +- lib/src/models/mfa_factors.dart | 63 +- lib/src/models/mfa_recovery_codes.dart | 30 +- lib/src/models/mfa_type.dart | 41 +- lib/src/models/model.dart | 2 +- lib/src/models/phone.dart | 52 +- lib/src/models/phone_list.dart | 44 +- lib/src/models/preferences.dart | 30 +- lib/src/models/provider.dart | 124 +- lib/src/models/provider_list.dart | 45 +- lib/src/models/runtime.dart | 113 +- lib/src/models/runtime_list.dart | 45 +- lib/src/models/session.dart | 344 +-- lib/src/models/session_list.dart | 45 +- lib/src/models/specification.dart | 66 +- lib/src/models/specification_list.dart | 45 +- lib/src/models/subscriber.dart | 124 +- lib/src/models/subscriber_list.dart | 45 +- lib/src/models/target.dart | 113 +- lib/src/models/target_list.dart | 44 +- lib/src/models/team.dart | 94 +- lib/src/models/team_list.dart | 44 +- lib/src/models/token.dart | 91 +- lib/src/models/topic.dart | 122 +- lib/src/models/topic_list.dart | 44 +- lib/src/models/user.dart | 234 +- lib/src/models/user_list.dart | 44 +- lib/src/models/variable.dart | 102 +- lib/src/models/variable_list.dart | 45 +- 134 files changed, 11725 insertions(+), 11109 deletions(-) diff --git a/lib/client_browser.dart b/lib/client_browser.dart index 09f110ea..b9805a3a 100644 --- a/lib/client_browser.dart +++ b/lib/client_browser.dart @@ -1 +1 @@ -export 'src/client_browser.dart'; \ No newline at end of file +export 'src/client_browser.dart'; diff --git a/lib/client_io.dart b/lib/client_io.dart index 4d85cbfa..42a0c0b6 100644 --- a/lib/client_io.dart +++ b/lib/client_io.dart @@ -1 +1 @@ -export 'src/client_io.dart'; \ No newline at end of file +export 'src/client_io.dart'; diff --git a/lib/dart_appwrite.dart b/lib/dart_appwrite.dart index 659eb962..6e1a5f10 100644 --- a/lib/dart_appwrite.dart +++ b/lib/dart_appwrite.dart @@ -1,6 +1,6 @@ /// Appwrite Dart SDK /// -/// This SDK is compatible with Appwrite server version 1.6.x. +/// This SDK is compatible with Appwrite server version 1.6.x. /// For older versions, please check /// [previous releases](https://github.com/appwrite/sdk-for-dart/releases). library dart_appwrite; diff --git a/lib/id.dart b/lib/id.dart index 72e26a23..28ff15e8 100644 --- a/lib/id.dart +++ b/lib/id.dart @@ -10,8 +10,7 @@ class ID { final now = DateTime.now(); final sec = (now.millisecondsSinceEpoch / 1000).floor(); final usec = now.microsecondsSinceEpoch - (sec * 1000000); - return sec.toRadixString(16) + - usec.toRadixString(16).padLeft(5, '0'); + return sec.toRadixString(16) + usec.toRadixString(16).padLeft(5, '0'); } // Generate a unique ID with padding to have a longer ID diff --git a/lib/payload.dart b/lib/payload.dart index 5dc144c9..fec52b0d 100644 --- a/lib/payload.dart +++ b/lib/payload.dart @@ -14,10 +14,10 @@ class Payload { /// Convert to binary, with optional offset and length List toBinary({int offset = 0, int? length}) { - if(data == null) { + if (data == null) { throw AppwriteException('`data` is not defined.'); } - if(offset == 0 && length == null) { + if (offset == 0 && length == null) { return data!; } else if (length == null) { return data!.sublist(offset); @@ -29,7 +29,7 @@ class Payload { /// Convert binary data to string (utf8) @override String toString() { - if(data == null) { + if (data == null) { return ''; } return utf8.decode(data!); diff --git a/lib/query.dart b/lib/query.dart index 46882207..6b8ed94f 100644 --- a/lib/query.dart +++ b/lib/query.dart @@ -1,6 +1,5 @@ part of 'dart_appwrite.dart'; - /// Helper class to generate query strings. class Query { final String method; @@ -14,11 +13,11 @@ class Query { 'method': method, }; - if(attribute != null) { + if (attribute != null) { map['attribute'] = attribute; } - - if(values != null) { + + if (values != null) { map['values'] = values is List ? values : [values]; } @@ -29,7 +28,7 @@ class Query { String toString() => jsonEncode(toJson()); /// Filter resources where [attribute] is equal to [value]. - /// + /// /// [value] can be a single value or a list. If a list is used /// the query will return resources where [attribute] is equal /// to any of the values in the list. @@ -61,10 +60,12 @@ class Query { Query._('search', attribute, value).toString(); /// Filter resources where [attribute] is null. - static String isNull(String attribute) => Query._('isNull', attribute).toString(); + static String isNull(String attribute) => + Query._('isNull', attribute).toString(); /// Filter resources where [attribute] is not null. - static String isNotNull(String attribute) => Query._('isNotNull', attribute).toString(); + static String isNotNull(String attribute) => + Query._('isNotNull', attribute).toString(); /// Filter resources where [attribute] is between [start] and [end] (inclusive). static String between(String attribute, dynamic start, dynamic end) => @@ -84,40 +85,46 @@ class Query { Query._('contains', attribute, value).toString(); static String or(List queries) => - Query._('or', null, queries.map((query) => jsonDecode(query)).toList()).toString(); + Query._('or', null, queries.map((query) => jsonDecode(query)).toList()) + .toString(); static String and(List queries) => - Query._('and', null, queries.map((query) => jsonDecode(query)).toList()).toString(); + Query._('and', null, queries.map((query) => jsonDecode(query)).toList()) + .toString(); /// Specify which attributes should be returned by the API call. static String select(List attributes) => Query._('select', null, attributes).toString(); /// Sort results by [attribute] ascending. - static String orderAsc(String attribute) => Query._('orderAsc', attribute).toString(); + static String orderAsc(String attribute) => + Query._('orderAsc', attribute).toString(); /// Sort results by [attribute] descending. - static String orderDesc(String attribute) => Query._('orderDesc', attribute).toString(); + static String orderDesc(String attribute) => + Query._('orderDesc', attribute).toString(); /// Return results before [id]. - /// + /// /// Refer to the [Cursor Based Pagination](https://appwrite.io/docs/pagination#cursor-pagination) /// docs for more information. - static String cursorBefore(String id) => Query._('cursorBefore', null, id).toString(); + static String cursorBefore(String id) => + Query._('cursorBefore', null, id).toString(); /// Return results after [id]. - /// + /// /// Refer to the [Cursor Based Pagination](https://appwrite.io/docs/pagination#cursor-pagination) /// docs for more information. - static String cursorAfter(String id) => Query._('cursorAfter', null, id).toString(); + static String cursorAfter(String id) => + Query._('cursorAfter', null, id).toString(); /// Return only [limit] results. static String limit(int limit) => Query._('limit', null, limit).toString(); /// Return results from [offset]. - /// + /// /// Refer to the [Offset Pagination](https://appwrite.io/docs/pagination#offset-pagination) /// docs for more information. - static String offset(int offset) => Query._('offset', null, offset).toString(); - -} \ No newline at end of file + static String offset(int offset) => + Query._('offset', null, offset).toString(); +} diff --git a/lib/role.dart b/lib/role.dart index 6552df47..dafeb78d 100644 --- a/lib/role.dart +++ b/lib/role.dart @@ -2,65 +2,65 @@ part of 'dart_appwrite.dart'; /// Helper class to generate role strings for [Permission]. class Role { - Role._(); - - /// Grants access to anyone. - /// - /// This includes authenticated and unauthenticated users. - static String any() { - return 'any'; - } + Role._(); - /// Grants access to a specific user by user ID. - /// - /// You can optionally pass verified or unverified for - /// [status] to target specific types of users. - static String user(String id, [String status = '']) { - if(status.isEmpty) { - return 'user:$id'; - } - return 'user:$id/$status'; - } + /// Grants access to anyone. + /// + /// This includes authenticated and unauthenticated users. + static String any() { + return 'any'; + } - /// Grants access to any authenticated or anonymous user. - /// - /// You can optionally pass verified or unverified for - /// [status] to target specific types of users. - static String users([String status = '']) { - if(status.isEmpty) { - return 'users'; - } - return 'users/$status'; + /// Grants access to a specific user by user ID. + /// + /// You can optionally pass verified or unverified for + /// [status] to target specific types of users. + static String user(String id, [String status = '']) { + if (status.isEmpty) { + return 'user:$id'; } + return 'user:$id/$status'; + } - /// Grants access to any guest user without a session. - /// - /// Authenticated users don't have access to this role. - static String guests() { - return 'guests'; + /// Grants access to any authenticated or anonymous user. + /// + /// You can optionally pass verified or unverified for + /// [status] to target specific types of users. + static String users([String status = '']) { + if (status.isEmpty) { + return 'users'; } + return 'users/$status'; + } - /// Grants access to a team by team ID. - /// - /// You can optionally pass a role for [role] to target - /// team members with the specified role. - static String team(String id, [String role = '']) { - if(role.isEmpty) { - return 'team:$id'; - } - return 'team:$id/$role'; - } + /// Grants access to any guest user without a session. + /// + /// Authenticated users don't have access to this role. + static String guests() { + return 'guests'; + } - /// Grants access to a specific member of a team. - /// - /// When the member is removed from the team, they will - /// no longer have access. - static String member(String id) { - return 'member:$id'; + /// Grants access to a team by team ID. + /// + /// You can optionally pass a role for [role] to target + /// team members with the specified role. + static String team(String id, [String role = '']) { + if (role.isEmpty) { + return 'team:$id'; } + return 'team:$id/$role'; + } - /// Grants access to a user with the specified label. - static String label(String name) { - return 'label:$name'; - } -} \ No newline at end of file + /// Grants access to a specific member of a team. + /// + /// When the member is removed from the team, they will + /// no longer have access. + static String member(String id) { + return 'member:$id'; + } + + /// Grants access to a user with the specified label. + static String label(String name) { + return 'label:$name'; + } +} diff --git a/lib/services/account.dart b/lib/services/account.dart index 93c16e2d..6e4936cd 100644 --- a/lib/services/account.dart +++ b/lib/services/account.dart @@ -2,1177 +2,1072 @@ part of '../dart_appwrite.dart'; /// The Account service allows you to authenticate and manage a user account. class Account extends Service { - Account(super.client); - - /// Get account - /// - /// Get the currently logged in user. - Future get() async { - final String apiPath = '/account'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.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](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession). - Future create({required String userId, required String email, required String password, String? name}) async { - final String apiPath = '/account'; - - final Map apiParams = { - - 'userId': userId, -'email': email, -'password': password, -'name': name, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Update 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 { - final String apiPath = '/account/email'; - - final Map apiParams = { - - 'email': email, -'password': password, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// List Identities - /// - /// Get the list of identities for the currently logged in user. - Future listIdentities({List? queries}) async { - final String apiPath = '/account/identities'; - - final Map apiParams = { - 'queries': queries, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.IdentityList.fromMap(res.data); - - } - - /// Delete identity - /// - /// Delete an identity by its unique ID. - Future deleteIdentity({required String identityId}) async { - final String apiPath = '/account/identities/{identityId}'.replaceAll('{identityId}', identityId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Create 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 { - final String apiPath = '/account/jwts'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Jwt.fromMap(res.data); - - } - - /// List logs - /// - /// Get the list of latest security activity logs for the currently logged in - /// user. Each log returns user IP address, location and date and time of log. - Future listLogs({List? queries}) async { - final String apiPath = '/account/logs'; - - final Map apiParams = { - 'queries': queries, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - - } - - /// Update MFA - /// - /// Enable or disable MFA on an account. - Future updateMFA({required bool mfa}) async { - final String apiPath = '/account/mfa'; - - final Map apiParams = { - - 'mfa': mfa, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create Authenticator - /// - /// Add an authenticator app to be used as an MFA factor. Verify the - /// authenticator using the [verify - /// authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) - /// method. - Future createMfaAuthenticator({required enums.AuthenticatorType type}) async { - final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaType.fromMap(res.data); - - } - - /// Verify Authenticator - /// - /// Verify an authenticator app after adding it using the [add - /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) - /// method. - Future updateMfaAuthenticator({required enums.AuthenticatorType type, required String otp}) async { - final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); - - final Map apiParams = { - - 'otp': otp, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Delete Authenticator - /// - /// Delete an authenticator for a user by ID. - Future deleteMfaAuthenticator({required enums.AuthenticatorType type}) async { - final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Create MFA Challenge - /// - /// Begin the process of MFA verification after sign-in. Finish the flow with - /// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) - /// method. - Future createMfaChallenge({required enums.AuthenticationFactor factor}) async { - final String apiPath = '/account/mfa/challenge'; - - final Map apiParams = { - - 'factor': factor.value, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaChallenge.fromMap(res.data); - - } - - /// Create MFA Challenge (confirmation) - /// - /// Complete the MFA challenge by providing the one-time password. Finish the - /// process of MFA verification by providing the one-time password. To begin - /// the flow, use - /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) - /// method. - Future updateMfaChallenge({required String challengeId, required String otp}) async { - final String apiPath = '/account/mfa/challenge'; - - final Map apiParams = { - - 'challengeId': challengeId, -'otp': otp, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List Factors - /// - /// List the factors available on the account to be used as a MFA challange. - Future listMfaFactors() async { - final String apiPath = '/account/mfa/factors'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaFactors.fromMap(res.data); - - } - - /// Get MFA Recovery Codes - /// - /// Get recovery codes that can be used as backup for MFA flow. Before getting - /// codes, they must be generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. An OTP challenge is required to read recovery codes. - Future getMfaRecoveryCodes() async { - final String apiPath = '/account/mfa/recovery-codes'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - - } - - /// Create MFA Recovery Codes - /// - /// Generate recovery codes as backup for MFA flow. It's recommended to - /// generate and show then immediately after user successfully adds their - /// authehticator. Recovery codes can be used as a MFA verification type in - /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) - /// method. - Future createMfaRecoveryCodes() async { - final String apiPath = '/account/mfa/recovery-codes'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - - } - - /// Regenerate MFA Recovery Codes - /// - /// Regenerate recovery codes that can be used as backup for MFA flow. Before - /// regenerating codes, they must be first generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. An OTP challenge is required to regenreate recovery codes. - Future updateMfaRecoveryCodes() async { - final String apiPath = '/account/mfa/recovery-codes'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - - } - - /// Update name - /// - /// Update currently logged in user account name. - Future updateName({required String name}) async { - final String apiPath = '/account/name'; - - final Map apiParams = { - - 'name': name, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Update 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 { - final String apiPath = '/account/password'; - - final Map apiParams = { - - 'password': password, -'oldPassword': oldPassword, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Update 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](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification) - /// endpoint to send a confirmation SMS. - Future updatePhone({required String phone, required String password}) async { - final String apiPath = '/account/phone'; - - final Map apiParams = { - - 'phone': phone, -'password': password, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Get account preferences - /// - /// Get the preferences as a key-value object for the currently logged in user. - Future getPrefs() async { - final String apiPath = '/account/prefs'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - - } - - /// Update 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 { - final String apiPath = '/account/prefs'; - - final Map apiParams = { - - 'prefs': prefs, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery) - /// 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 { - final String apiPath = '/account/recovery'; - - final Map apiParams = { - - 'email': email, -'url': url, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// Create 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](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery) - /// 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}) async { - final String apiPath = '/account/recovery'; - - final Map apiParams = { - - 'userId': userId, -'secret': secret, -'password': password, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// List sessions - /// - /// Get the list of active sessions across different devices for the currently - /// logged in user. - Future listSessions() async { - final String apiPath = '/account/sessions'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SessionList.fromMap(res.data); - - } - - /// Delete sessions - /// - /// Delete all sessions from the user account and remove any sessions cookies - /// from the end client. - Future deleteSessions() async { - final String apiPath = '/account/sessions'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Create 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](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail) - /// or create an [OAuth2 - /// session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session). - Future createAnonymousSession() async { - final String apiPath = '/account/sessions/anonymous'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - - } - - /// Create email password session - /// - /// Allow the user to login into their account by providing a valid email and - /// password combination. This route will create a new session for the user. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future createEmailPasswordSession({required String email, required String password}) async { - final String apiPath = '/account/sessions/email'; - - final Map apiParams = { - - 'email': email, -'password': password, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - - } - - /// Update magic URL session - /// - /// Use this endpoint to create a session from token. Provide the **userId** - /// and **secret** parameters from the successful response of authentication - /// flows initiated by token creation. For example, magic URL and phone login. - Future updateMagicURLSession({required String userId, required String secret}) async { - final String apiPath = '/account/sessions/magic-url'; - - final Map apiParams = { - - 'userId': userId, -'secret': secret, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - - } - - /// Update phone session - /// - /// Use this endpoint to create a session from token. Provide the **userId** - /// and **secret** parameters from the successful response of authentication - /// flows initiated by token creation. For example, magic URL and phone login. - Future updatePhoneSession({required String userId, required String secret}) async { - final String apiPath = '/account/sessions/phone'; - - final Map apiParams = { - - 'userId': userId, -'secret': secret, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - - } - - /// Create session - /// - /// Use this endpoint to create a session from token. Provide the **userId** - /// and **secret** parameters from the successful response of authentication - /// flows initiated by token creation. For example, magic URL and phone login. - Future createSession({required String userId, required String secret}) async { - final String apiPath = '/account/sessions/token'; - - final Map apiParams = { - - 'userId': userId, -'secret': secret, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - - } - - /// Get session - /// - /// 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 apiPath = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - - } - - /// Update session - /// - /// Use this endpoint to extend a session's length. Extending a session is - /// useful when session expiry is short. If the session was created using an - /// OAuth provider, this endpoint refreshes the access token from the provider. - Future updateSession({required String sessionId}) async { - final String apiPath = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - - } - - /// Delete session - /// - /// Logout the user. Use 'current' as the session ID to logout on this device, - /// use a session ID to logout on another device. If you're looking to logout - /// the user on all devices, use [Delete - /// Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions) - /// instead. - Future deleteSession({required String sessionId}) async { - final String apiPath = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Update 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 { - final String apiPath = '/account/status'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create email token (OTP) - /// - /// Sends the user an email with a secret key for creating a session. If the - /// provided user ID has not be registered, a new user will be created. Use the - /// returned user ID and secret and submit a request to the [POST - /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. The secret sent to the user's email - /// is valid for 15 minutes. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future createEmailToken({required String userId, required String email, bool? phrase}) async { - final String apiPath = '/account/tokens/email'; - - final Map apiParams = { - - 'userId': userId, -'email': email, -'phrase': phrase, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// Create magic URL token - /// - /// Sends the user an email with a secret key for creating a session. If the - /// provided user ID has not been registered, a new user will be created. When - /// the user clicks the link in the email, the user is redirected back to the - /// URL you provided with the secret key and userId values attached to the URL - /// query string. Use the query string parameters to submit a request to the - /// [POST - /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. The link sent to the user's email - /// address is valid for 1 hour. If you are on a mobile device you can leave - /// the URL parameter empty, so that the login completion will be handled by - /// your Appwrite instance by default. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - /// - Future createMagicURLToken({required String userId, required String email, String? url, bool? phrase}) async { - final String apiPath = '/account/tokens/magic-url'; - - final Map apiParams = { - - 'userId': userId, -'email': email, -'url': url, -'phrase': phrase, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// Create OAuth2 token - /// - /// Allow the user to login to their account using the OAuth2 provider of their - /// choice. Each OAuth2 provider should be enabled from the Appwrite console - /// first. Use the success and failure arguments to provide a redirect URL's - /// back to your app when login is completed. - /// - /// If authentication succeeds, `userId` and `secret` of a token will be - /// appended to the success URL as query parameters. These can be used to - /// create a new session using the [Create - /// session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future createOAuth2Token({required enums.OAuthProvider provider, String? success, String? failure, List? scopes}) async { - final String apiPath = '/account/tokens/oauth2/{provider}'.replaceAll('{provider}', provider.value); - - final Map params = { - 'success': success, -'failure': failure, -'scopes': scopes, - - - 'project': client.config['project'], - }; - - final List query = []; - - params.forEach((key, value) { - if (value is List) { - for (var item in value) { - query.add(Uri.encodeComponent(key + '[]') + '=' + Uri.encodeComponent(item)); - } - } else if(value != null) { - query.add(Uri.encodeComponent(key) + '=' + Uri.encodeComponent(value)); - } - }); - - Uri endpoint = Uri.parse(client.endPoint); - Uri url = Uri(scheme: endpoint.scheme, - host: endpoint.host, - port: endpoint.port, - path: endpoint.path + apiPath, - query: query.join('&') - ); - - return client.webAuth(url); - } - - /// Create phone token - /// - /// Sends the user an SMS with a secret key for creating a session. If the - /// provided user ID has not be registered, a new user will be created. Use the - /// returned user ID and secret and submit a request to the [POST - /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. The secret sent to the user's phone - /// is valid for 15 minutes. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future createPhoneToken({required String userId, required String phone}) async { - final String apiPath = '/account/tokens/phone'; - - final Map apiParams = { - - 'userId': userId, -'phone': phone, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// Create email verification - /// - /// Use this endpoint to send a verification message to your user email address - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). - /// 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 { - final String apiPath = '/account/verification'; - - final Map apiParams = { - - 'url': url, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// Create 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 { - final String apiPath = '/account/verification'; - - final Map apiParams = { - - 'userId': userId, -'secret': secret, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone) - /// endpoint. Learn more about how to [complete the verification - /// process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification). - /// The verification code sent to the user's phone number is valid for 15 - /// minutes. - Future createPhoneVerification() async { - final String apiPath = '/account/verification/phone'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// Update 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 { - final String apiPath = '/account/verification/phone'; - - final Map apiParams = { - - 'userId': userId, -'secret': secret, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } -} \ No newline at end of file + Account(super.client); + + /// Get account + /// + /// Get the currently logged in user. + Future get() async { + final String apiPath = '/account'; + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.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](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession). + Future create( + {required String userId, + required String email, + required String password, + String? name}) async { + final String apiPath = '/account'; + + final Map apiParams = { + 'userId': userId, + 'email': email, + 'password': password, + 'name': name, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Update 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 { + final String apiPath = '/account/email'; + + final Map apiParams = { + 'email': email, + 'password': password, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// List Identities + /// + /// Get the list of identities for the currently logged in user. + Future listIdentities({List? queries}) async { + final String apiPath = '/account/identities'; + + final Map apiParams = { + 'queries': queries, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.IdentityList.fromMap(res.data); + } + + /// Delete identity + /// + /// Delete an identity by its unique ID. + Future deleteIdentity({required String identityId}) async { + final String apiPath = '/account/identities/{identityId}' + .replaceAll('{identityId}', identityId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Create 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 { + final String apiPath = '/account/jwts'; + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Jwt.fromMap(res.data); + } + + /// List logs + /// + /// Get the list of latest security activity logs for the currently logged in + /// user. Each log returns user IP address, location and date and time of log. + Future listLogs({List? queries}) async { + final String apiPath = '/account/logs'; + + final Map apiParams = { + 'queries': queries, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + } + + /// Update MFA + /// + /// Enable or disable MFA on an account. + Future updateMFA({required bool mfa}) async { + final String apiPath = '/account/mfa'; + + final Map apiParams = { + 'mfa': mfa, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create Authenticator + /// + /// Add an authenticator app to be used as an MFA factor. Verify the + /// authenticator using the [verify + /// authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) + /// method. + Future createMfaAuthenticator( + {required enums.AuthenticatorType type}) async { + final String apiPath = + '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaType.fromMap(res.data); + } + + /// Verify Authenticator + /// + /// Verify an authenticator app after adding it using the [add + /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) + /// method. + Future updateMfaAuthenticator( + {required enums.AuthenticatorType type, required String otp}) async { + final String apiPath = + '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map apiParams = { + 'otp': otp, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Delete Authenticator + /// + /// Delete an authenticator for a user by ID. + Future deleteMfaAuthenticator({required enums.AuthenticatorType type}) async { + final String apiPath = + '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Create MFA Challenge + /// + /// Begin the process of MFA verification after sign-in. Finish the flow with + /// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) + /// method. + Future createMfaChallenge( + {required enums.AuthenticationFactor factor}) async { + final String apiPath = '/account/mfa/challenge'; + + final Map apiParams = { + 'factor': factor.value, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaChallenge.fromMap(res.data); + } + + /// Create MFA Challenge (confirmation) + /// + /// Complete the MFA challenge by providing the one-time password. Finish the + /// process of MFA verification by providing the one-time password. To begin + /// the flow, use + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method. + Future updateMfaChallenge( + {required String challengeId, required String otp}) async { + final String apiPath = '/account/mfa/challenge'; + + final Map apiParams = { + 'challengeId': challengeId, + 'otp': otp, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List Factors + /// + /// List the factors available on the account to be used as a MFA challange. + Future listMfaFactors() async { + final String apiPath = '/account/mfa/factors'; + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaFactors.fromMap(res.data); + } + + /// Get MFA Recovery Codes + /// + /// Get recovery codes that can be used as backup for MFA flow. Before getting + /// codes, they must be generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. An OTP challenge is required to read recovery codes. + Future getMfaRecoveryCodes() async { + final String apiPath = '/account/mfa/recovery-codes'; + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + } + + /// Create MFA Recovery Codes + /// + /// Generate recovery codes as backup for MFA flow. It's recommended to + /// generate and show then immediately after user successfully adds their + /// authehticator. Recovery codes can be used as a MFA verification type in + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method. + Future createMfaRecoveryCodes() async { + final String apiPath = '/account/mfa/recovery-codes'; + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + } + + /// Regenerate MFA Recovery Codes + /// + /// Regenerate recovery codes that can be used as backup for MFA flow. Before + /// regenerating codes, they must be first generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. An OTP challenge is required to regenreate recovery codes. + Future updateMfaRecoveryCodes() async { + final String apiPath = '/account/mfa/recovery-codes'; + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + } + + /// Update name + /// + /// Update currently logged in user account name. + Future updateName({required String name}) async { + final String apiPath = '/account/name'; + + final Map apiParams = { + 'name': name, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Update 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 { + final String apiPath = '/account/password'; + + final Map apiParams = { + 'password': password, + 'oldPassword': oldPassword, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Update 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](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification) + /// endpoint to send a confirmation SMS. + Future updatePhone( + {required String phone, required String password}) async { + final String apiPath = '/account/phone'; + + final Map apiParams = { + 'phone': phone, + 'password': password, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Get account preferences + /// + /// Get the preferences as a key-value object for the currently logged in user. + Future getPrefs() async { + final String apiPath = '/account/prefs'; + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + } + + /// Update 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 { + final String apiPath = '/account/prefs'; + + final Map apiParams = { + 'prefs': prefs, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery) + /// 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 { + final String apiPath = '/account/recovery'; + + final Map apiParams = { + 'email': email, + 'url': url, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// Create 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](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery) + /// 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}) async { + final String apiPath = '/account/recovery'; + + final Map apiParams = { + 'userId': userId, + 'secret': secret, + 'password': password, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// List sessions + /// + /// Get the list of active sessions across different devices for the currently + /// logged in user. + Future listSessions() async { + final String apiPath = '/account/sessions'; + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SessionList.fromMap(res.data); + } + + /// Delete sessions + /// + /// Delete all sessions from the user account and remove any sessions cookies + /// from the end client. + Future deleteSessions() async { + final String apiPath = '/account/sessions'; + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Create 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](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail) + /// or create an [OAuth2 + /// session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session). + Future createAnonymousSession() async { + final String apiPath = '/account/sessions/anonymous'; + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + } + + /// Create email password session + /// + /// Allow the user to login into their account by providing a valid email and + /// password combination. This route will create a new session for the user. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future createEmailPasswordSession( + {required String email, required String password}) async { + final String apiPath = '/account/sessions/email'; + + final Map apiParams = { + 'email': email, + 'password': password, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + } + + /// Update magic URL session + /// + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. + Future updateMagicURLSession( + {required String userId, required String secret}) async { + final String apiPath = '/account/sessions/magic-url'; + + final Map apiParams = { + 'userId': userId, + 'secret': secret, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + } + + /// Update phone session + /// + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. + Future updatePhoneSession( + {required String userId, required String secret}) async { + final String apiPath = '/account/sessions/phone'; + + final Map apiParams = { + 'userId': userId, + 'secret': secret, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + } + + /// Create session + /// + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. + Future createSession( + {required String userId, required String secret}) async { + final String apiPath = '/account/sessions/token'; + + final Map apiParams = { + 'userId': userId, + 'secret': secret, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + } + + /// Get session + /// + /// 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 apiPath = + '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + } + + /// Update session + /// + /// Use this endpoint to extend a session's length. Extending a session is + /// useful when session expiry is short. If the session was created using an + /// OAuth provider, this endpoint refreshes the access token from the provider. + Future updateSession({required String sessionId}) async { + final String apiPath = + '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + } + + /// Delete session + /// + /// Logout the user. Use 'current' as the session ID to logout on this device, + /// use a session ID to logout on another device. If you're looking to logout + /// the user on all devices, use [Delete + /// Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions) + /// instead. + Future deleteSession({required String sessionId}) async { + final String apiPath = + '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Update 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 { + final String apiPath = '/account/status'; + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create email token (OTP) + /// + /// Sends the user an email with a secret key for creating a session. If the + /// provided user ID has not be registered, a new user will be created. Use the + /// returned user ID and secret and submit a request to the [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The secret sent to the user's email + /// is valid for 15 minutes. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future createEmailToken( + {required String userId, required String email, bool? phrase}) async { + final String apiPath = '/account/tokens/email'; + + final Map apiParams = { + 'userId': userId, + 'email': email, + 'phrase': phrase, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// Create magic URL token + /// + /// Sends the user an email with a secret key for creating a session. If the + /// provided user ID has not been registered, a new user will be created. When + /// the user clicks the link in the email, the user is redirected back to the + /// URL you provided with the secret key and userId values attached to the URL + /// query string. Use the query string parameters to submit a request to the + /// [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The link sent to the user's email + /// address is valid for 1 hour. If you are on a mobile device you can leave + /// the URL parameter empty, so that the login completion will be handled by + /// your Appwrite instance by default. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + /// + Future createMagicURLToken( + {required String userId, + required String email, + String? url, + bool? phrase}) async { + final String apiPath = '/account/tokens/magic-url'; + + final Map apiParams = { + 'userId': userId, + 'email': email, + 'url': url, + 'phrase': phrase, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// Create OAuth2 token + /// + /// Allow the user to login to their account using the OAuth2 provider of their + /// choice. Each OAuth2 provider should be enabled from the Appwrite console + /// first. Use the success and failure arguments to provide a redirect URL's + /// back to your app when login is completed. + /// + /// If authentication succeeds, `userId` and `secret` of a token will be + /// appended to the success URL as query parameters. These can be used to + /// create a new session using the [Create + /// session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future createOAuth2Token( + {required enums.OAuthProvider provider, + String? success, + String? failure, + List? scopes}) async { + final String apiPath = '/account/tokens/oauth2/{provider}' + .replaceAll('{provider}', provider.value); + + final Map params = { + 'success': success, + 'failure': failure, + 'scopes': scopes, + 'project': client.config['project'], + }; + + final List query = []; + + params.forEach((key, value) { + if (value is List) { + for (var item in value) { + query.add(Uri.encodeComponent(key + '[]') + + '=' + + Uri.encodeComponent(item)); + } + } else if (value != null) { + query.add(Uri.encodeComponent(key) + '=' + Uri.encodeComponent(value)); + } + }); + + Uri endpoint = Uri.parse(client.endPoint); + Uri url = Uri( + scheme: endpoint.scheme, + host: endpoint.host, + port: endpoint.port, + path: endpoint.path + apiPath, + query: query.join('&')); + + return client.webAuth(url); + } + + /// Create phone token + /// + /// Sends the user an SMS with a secret key for creating a session. If the + /// provided user ID has not be registered, a new user will be created. Use the + /// returned user ID and secret and submit a request to the [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The secret sent to the user's phone + /// is valid for 15 minutes. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future createPhoneToken( + {required String userId, required String phone}) async { + final String apiPath = '/account/tokens/phone'; + + final Map apiParams = { + 'userId': userId, + 'phone': phone, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// Create email verification + /// + /// Use this endpoint to send a verification message to your user email address + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). + /// 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 { + final String apiPath = '/account/verification'; + + final Map apiParams = { + 'url': url, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// Create 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 { + final String apiPath = '/account/verification'; + + final Map apiParams = { + 'userId': userId, + 'secret': secret, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone) + /// endpoint. Learn more about how to [complete the verification + /// process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification). + /// The verification code sent to the user's phone number is valid for 15 + /// minutes. + Future createPhoneVerification() async { + final String apiPath = '/account/verification/phone'; + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// Update 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 { + final String apiPath = '/account/verification/phone'; + + final Map apiParams = { + 'userId': userId, + 'secret': secret, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } +} diff --git a/lib/services/avatars.dart b/lib/services/avatars.dart index 4609b00b..9c77eda6 100644 --- a/lib/services/avatars.dart +++ b/lib/services/avatars.dart @@ -3,201 +3,209 @@ part of '../dart_appwrite.dart'; /// The Avatars service aims to help you complete everyday tasks related to /// your app image, icons, and avatars. class Avatars extends Service { - Avatars(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](https://appwrite.io/docs/references/cloud/client-web/account#getSessions) - /// 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 enums.Browser code, int? width, int? height, int? quality}) async { - final String apiPath = '/avatars/browsers/{code}'.replaceAll('{code}', code.value); - - final Map params = { - 'width': width, -'height': height, -'quality': quality, - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, 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 enums.CreditCard code, int? width, int? height, int? quality}) async { - final String apiPath = '/avatars/credit-cards/{code}'.replaceAll('{code}', code.value); - - final Map params = { - 'width': width, -'height': height, -'quality': quality, - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, 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. - /// - /// This endpoint does not follow HTTP redirects. - Future getFavicon({required String url}) async { - final String apiPath = '/avatars/favicon'; - - final Map params = { - 'url': url, - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, 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. Country codes - /// follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard. - /// - /// 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 enums.Flag code, int? width, int? height, int? quality}) async { - final String apiPath = '/avatars/flags/{code}'.replaceAll('{code}', code.value); - - final Map params = { - 'width': width, -'height': height, -'quality': quality, - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, 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. - /// - /// This endpoint does not follow HTTP redirects. - Future getImage({required String url, int? width, int? height}) async { - final String apiPath = '/avatars/image'; - - final Map params = { - 'url': url, -'width': width, -'height': height, - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, 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? background}) async { - final String apiPath = '/avatars/initials'; - - final Map params = { - 'name': name, -'width': width, -'height': height, -'background': background, - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, 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 { - final String apiPath = '/avatars/qr'; - - final Map params = { - 'text': text, -'size': size, -'margin': margin, -'download': download, - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: params, responseType: ResponseType.bytes); - return res.data; - } -} \ No newline at end of file + Avatars(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](https://appwrite.io/docs/references/cloud/client-web/account#getSessions) + /// 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 enums.Browser code, + int? width, + int? height, + int? quality}) async { + final String apiPath = + '/avatars/browsers/{code}'.replaceAll('{code}', code.value); + + final Map params = { + 'width': width, + 'height': height, + 'quality': quality, + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, 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 enums.CreditCard code, + int? width, + int? height, + int? quality}) async { + final String apiPath = + '/avatars/credit-cards/{code}'.replaceAll('{code}', code.value); + + final Map params = { + 'width': width, + 'height': height, + 'quality': quality, + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, 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. + /// + /// This endpoint does not follow HTTP redirects. + Future getFavicon({required String url}) async { + final String apiPath = '/avatars/favicon'; + + final Map params = { + 'url': url, + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, 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. Country codes + /// follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard. + /// + /// 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 enums.Flag code, int? width, int? height, int? quality}) async { + final String apiPath = + '/avatars/flags/{code}'.replaceAll('{code}', code.value); + + final Map params = { + 'width': width, + 'height': height, + 'quality': quality, + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, 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. + /// + /// This endpoint does not follow HTTP redirects. + Future getImage( + {required String url, int? width, int? height}) async { + final String apiPath = '/avatars/image'; + + final Map params = { + 'url': url, + 'width': width, + 'height': height, + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, 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? background}) async { + final String apiPath = '/avatars/initials'; + + final Map params = { + 'name': name, + 'width': width, + 'height': height, + 'background': background, + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, 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 { + final String apiPath = '/avatars/qr'; + + final Map params = { + 'text': text, + 'size': size, + 'margin': margin, + 'download': download, + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: params, responseType: ResponseType.bytes); + return res.data; + } +} diff --git a/lib/services/databases.dart b/lib/services/databases.dart index 6d74eb4b..5d3a8c86 100644 --- a/lib/services/databases.dart +++ b/lib/services/databases.dart @@ -3,1093 +3,1280 @@ part of '../dart_appwrite.dart'; /// The Databases service allows you to create structured collections of /// documents, query and filter lists of documents class Databases extends Service { - Databases(super.client); - - /// List databases - /// - /// Get a list of all databases from the current Appwrite project. You can use - /// the search parameter to filter your results. - Future list({List? queries, String? search}) async { - final String apiPath = '/databases'; - - final Map apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.DatabaseList.fromMap(res.data); - - } - - /// Create database - /// - /// Create a new Database. - /// - Future create({required String databaseId, required String name, bool? enabled}) async { - final String apiPath = '/databases'; - - final Map apiParams = { - - 'databaseId': databaseId, -'name': name, -'enabled': enabled, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Database.fromMap(res.data); - - } - - /// Get database - /// - /// Get a database by its unique ID. This endpoint response returns a JSON - /// object with the database metadata. - Future get({required String databaseId}) async { - final String apiPath = '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Database.fromMap(res.data); - - } - - /// Update database - /// - /// Update a database by its unique ID. - Future update({required String databaseId, required String name, bool? enabled}) async { - final String apiPath = '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); - - final Map apiParams = { - - 'name': name, -'enabled': enabled, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Database.fromMap(res.data); - - } - - /// Delete database - /// - /// Delete a database by its unique ID. Only API keys with with databases.write - /// scope can delete a database. - Future delete({required String databaseId}) async { - final String apiPath = '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List collections - /// - /// Get a list of all collections that belong to the provided databaseId. You - /// can use the search parameter to filter your results. - Future listCollections({required String databaseId, List? queries, String? search}) async { - final String apiPath = '/databases/{databaseId}/collections'.replaceAll('{databaseId}', databaseId); - - final Map apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.CollectionList.fromMap(res.data); - - } - - /// Create collection - /// - /// Create a new Collection. Before using this route, you should create a new - /// database resource using either a [server - /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) - /// API or directly from your database console. - Future createCollection({required String databaseId, required String collectionId, required String name, List? permissions, bool? documentSecurity, bool? enabled}) async { - final String apiPath = '/databases/{databaseId}/collections'.replaceAll('{databaseId}', databaseId); - - final Map apiParams = { - - 'collectionId': collectionId, -'name': name, -'permissions': permissions, -'documentSecurity': documentSecurity, -'enabled': enabled, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Collection.fromMap(res.data); - - } - - /// Get collection - /// - /// Get a collection by its unique ID. This endpoint response returns a JSON - /// object with the collection metadata. - Future getCollection({required String databaseId, required String collectionId}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Collection.fromMap(res.data); - - } - - /// Update collection - /// - /// Update a collection by its unique ID. - Future updateCollection({required String databaseId, required String collectionId, required String name, List? permissions, bool? documentSecurity, bool? enabled}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - - 'name': name, -'permissions': permissions, -'documentSecurity': documentSecurity, -'enabled': enabled, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Collection.fromMap(res.data); - - } - - /// Delete collection - /// - /// Delete a collection by its unique ID. Only users with write permissions - /// have access to delete this resource. - Future deleteCollection({required String databaseId, required String collectionId}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List attributes - /// - /// List attributes in the collection. - Future listAttributes({required String databaseId, required String collectionId, List? queries}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'queries': queries, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeList.fromMap(res.data); - - } - - /// Create boolean attribute - /// - /// Create a boolean attribute. - /// - Future createBooleanAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, bool? xdefault, bool? array}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/boolean'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - - 'key': key, -'required': xrequired, -'default': xdefault, -'array': array, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeBoolean.fromMap(res.data); - - } - - /// Update boolean attribute - /// - /// Update a boolean attribute. Changing the `default` value will not update - /// already existing documents. - Future updateBooleanAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required bool? xdefault, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/boolean/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map apiParams = { - - 'required': xrequired, -'default': xdefault, -'newKey': newKey, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeBoolean.fromMap(res.data); - - } - - /// Create datetime attribute - /// - /// Create a date time attribute according to the ISO 8601 standard. - Future createDatetimeAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/datetime'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - - 'key': key, -'required': xrequired, -'default': xdefault, -'array': array, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeDatetime.fromMap(res.data); - - } - - /// Update dateTime attribute - /// - /// Update a date time attribute. Changing the `default` value will not update - /// already existing documents. - Future updateDatetimeAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/datetime/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map apiParams = { - - 'required': xrequired, -'default': xdefault, -'newKey': newKey, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeDatetime.fromMap(res.data); - - } - - /// Create email attribute - /// - /// Create an email attribute. - /// - Future createEmailAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/email'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - - 'key': key, -'required': xrequired, -'default': xdefault, -'array': array, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEmail.fromMap(res.data); - - } - - /// Update email attribute - /// - /// Update an email attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateEmailAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/email/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map apiParams = { - - 'required': xrequired, -'default': xdefault, -'newKey': newKey, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEmail.fromMap(res.data); - - } - - /// Create enum attribute - /// - /// Create an enumeration attribute. The `elements` param acts as a white-list - /// of accepted values for this attribute. - /// - Future createEnumAttribute({required String databaseId, required String collectionId, required String key, required List elements, required bool xrequired, String? xdefault, bool? array}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/enum'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - - 'key': key, -'elements': elements, -'required': xrequired, -'default': xdefault, -'array': array, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEnum.fromMap(res.data); - - } - - /// Update enum attribute - /// - /// Update an enum attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateEnumAttribute({required String databaseId, required String collectionId, required String key, required List elements, required bool xrequired, required String? xdefault, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/enum/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map apiParams = { - - 'elements': elements, -'required': xrequired, -'default': xdefault, -'newKey': newKey, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEnum.fromMap(res.data); - - } - - /// Create float attribute - /// - /// Create a float attribute. Optionally, minimum and maximum values can be - /// provided. - /// - Future createFloatAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, double? min, double? max, double? xdefault, bool? array}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/float'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - - 'key': key, -'required': xrequired, -'min': min, -'max': max, -'default': xdefault, -'array': array, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeFloat.fromMap(res.data); - - } - - /// Update float attribute - /// - /// Update a float attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateFloatAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required double min, required double max, required double? xdefault, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/float/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map apiParams = { - - 'required': xrequired, -'min': min, -'max': max, -'default': xdefault, -'newKey': newKey, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeFloat.fromMap(res.data); - - } - - /// Create integer attribute - /// - /// Create an integer attribute. Optionally, minimum and maximum values can be - /// provided. - /// - Future createIntegerAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, int? min, int? max, int? xdefault, bool? array}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/integer'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - - 'key': key, -'required': xrequired, -'min': min, -'max': max, -'default': xdefault, -'array': array, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeInteger.fromMap(res.data); - - } - - /// Update integer attribute - /// - /// Update an integer attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateIntegerAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required int min, required int max, required int? xdefault, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/integer/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map apiParams = { - - 'required': xrequired, -'min': min, -'max': max, -'default': xdefault, -'newKey': newKey, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeInteger.fromMap(res.data); - - } - - /// Create IP address attribute - /// - /// Create IP address attribute. - /// - Future createIpAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/ip'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - - 'key': key, -'required': xrequired, -'default': xdefault, -'array': array, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeIp.fromMap(res.data); - - } - - /// Update IP address attribute - /// - /// Update an ip attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateIpAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/ip/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map apiParams = { - - 'required': xrequired, -'default': xdefault, -'newKey': newKey, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeIp.fromMap(res.data); - - } - - /// Create relationship attribute - /// - /// Create relationship attribute. [Learn more about relationship - /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). - /// - Future createRelationshipAttribute({required String databaseId, required String collectionId, required String relatedCollectionId, required enums.RelationshipType type, bool? twoWay, String? key, String? twoWayKey, enums.RelationMutate? onDelete}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/relationship'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - - 'relatedCollectionId': relatedCollectionId, -'type': type.value, -'twoWay': twoWay, -'key': key, -'twoWayKey': twoWayKey, -'onDelete': onDelete?.value, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeRelationship.fromMap(res.data); - - } - - /// Create string attribute - /// - /// Create a string attribute. - /// - Future createStringAttribute({required String databaseId, required String collectionId, required String key, required int size, required bool xrequired, String? xdefault, bool? array, bool? encrypt}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/string'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - - 'key': key, -'size': size, -'required': xrequired, -'default': xdefault, -'array': array, -'encrypt': encrypt, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeString.fromMap(res.data); - - } - - /// Update string attribute - /// - /// Update a string attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateStringAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, int? size, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/string/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map apiParams = { - - 'required': xrequired, -'default': xdefault, -'size': size, -'newKey': newKey, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeString.fromMap(res.data); - - } - - /// Create URL attribute - /// - /// Create a URL attribute. - /// - Future createUrlAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/url'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - - 'key': key, -'required': xrequired, -'default': xdefault, -'array': array, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeUrl.fromMap(res.data); - - } - - /// Update URL attribute - /// - /// Update an url attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateUrlAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/url/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map apiParams = { - - 'required': xrequired, -'default': xdefault, -'newKey': newKey, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeUrl.fromMap(res.data); - - } - - /// Get attribute - /// - /// Get attribute by ID. - Future getAttribute({required String databaseId, required String collectionId, required String key}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Delete attribute - /// - /// Deletes an attribute. - Future deleteAttribute({required String databaseId, required String collectionId, required String key}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Update relationship attribute - /// - /// Update relationship attribute. [Learn more about relationship - /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). - /// - Future updateRelationshipAttribute({required String databaseId, required String collectionId, required String key, enums.RelationMutate? onDelete, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}/relationship'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map apiParams = { - - 'onDelete': onDelete?.value, -'newKey': newKey, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeRelationship.fromMap(res.data); - - } - - /// List documents - /// - /// Get a list of all the user's documents in a given collection. You can use - /// the query params to filter your results. - Future listDocuments({required String databaseId, required String collectionId, List? queries}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'queries': queries, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.DocumentList.fromMap(res.data); - - } - - /// Create document - /// - /// Create a new Document. Before using this route, you should create a new - /// collection resource using either a [server - /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) - /// API or directly from your database console. - Future createDocument({required String databaseId, required String collectionId, required String documentId, required Map data, List? permissions}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - - 'documentId': documentId, -'data': data, -'permissions': permissions, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Document.fromMap(res.data); - - } - - /// Get document - /// - /// Get a document by its unique ID. This endpoint response returns a JSON - /// object with the document data. - Future getDocument({required String databaseId, required String collectionId, required String documentId, List? queries}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); - - final Map apiParams = { - 'queries': queries, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Document.fromMap(res.data); - - } - - /// Update document - /// - /// Update a document by its unique ID. Using the patch method you can pass - /// only specific fields that will get updated. - Future updateDocument({required String databaseId, required String collectionId, required String documentId, Map? data, List? permissions}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); - - final Map apiParams = { - - 'data': data, -'permissions': permissions, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Document.fromMap(res.data); - - } - - /// Delete document - /// - /// Delete a document by its unique ID. - Future deleteDocument({required String databaseId, required String collectionId, required String documentId}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List indexes - /// - /// List indexes in the collection. - Future listIndexes({required String databaseId, required String collectionId, List? queries}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'queries': queries, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.IndexList.fromMap(res.data); - - } - - /// Create index - /// - /// Creates an index on the attributes listed. Your index should include all - /// the attributes you will query in a single request. - /// Attributes can be `key`, `fulltext`, and `unique`. - Future createIndex({required String databaseId, required String collectionId, required String key, required enums.IndexType type, required List attributes, List? orders}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - - 'key': key, -'type': type.value, -'attributes': attributes, -'orders': orders, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Index.fromMap(res.data); - - } - - /// Get index - /// - /// Get index by ID. - Future getIndex({required String databaseId, required String collectionId, required String key}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Index.fromMap(res.data); - - } - - /// Delete index - /// - /// Delete an index. - Future deleteIndex({required String databaseId, required String collectionId, required String key}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } -} \ No newline at end of file + Databases(super.client); + + /// List databases + /// + /// Get a list of all databases from the current Appwrite project. You can use + /// the search parameter to filter your results. + Future list( + {List? queries, String? search}) async { + final String apiPath = '/databases'; + + final Map apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DatabaseList.fromMap(res.data); + } + + /// Create database + /// + /// Create a new Database. + /// + Future create( + {required String databaseId, required String name, bool? enabled}) async { + final String apiPath = '/databases'; + + final Map apiParams = { + 'databaseId': databaseId, + 'name': name, + 'enabled': enabled, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Database.fromMap(res.data); + } + + /// Get database + /// + /// Get a database by its unique ID. This endpoint response returns a JSON + /// object with the database metadata. + Future get({required String databaseId}) async { + final String apiPath = + '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Database.fromMap(res.data); + } + + /// Update database + /// + /// Update a database by its unique ID. + Future update( + {required String databaseId, required String name, bool? enabled}) async { + final String apiPath = + '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); + + final Map apiParams = { + 'name': name, + 'enabled': enabled, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Database.fromMap(res.data); + } + + /// Delete database + /// + /// Delete a database by its unique ID. Only API keys with with databases.write + /// scope can delete a database. + Future delete({required String databaseId}) async { + final String apiPath = + '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List collections + /// + /// Get a list of all collections that belong to the provided databaseId. You + /// can use the search parameter to filter your results. + Future listCollections( + {required String databaseId, + List? queries, + String? search}) async { + final String apiPath = '/databases/{databaseId}/collections' + .replaceAll('{databaseId}', databaseId); + + final Map apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.CollectionList.fromMap(res.data); + } + + /// Create collection + /// + /// Create a new Collection. Before using this route, you should create a new + /// database resource using either a [server + /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) + /// API or directly from your database console. + Future createCollection( + {required String databaseId, + required String collectionId, + required String name, + List? permissions, + bool? documentSecurity, + bool? enabled}) async { + final String apiPath = '/databases/{databaseId}/collections' + .replaceAll('{databaseId}', databaseId); + + final Map apiParams = { + 'collectionId': collectionId, + 'name': name, + 'permissions': permissions, + 'documentSecurity': documentSecurity, + 'enabled': enabled, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Collection.fromMap(res.data); + } + + /// Get collection + /// + /// Get a collection by its unique ID. This endpoint response returns a JSON + /// object with the collection metadata. + Future getCollection( + {required String databaseId, required String collectionId}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Collection.fromMap(res.data); + } + + /// Update collection + /// + /// Update a collection by its unique ID. + Future updateCollection( + {required String databaseId, + required String collectionId, + required String name, + List? permissions, + bool? documentSecurity, + bool? enabled}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'name': name, + 'permissions': permissions, + 'documentSecurity': documentSecurity, + 'enabled': enabled, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Collection.fromMap(res.data); + } + + /// Delete collection + /// + /// Delete a collection by its unique ID. Only users with write permissions + /// have access to delete this resource. + Future deleteCollection( + {required String databaseId, required String collectionId}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List attributes + /// + /// List attributes in the collection. + Future listAttributes( + {required String databaseId, + required String collectionId, + List? queries}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'queries': queries, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeList.fromMap(res.data); + } + + /// Create boolean attribute + /// + /// Create a boolean attribute. + /// + Future createBooleanAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + bool? xdefault, + bool? array}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/boolean' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'key': key, + 'required': xrequired, + 'default': xdefault, + 'array': array, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeBoolean.fromMap(res.data); + } + + /// Update boolean attribute + /// + /// Update a boolean attribute. Changing the `default` value will not update + /// already existing documents. + Future updateBooleanAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + required bool? xdefault, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/boolean/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map apiParams = { + 'required': xrequired, + 'default': xdefault, + 'newKey': newKey, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeBoolean.fromMap(res.data); + } + + /// Create datetime attribute + /// + /// Create a date time attribute according to the ISO 8601 standard. + Future createDatetimeAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + String? xdefault, + bool? array}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/datetime' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'key': key, + 'required': xrequired, + 'default': xdefault, + 'array': array, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeDatetime.fromMap(res.data); + } + + /// Update dateTime attribute + /// + /// Update a date time attribute. Changing the `default` value will not update + /// already existing documents. + Future updateDatetimeAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + required String? xdefault, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/datetime/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map apiParams = { + 'required': xrequired, + 'default': xdefault, + 'newKey': newKey, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeDatetime.fromMap(res.data); + } + + /// Create email attribute + /// + /// Create an email attribute. + /// + Future createEmailAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + String? xdefault, + bool? array}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/email' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'key': key, + 'required': xrequired, + 'default': xdefault, + 'array': array, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEmail.fromMap(res.data); + } + + /// Update email attribute + /// + /// Update an email attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateEmailAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + required String? xdefault, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/email/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map apiParams = { + 'required': xrequired, + 'default': xdefault, + 'newKey': newKey, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEmail.fromMap(res.data); + } + + /// Create enum attribute + /// + /// Create an enumeration attribute. The `elements` param acts as a white-list + /// of accepted values for this attribute. + /// + Future createEnumAttribute( + {required String databaseId, + required String collectionId, + required String key, + required List elements, + required bool xrequired, + String? xdefault, + bool? array}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/enum' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'key': key, + 'elements': elements, + 'required': xrequired, + 'default': xdefault, + 'array': array, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEnum.fromMap(res.data); + } + + /// Update enum attribute + /// + /// Update an enum attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateEnumAttribute( + {required String databaseId, + required String collectionId, + required String key, + required List elements, + required bool xrequired, + required String? xdefault, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/enum/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map apiParams = { + 'elements': elements, + 'required': xrequired, + 'default': xdefault, + 'newKey': newKey, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEnum.fromMap(res.data); + } + + /// Create float attribute + /// + /// Create a float attribute. Optionally, minimum and maximum values can be + /// provided. + /// + Future createFloatAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + double? min, + double? max, + double? xdefault, + bool? array}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/float' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'key': key, + 'required': xrequired, + 'min': min, + 'max': max, + 'default': xdefault, + 'array': array, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeFloat.fromMap(res.data); + } + + /// Update float attribute + /// + /// Update a float attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateFloatAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + required double min, + required double max, + required double? xdefault, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/float/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map apiParams = { + 'required': xrequired, + 'min': min, + 'max': max, + 'default': xdefault, + 'newKey': newKey, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeFloat.fromMap(res.data); + } + + /// Create integer attribute + /// + /// Create an integer attribute. Optionally, minimum and maximum values can be + /// provided. + /// + Future createIntegerAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + int? min, + int? max, + int? xdefault, + bool? array}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/integer' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'key': key, + 'required': xrequired, + 'min': min, + 'max': max, + 'default': xdefault, + 'array': array, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeInteger.fromMap(res.data); + } + + /// Update integer attribute + /// + /// Update an integer attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateIntegerAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + required int min, + required int max, + required int? xdefault, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/integer/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map apiParams = { + 'required': xrequired, + 'min': min, + 'max': max, + 'default': xdefault, + 'newKey': newKey, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeInteger.fromMap(res.data); + } + + /// Create IP address attribute + /// + /// Create IP address attribute. + /// + Future createIpAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + String? xdefault, + bool? array}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/ip' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'key': key, + 'required': xrequired, + 'default': xdefault, + 'array': array, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeIp.fromMap(res.data); + } + + /// Update IP address attribute + /// + /// Update an ip attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateIpAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + required String? xdefault, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/ip/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map apiParams = { + 'required': xrequired, + 'default': xdefault, + 'newKey': newKey, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeIp.fromMap(res.data); + } + + /// Create relationship attribute + /// + /// Create relationship attribute. [Learn more about relationship + /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). + /// + Future createRelationshipAttribute( + {required String databaseId, + required String collectionId, + required String relatedCollectionId, + required enums.RelationshipType type, + bool? twoWay, + String? key, + String? twoWayKey, + enums.RelationMutate? onDelete}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/relationship' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'relatedCollectionId': relatedCollectionId, + 'type': type.value, + 'twoWay': twoWay, + 'key': key, + 'twoWayKey': twoWayKey, + 'onDelete': onDelete?.value, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeRelationship.fromMap(res.data); + } + + /// Create string attribute + /// + /// Create a string attribute. + /// + Future createStringAttribute( + {required String databaseId, + required String collectionId, + required String key, + required int size, + required bool xrequired, + String? xdefault, + bool? array, + bool? encrypt}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/string' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'key': key, + 'size': size, + 'required': xrequired, + 'default': xdefault, + 'array': array, + 'encrypt': encrypt, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeString.fromMap(res.data); + } + + /// Update string attribute + /// + /// Update a string attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateStringAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + required String? xdefault, + int? size, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/string/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map apiParams = { + 'required': xrequired, + 'default': xdefault, + 'size': size, + 'newKey': newKey, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeString.fromMap(res.data); + } + + /// Create URL attribute + /// + /// Create a URL attribute. + /// + Future createUrlAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + String? xdefault, + bool? array}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/url' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'key': key, + 'required': xrequired, + 'default': xdefault, + 'array': array, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeUrl.fromMap(res.data); + } + + /// Update URL attribute + /// + /// Update an url attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateUrlAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + required String? xdefault, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/url/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map apiParams = { + 'required': xrequired, + 'default': xdefault, + 'newKey': newKey, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeUrl.fromMap(res.data); + } + + /// Get attribute + /// + /// Get attribute by ID. + Future getAttribute( + {required String databaseId, + required String collectionId, + required String key}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Delete attribute + /// + /// Deletes an attribute. + Future deleteAttribute( + {required String databaseId, + required String collectionId, + required String key}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Update relationship attribute + /// + /// Update relationship attribute. [Learn more about relationship + /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). + /// + Future updateRelationshipAttribute( + {required String databaseId, + required String collectionId, + required String key, + enums.RelationMutate? onDelete, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/{key}/relationship' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map apiParams = { + 'onDelete': onDelete?.value, + 'newKey': newKey, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeRelationship.fromMap(res.data); + } + + /// List documents + /// + /// Get a list of all the user's documents in a given collection. You can use + /// the query params to filter your results. + Future listDocuments( + {required String databaseId, + required String collectionId, + List? queries}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/documents' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'queries': queries, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DocumentList.fromMap(res.data); + } + + /// Create document + /// + /// Create a new Document. Before using this route, you should create a new + /// collection resource using either a [server + /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) + /// API or directly from your database console. + Future createDocument( + {required String databaseId, + required String collectionId, + required String documentId, + required Map data, + List? permissions}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/documents' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'documentId': documentId, + 'data': data, + 'permissions': permissions, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Document.fromMap(res.data); + } + + /// Get document + /// + /// Get a document by its unique ID. This endpoint response returns a JSON + /// object with the document data. + Future getDocument( + {required String databaseId, + required String collectionId, + required String documentId, + List? queries}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{documentId}', documentId); + + final Map apiParams = { + 'queries': queries, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Document.fromMap(res.data); + } + + /// Update document + /// + /// Update a document by its unique ID. Using the patch method you can pass + /// only specific fields that will get updated. + Future updateDocument( + {required String databaseId, + required String collectionId, + required String documentId, + Map? data, + List? permissions}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{documentId}', documentId); + + final Map apiParams = { + 'data': data, + 'permissions': permissions, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Document.fromMap(res.data); + } + + /// Delete document + /// + /// Delete a document by its unique ID. + Future deleteDocument( + {required String databaseId, + required String collectionId, + required String documentId}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{documentId}', documentId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List indexes + /// + /// List indexes in the collection. + Future listIndexes( + {required String databaseId, + required String collectionId, + List? queries}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/indexes' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'queries': queries, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.IndexList.fromMap(res.data); + } + + /// Create index + /// + /// Creates an index on the attributes listed. Your index should include all + /// the attributes you will query in a single request. + /// Attributes can be `key`, `fulltext`, and `unique`. + Future createIndex( + {required String databaseId, + required String collectionId, + required String key, + required enums.IndexType type, + required List attributes, + List? orders}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/indexes' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'key': key, + 'type': type.value, + 'attributes': attributes, + 'orders': orders, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Index.fromMap(res.data); + } + + /// Get index + /// + /// Get index by ID. + Future getIndex( + {required String databaseId, + required String collectionId, + required String key}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/indexes/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Index.fromMap(res.data); + } + + /// Delete index + /// + /// Delete an index. + Future deleteIndex( + {required String databaseId, + required String collectionId, + required String key}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/indexes/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } +} diff --git a/lib/services/functions.dart b/lib/services/functions.dart index 2bc323e9..5852b341 100644 --- a/lib/services/functions.dart +++ b/lib/services/functions.dart @@ -3,619 +3,650 @@ part of '../dart_appwrite.dart'; /// The Functions Service allows you view, create and manage your Cloud /// Functions. class Functions extends Service { - Functions(super.client); - - /// List functions - /// - /// Get a list of all the project's functions. You can use the query params to - /// filter your results. - Future list({List? queries, String? search}) async { - final String apiPath = '/functions'; - - final Map apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.FunctionList.fromMap(res.data); - - } - - /// Create function - /// - /// Create a new function. You can pass a list of - /// [permissions](https://appwrite.io/docs/permissions) to allow different - /// project users or team with access to execute the function using the client - /// API. - Future create({required String functionId, required String name, required enums.Runtime runtime, List? execute, List? events, String? schedule, int? timeout, bool? enabled, bool? logging, String? entrypoint, String? commands, List? scopes, String? installationId, String? providerRepositoryId, String? providerBranch, bool? providerSilentMode, String? providerRootDirectory, String? templateRepository, String? templateOwner, String? templateRootDirectory, String? templateVersion, String? specification}) async { - final String apiPath = '/functions'; - - final Map apiParams = { - - 'functionId': functionId, -'name': name, -'runtime': runtime.value, -'execute': execute, -'events': events, -'schedule': schedule, -'timeout': timeout, -'enabled': enabled, -'logging': logging, -'entrypoint': entrypoint, -'commands': commands, -'scopes': scopes, -'installationId': installationId, -'providerRepositoryId': providerRepositoryId, -'providerBranch': providerBranch, -'providerSilentMode': providerSilentMode, -'providerRootDirectory': providerRootDirectory, -'templateRepository': templateRepository, -'templateOwner': templateOwner, -'templateRootDirectory': templateRootDirectory, -'templateVersion': templateVersion, -'specification': specification, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - - } - - /// List runtimes - /// - /// Get a list of all runtimes that are currently active on your instance. - Future listRuntimes() async { - final String apiPath = '/functions/runtimes'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.RuntimeList.fromMap(res.data); - - } - - /// List available function runtime specifications - /// - /// List allowed function specifications for this instance. - /// - Future listSpecifications() async { - final String apiPath = '/functions/specifications'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SpecificationList.fromMap(res.data); - - } - - /// Get function - /// - /// Get a function by its unique ID. - Future get({required String functionId}) async { - final String apiPath = '/functions/{functionId}'.replaceAll('{functionId}', functionId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - - } - - /// Update function - /// - /// Update function by its unique ID. - Future update({required String functionId, required String name, enums.Runtime? runtime, List? execute, List? events, String? schedule, int? timeout, bool? enabled, bool? logging, String? entrypoint, String? commands, List? scopes, String? installationId, String? providerRepositoryId, String? providerBranch, bool? providerSilentMode, String? providerRootDirectory, String? specification}) async { - final String apiPath = '/functions/{functionId}'.replaceAll('{functionId}', functionId); - - final Map apiParams = { - - 'name': name, -'runtime': runtime?.value, -'execute': execute, -'events': events, -'schedule': schedule, -'timeout': timeout, -'enabled': enabled, -'logging': logging, -'entrypoint': entrypoint, -'commands': commands, -'scopes': scopes, -'installationId': installationId, -'providerRepositoryId': providerRepositoryId, -'providerBranch': providerBranch, -'providerSilentMode': providerSilentMode, -'providerRootDirectory': providerRootDirectory, -'specification': specification, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - - } - - /// Delete function - /// - /// Delete a function by its unique ID. - Future delete({required String functionId}) async { - final String apiPath = '/functions/{functionId}'.replaceAll('{functionId}', functionId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List deployments - /// - /// Get a list of all the project's code deployments. You can use the query - /// params to filter your results. - Future listDeployments({required String functionId, List? queries, String? search}) async { - final String apiPath = '/functions/{functionId}/deployments'.replaceAll('{functionId}', functionId); - - final Map apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.DeploymentList.fromMap(res.data); - - } - - /// Create deployment - /// - /// Create a new function code deployment. Use this endpoint to upload a new - /// version of your code function. To execute your newly uploaded code, you'll - /// need to update the function's deployment to use your new deployment UID. - /// - /// This endpoint accepts a tar.gz file compressed with your code. Make sure to - /// include any dependencies your code has within the compressed file. You can - /// learn more about code packaging in the [Appwrite Cloud Functions - /// tutorial](https://appwrite.io/docs/functions). - /// - /// Use the "command" param to set the entrypoint used to execute your code. - Future createDeployment({required String functionId, required Payload code, required bool activate, String? entrypoint, String? commands, Function(UploadProgress)? onProgress}) async { - final String apiPath = '/functions/{functionId}/deployments'.replaceAll('{functionId}', functionId); - - final Map apiParams = { - - 'entrypoint': entrypoint, -'commands': commands, -'code': code, -'activate': activate, - - }; - - final Map apiHeaders = { - 'content-type': 'multipart/form-data', - - }; - - String idParamName = ''; - final paramName = 'code'; - final res = await client.chunkedUpload( - path: apiPath, - params: apiParams, - paramName: paramName, - idParamName: idParamName, - headers: apiHeaders, - onProgress: onProgress, - ); - - return models.Deployment.fromMap(res.data); - - } - - /// Get deployment - /// - /// Get a code deployment by its unique ID. - Future getDeployment({required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Deployment.fromMap(res.data); - - } - - /// Update deployment - /// - /// Update the function code deployment ID using the unique function ID. Use - /// this endpoint to switch the code deployment that should be executed by the - /// execution endpoint. - Future updateDeployment({required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - - } - - /// Delete deployment - /// - /// Delete a code deployment by its unique ID. - Future deleteDeployment({required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Rebuild deployment - /// - Future createBuild({required String functionId, required String deploymentId, String? buildId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}/build'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); - - final Map apiParams = { - - 'buildId': buildId, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Cancel deployment - /// - Future updateDeploymentBuild({required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}/build'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Build.fromMap(res.data); - - } - - /// Download deployment - /// - /// Get a Deployment's contents by its unique ID. This endpoint supports range - /// requests for partial or streaming file download. - Future getDeploymentDownload({required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}/download'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); - - final Map params = { - - - 'project': client.config['project'], - 'key': client.config['key'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: params, responseType: ResponseType.bytes); - 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. - Future listExecutions({required String functionId, List? queries, String? search}) async { - final String apiPath = '/functions/{functionId}/executions'.replaceAll('{functionId}', functionId); - - final Map apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - 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, Payload? body, bool? xasync, String? path, enums.ExecutionMethod? method, Map? headers, String? scheduledAt, Function(UploadProgress)? onProgress}) async { - final String apiPath = '/functions/{functionId}/executions'.replaceAll('{functionId}', functionId); - - final Map apiParams = { - - 'body': body, -'async': xasync, -'path': path, -'method': method?.value, -'headers': headers, -'scheduledAt': scheduledAt, - - }; - - final Map apiHeaders = { - 'content-type': 'multipart/form-data', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/functions/{functionId}/executions/{executionId}'.replaceAll('{functionId}', functionId).replaceAll('{executionId}', executionId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Execution.fromMap(res.data); - - } - - /// Delete execution - /// - /// Delete a function execution by its unique ID. - /// - Future deleteExecution({required String functionId, required String executionId}) async { - final String apiPath = '/functions/{functionId}/executions/{executionId}'.replaceAll('{functionId}', functionId).replaceAll('{executionId}', executionId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List variables - /// - /// Get a list of all variables of a specific function. - Future listVariables({required String functionId}) async { - final String apiPath = '/functions/{functionId}/variables'.replaceAll('{functionId}', functionId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.VariableList.fromMap(res.data); - - } - - /// Create variable - /// - /// Create a new function environment variable. These variables can be accessed - /// in the function at runtime as environment variables. - Future createVariable({required String functionId, required String key, required String value}) async { - final String apiPath = '/functions/{functionId}/variables'.replaceAll('{functionId}', functionId); - - final Map apiParams = { - - 'key': key, -'value': value, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Variable.fromMap(res.data); - - } - - /// Get variable - /// - /// Get a variable by its unique ID. - Future getVariable({required String functionId, required String variableId}) async { - final String apiPath = '/functions/{functionId}/variables/{variableId}'.replaceAll('{functionId}', functionId).replaceAll('{variableId}', variableId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Variable.fromMap(res.data); - - } - - /// Update variable - /// - /// Update variable by its unique ID. - Future updateVariable({required String functionId, required String variableId, required String key, String? value}) async { - final String apiPath = '/functions/{functionId}/variables/{variableId}'.replaceAll('{functionId}', functionId).replaceAll('{variableId}', variableId); - - final Map apiParams = { - - 'key': key, -'value': value, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Variable.fromMap(res.data); - - } - - /// Delete variable - /// - /// Delete a variable by its unique ID. - Future deleteVariable({required String functionId, required String variableId}) async { - final String apiPath = '/functions/{functionId}/variables/{variableId}'.replaceAll('{functionId}', functionId).replaceAll('{variableId}', variableId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } -} \ No newline at end of file + Functions(super.client); + + /// List functions + /// + /// Get a list of all the project's functions. You can use the query params to + /// filter your results. + Future list( + {List? queries, String? search}) async { + final String apiPath = '/functions'; + + final Map apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.FunctionList.fromMap(res.data); + } + + /// Create function + /// + /// Create a new function. You can pass a list of + /// [permissions](https://appwrite.io/docs/permissions) to allow different + /// project users or team with access to execute the function using the client + /// API. + Future create( + {required String functionId, + required String name, + required enums.Runtime runtime, + List? execute, + List? events, + String? schedule, + int? timeout, + bool? enabled, + bool? logging, + String? entrypoint, + String? commands, + List? scopes, + String? installationId, + String? providerRepositoryId, + String? providerBranch, + bool? providerSilentMode, + String? providerRootDirectory, + String? templateRepository, + String? templateOwner, + String? templateRootDirectory, + String? templateVersion, + String? specification}) async { + final String apiPath = '/functions'; + + final Map apiParams = { + 'functionId': functionId, + 'name': name, + 'runtime': runtime.value, + 'execute': execute, + 'events': events, + 'schedule': schedule, + 'timeout': timeout, + 'enabled': enabled, + 'logging': logging, + 'entrypoint': entrypoint, + 'commands': commands, + 'scopes': scopes, + 'installationId': installationId, + 'providerRepositoryId': providerRepositoryId, + 'providerBranch': providerBranch, + 'providerSilentMode': providerSilentMode, + 'providerRootDirectory': providerRootDirectory, + 'templateRepository': templateRepository, + 'templateOwner': templateOwner, + 'templateRootDirectory': templateRootDirectory, + 'templateVersion': templateVersion, + 'specification': specification, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + } + + /// List runtimes + /// + /// Get a list of all runtimes that are currently active on your instance. + Future listRuntimes() async { + final String apiPath = '/functions/runtimes'; + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.RuntimeList.fromMap(res.data); + } + + /// List available function runtime specifications + /// + /// List allowed function specifications for this instance. + /// + Future listSpecifications() async { + final String apiPath = '/functions/specifications'; + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SpecificationList.fromMap(res.data); + } + + /// Get function + /// + /// Get a function by its unique ID. + Future get({required String functionId}) async { + final String apiPath = + '/functions/{functionId}'.replaceAll('{functionId}', functionId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + } + + /// Update function + /// + /// Update function by its unique ID. + Future update( + {required String functionId, + required String name, + enums.Runtime? runtime, + List? execute, + List? events, + String? schedule, + int? timeout, + bool? enabled, + bool? logging, + String? entrypoint, + String? commands, + List? scopes, + String? installationId, + String? providerRepositoryId, + String? providerBranch, + bool? providerSilentMode, + String? providerRootDirectory, + String? specification}) async { + final String apiPath = + '/functions/{functionId}'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + 'name': name, + 'runtime': runtime?.value, + 'execute': execute, + 'events': events, + 'schedule': schedule, + 'timeout': timeout, + 'enabled': enabled, + 'logging': logging, + 'entrypoint': entrypoint, + 'commands': commands, + 'scopes': scopes, + 'installationId': installationId, + 'providerRepositoryId': providerRepositoryId, + 'providerBranch': providerBranch, + 'providerSilentMode': providerSilentMode, + 'providerRootDirectory': providerRootDirectory, + 'specification': specification, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + } + + /// Delete function + /// + /// Delete a function by its unique ID. + Future delete({required String functionId}) async { + final String apiPath = + '/functions/{functionId}'.replaceAll('{functionId}', functionId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List deployments + /// + /// Get a list of all the project's code deployments. You can use the query + /// params to filter your results. + Future listDeployments( + {required String functionId, + List? queries, + String? search}) async { + final String apiPath = '/functions/{functionId}/deployments' + .replaceAll('{functionId}', functionId); + + final Map apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DeploymentList.fromMap(res.data); + } + + /// Create deployment + /// + /// Create a new function code deployment. Use this endpoint to upload a new + /// version of your code function. To execute your newly uploaded code, you'll + /// need to update the function's deployment to use your new deployment UID. + /// + /// This endpoint accepts a tar.gz file compressed with your code. Make sure to + /// include any dependencies your code has within the compressed file. You can + /// learn more about code packaging in the [Appwrite Cloud Functions + /// tutorial](https://appwrite.io/docs/functions). + /// + /// Use the "command" param to set the entrypoint used to execute your code. + Future createDeployment( + {required String functionId, + required Payload code, + required bool activate, + String? entrypoint, + String? commands, + Function(UploadProgress)? onProgress}) async { + final String apiPath = '/functions/{functionId}/deployments' + .replaceAll('{functionId}', functionId); + + final Map apiParams = { + 'entrypoint': entrypoint, + 'commands': commands, + 'code': code, + 'activate': activate, + }; + + final Map apiHeaders = { + 'content-type': 'multipart/form-data', + }; + + String idParamName = ''; + final paramName = 'code'; + final res = await client.chunkedUpload( + path: apiPath, + params: apiParams, + paramName: paramName, + idParamName: idParamName, + headers: apiHeaders, + onProgress: onProgress, + ); + + return models.Deployment.fromMap(res.data); + } + + /// Get deployment + /// + /// Get a code deployment by its unique ID. + Future getDeployment( + {required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}' + .replaceAll('{functionId}', functionId) + .replaceAll('{deploymentId}', deploymentId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Deployment.fromMap(res.data); + } + + /// Update deployment + /// + /// Update the function code deployment ID using the unique function ID. Use + /// this endpoint to switch the code deployment that should be executed by the + /// execution endpoint. + Future updateDeployment( + {required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}' + .replaceAll('{functionId}', functionId) + .replaceAll('{deploymentId}', deploymentId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + } + + /// Delete deployment + /// + /// Delete a code deployment by its unique ID. + Future deleteDeployment( + {required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}' + .replaceAll('{functionId}', functionId) + .replaceAll('{deploymentId}', deploymentId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Rebuild deployment + /// + Future createBuild( + {required String functionId, + required String deploymentId, + String? buildId}) async { + final String apiPath = + '/functions/{functionId}/deployments/{deploymentId}/build' + .replaceAll('{functionId}', functionId) + .replaceAll('{deploymentId}', deploymentId); + + final Map apiParams = { + 'buildId': buildId, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Cancel deployment + /// + Future updateDeploymentBuild( + {required String functionId, required String deploymentId}) async { + final String apiPath = + '/functions/{functionId}/deployments/{deploymentId}/build' + .replaceAll('{functionId}', functionId) + .replaceAll('{deploymentId}', deploymentId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Build.fromMap(res.data); + } + + /// Download deployment + /// + /// Get a Deployment's contents by its unique ID. This endpoint supports range + /// requests for partial or streaming file download. + Future getDeploymentDownload( + {required String functionId, required String deploymentId}) async { + final String apiPath = + '/functions/{functionId}/deployments/{deploymentId}/download' + .replaceAll('{functionId}', functionId) + .replaceAll('{deploymentId}', deploymentId); + + final Map params = { + 'project': client.config['project'], + 'key': client.config['key'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: params, responseType: ResponseType.bytes); + 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. + Future listExecutions( + {required String functionId, + List? queries, + String? search}) async { + final String apiPath = '/functions/{functionId}/executions' + .replaceAll('{functionId}', functionId); + + final Map apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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, + Payload? body, + bool? xasync, + String? path, + enums.ExecutionMethod? method, + Map? headers, + String? scheduledAt, + Function(UploadProgress)? onProgress}) async { + final String apiPath = '/functions/{functionId}/executions' + .replaceAll('{functionId}', functionId); + + final Map apiParams = { + 'body': body, + 'async': xasync, + 'path': path, + 'method': method?.value, + 'headers': headers, + 'scheduledAt': scheduledAt, + }; + + final Map apiHeaders = { + 'content-type': 'multipart/form-data', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/functions/{functionId}/executions/{executionId}' + .replaceAll('{functionId}', functionId) + .replaceAll('{executionId}', executionId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Execution.fromMap(res.data); + } + + /// Delete execution + /// + /// Delete a function execution by its unique ID. + /// + Future deleteExecution( + {required String functionId, required String executionId}) async { + final String apiPath = '/functions/{functionId}/executions/{executionId}' + .replaceAll('{functionId}', functionId) + .replaceAll('{executionId}', executionId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List variables + /// + /// Get a list of all variables of a specific function. + Future listVariables( + {required String functionId}) async { + final String apiPath = '/functions/{functionId}/variables' + .replaceAll('{functionId}', functionId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.VariableList.fromMap(res.data); + } + + /// Create variable + /// + /// Create a new function environment variable. These variables can be accessed + /// in the function at runtime as environment variables. + Future createVariable( + {required String functionId, + required String key, + required String value}) async { + final String apiPath = '/functions/{functionId}/variables' + .replaceAll('{functionId}', functionId); + + final Map apiParams = { + 'key': key, + 'value': value, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Variable.fromMap(res.data); + } + + /// Get variable + /// + /// Get a variable by its unique ID. + Future getVariable( + {required String functionId, required String variableId}) async { + final String apiPath = '/functions/{functionId}/variables/{variableId}' + .replaceAll('{functionId}', functionId) + .replaceAll('{variableId}', variableId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Variable.fromMap(res.data); + } + + /// Update variable + /// + /// Update variable by its unique ID. + Future updateVariable( + {required String functionId, + required String variableId, + required String key, + String? value}) async { + final String apiPath = '/functions/{functionId}/variables/{variableId}' + .replaceAll('{functionId}', functionId) + .replaceAll('{variableId}', variableId); + + final Map apiParams = { + 'key': key, + 'value': value, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Variable.fromMap(res.data); + } + + /// Delete variable + /// + /// Delete a variable by its unique ID. + Future deleteVariable( + {required String functionId, required String variableId}) async { + final String apiPath = '/functions/{functionId}/variables/{variableId}' + .replaceAll('{functionId}', functionId) + .replaceAll('{variableId}', variableId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } +} diff --git a/lib/services/graphql.dart b/lib/services/graphql.dart index be9d037b..fdc1ae0b 100644 --- a/lib/services/graphql.dart +++ b/lib/services/graphql.dart @@ -3,53 +3,47 @@ part of '../dart_appwrite.dart'; /// The GraphQL API allows you to query and mutate your Appwrite server using /// GraphQL. class Graphql extends Service { - Graphql(super.client); - - /// GraphQL endpoint - /// - /// Execute a GraphQL mutation. - Future query({required Map query}) async { - final String apiPath = '/graphql'; - - final Map apiParams = { - - 'query': query, - - }; - - final Map apiHeaders = { - 'x-sdk-graphql': 'true', -'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// GraphQL endpoint - /// - /// Execute a GraphQL mutation. - Future mutation({required Map query}) async { - final String apiPath = '/graphql/mutation'; - - final Map apiParams = { - - 'query': query, - - }; - - final Map apiHeaders = { - 'x-sdk-graphql': 'true', -'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } -} \ No newline at end of file + Graphql(super.client); + + /// GraphQL endpoint + /// + /// Execute a GraphQL mutation. + Future query({required Map query}) async { + final String apiPath = '/graphql'; + + final Map apiParams = { + 'query': query, + }; + + final Map apiHeaders = { + 'x-sdk-graphql': 'true', + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// GraphQL endpoint + /// + /// Execute a GraphQL mutation. + Future mutation({required Map query}) async { + final String apiPath = '/graphql/mutation'; + + final Map apiParams = { + 'query': query, + }; + + final Map apiHeaders = { + 'x-sdk-graphql': 'true', + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } +} diff --git a/lib/services/health.dart b/lib/services/health.dart index 4e7b4603..121083c0 100644 --- a/lib/services/health.dart +++ b/lib/services/health.dart @@ -3,548 +3,473 @@ part of '../dart_appwrite.dart'; /// The Health service allows you to both validate and monitor your Appwrite /// server's health. class Health extends Service { - Health(super.client); + Health(super.client); - /// Get HTTP - /// - /// Check the Appwrite HTTP server is up and responsive. - Future get() async { - final String apiPath = '/health'; + /// Get HTTP + /// + /// Check the Appwrite HTTP server is up and responsive. + Future get() async { + final String apiPath = '/health'; - final Map apiParams = { - - - }; + final Map apiParams = {}; - final Map apiHeaders = { - 'content-type': 'application/json', + final Map apiHeaders = { + 'content-type': 'application/json', + }; - }; + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + return models.HealthStatus.fromMap(res.data); + } - return models.HealthStatus.fromMap(res.data); + /// Get antivirus + /// + /// Check the Appwrite Antivirus server is up and connection is successful. + Future getAntivirus() async { + final String apiPath = '/health/anti-virus'; - } + final Map apiParams = {}; - /// Get antivirus - /// - /// Check the Appwrite Antivirus server is up and connection is successful. - Future getAntivirus() async { - final String apiPath = '/health/anti-virus'; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final Map apiParams = { - - - }; + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - final Map apiHeaders = { - 'content-type': 'application/json', + return models.HealthAntivirus.fromMap(res.data); + } - }; + /// Get cache + /// + /// Check the Appwrite in-memory cache servers are up and connection is + /// successful. + Future getCache() async { + final String apiPath = '/health/cache'; - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + final Map apiParams = {}; - return models.HealthAntivirus.fromMap(res.data); + final Map apiHeaders = { + 'content-type': 'application/json', + }; - } + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - /// Get cache - /// - /// Check the Appwrite in-memory cache servers are up and connection is - /// successful. - Future getCache() async { - final String apiPath = '/health/cache'; + return models.HealthStatus.fromMap(res.data); + } - final Map apiParams = { - - - }; + /// Get the SSL certificate for a domain + /// + /// Get the SSL certificate for a domain + Future getCertificate({String? domain}) async { + final String apiPath = '/health/certificate'; - final Map apiHeaders = { - 'content-type': 'application/json', + final Map apiParams = { + 'domain': domain, + }; - }; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - return models.HealthStatus.fromMap(res.data); + return models.HealthCertificate.fromMap(res.data); + } - } + /// Get DB + /// + /// Check the Appwrite database servers are up and connection is successful. + Future getDB() async { + final String apiPath = '/health/db'; - /// Get the SSL certificate for a domain - /// - /// Get the SSL certificate for a domain - Future getCertificate({String? domain}) async { - final String apiPath = '/health/certificate'; + final Map apiParams = {}; - final Map apiParams = { - 'domain': domain, + final Map apiHeaders = { + 'content-type': 'application/json', + }; - - }; + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - final Map apiHeaders = { - 'content-type': 'application/json', + return models.HealthStatus.fromMap(res.data); + } - }; + /// Get pubsub + /// + /// Check the Appwrite pub-sub servers are up and connection is successful. + Future getPubSub() async { + final String apiPath = '/health/pubsub'; - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + final Map apiParams = {}; - return models.HealthCertificate.fromMap(res.data); + final Map apiHeaders = { + 'content-type': 'application/json', + }; - } + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - /// Get DB - /// - /// Check the Appwrite database servers are up and connection is successful. - Future getDB() async { - final String apiPath = '/health/db'; + return models.HealthStatus.fromMap(res.data); + } - final Map apiParams = { - - - }; + /// Get queue + /// + /// Check the Appwrite queue messaging servers are up and connection is + /// successful. + Future getQueue() async { + final String apiPath = '/health/queue'; - final Map apiHeaders = { - 'content-type': 'application/json', + final Map apiParams = {}; - }; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthStatus.fromMap(res.data); + } - return models.HealthStatus.fromMap(res.data); + /// Get builds queue + /// + /// Get the number of builds that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueBuilds({int? threshold}) async { + final String apiPath = '/health/queue/builds'; + + final Map apiParams = { + 'threshold': threshold, + }; - } + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get certificates queue + /// + /// Get the number of certificates that are waiting to be issued against + /// [Letsencrypt](https://letsencrypt.org/) in the Appwrite internal queue + /// server. + Future getQueueCertificates({int? threshold}) async { + final String apiPath = '/health/queue/certificates'; + + final Map apiParams = { + 'threshold': threshold, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get databases queue + /// + /// Get the number of database changes that are waiting to be processed in the + /// Appwrite internal queue server. + Future getQueueDatabases( + {String? name, int? threshold}) async { + final String apiPath = '/health/queue/databases'; + + final Map apiParams = { + 'name': name, + 'threshold': threshold, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get deletes queue + /// + /// Get the number of background destructive changes that are waiting to be + /// processed in the Appwrite internal queue server. + Future getQueueDeletes({int? threshold}) async { + final String apiPath = '/health/queue/deletes'; + + final Map apiParams = { + 'threshold': threshold, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get number of failed queue jobs + /// + /// Returns the amount of failed jobs in a given queue. + /// + Future getFailedJobs( + {required enums.Name name, int? threshold}) async { + final String apiPath = + '/health/queue/failed/{name}'.replaceAll('{name}', name.value); + + final Map apiParams = { + 'threshold': threshold, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get functions queue + /// + /// Get the number of function executions that are waiting to be processed in + /// the Appwrite internal queue server. + Future getQueueFunctions({int? threshold}) async { + final String apiPath = '/health/queue/functions'; + + final Map apiParams = { + 'threshold': threshold, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get logs queue + /// + /// Get the number of logs that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueLogs({int? threshold}) async { + final String apiPath = '/health/queue/logs'; + + final Map apiParams = { + 'threshold': threshold, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get mails queue + /// + /// Get the number of mails that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueMails({int? threshold}) async { + final String apiPath = '/health/queue/mails'; + + final Map apiParams = { + 'threshold': threshold, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get messaging queue + /// + /// Get the number of messages that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueMessaging({int? threshold}) async { + final String apiPath = '/health/queue/messaging'; + + final Map apiParams = { + 'threshold': threshold, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get migrations queue + /// + /// Get the number of migrations that are waiting to be processed in the + /// Appwrite internal queue server. + Future getQueueMigrations({int? threshold}) async { + final String apiPath = '/health/queue/migrations'; + + final Map apiParams = { + 'threshold': threshold, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } - /// Get pubsub - /// - /// Check the Appwrite pub-sub servers are up and connection is successful. - Future getPubSub() async { - final String apiPath = '/health/pubsub'; + /// Get usage queue + /// + /// Get the number of metrics that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueUsage({int? threshold}) async { + final String apiPath = '/health/queue/usage'; + + final Map apiParams = { + 'threshold': threshold, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get usage dump queue + /// + /// Get the number of projects containing metrics that are waiting to be + /// processed in the Appwrite internal queue server. + Future getQueueUsageDump({int? threshold}) async { + final String apiPath = '/health/queue/usage-dump'; + + final Map apiParams = { + 'threshold': threshold, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get webhooks queue + /// + /// Get the number of webhooks that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueWebhooks({int? threshold}) async { + final String apiPath = '/health/queue/webhooks'; + + final Map apiParams = { + 'threshold': threshold, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get storage + /// + /// Check the Appwrite storage device is up and connection is successful. + Future getStorage() async { + final String apiPath = '/health/storage'; - final Map apiParams = { - - - }; + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthStatus.fromMap(res.data); + } + + /// Get local storage + /// + /// Check the Appwrite local storage device is up and connection is successful. + Future getStorageLocal() async { + final String apiPath = '/health/storage/local'; + + final Map apiParams = {}; - final Map apiHeaders = { - 'content-type': 'application/json', + final Map apiHeaders = { + 'content-type': 'application/json', + }; - }; + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthStatus.fromMap(res.data); + } + + /// Get time + /// + /// Check the Appwrite server time is synced with Google remote NTP server. We + /// use this technology to smoothly handle leap seconds with no disruptive + /// events. The [Network Time + /// Protocol](https://en.wikipedia.org/wiki/Network_Time_Protocol) (NTP) is + /// used by hundreds of millions of computers and devices to synchronize their + /// clocks over the Internet. If your computer sets its own clock, it likely + /// uses NTP. + Future getTime() async { + final String apiPath = '/health/time'; - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + final Map apiParams = {}; - return models.HealthStatus.fromMap(res.data); + final Map apiHeaders = { + 'content-type': 'application/json', + }; - } - - /// Get queue - /// - /// Check the Appwrite queue messaging servers are up and connection is - /// successful. - Future getQueue() async { - final String apiPath = '/health/queue'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthStatus.fromMap(res.data); - - } - - /// Get builds queue - /// - /// Get the number of builds that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueBuilds({int? threshold}) async { - final String apiPath = '/health/queue/builds'; - - final Map apiParams = { - 'threshold': threshold, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get certificates queue - /// - /// Get the number of certificates that are waiting to be issued against - /// [Letsencrypt](https://letsencrypt.org/) in the Appwrite internal queue - /// server. - Future getQueueCertificates({int? threshold}) async { - final String apiPath = '/health/queue/certificates'; - - final Map apiParams = { - 'threshold': threshold, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get databases queue - /// - /// Get the number of database changes that are waiting to be processed in the - /// Appwrite internal queue server. - Future getQueueDatabases({String? name, int? threshold}) async { - final String apiPath = '/health/queue/databases'; - - final Map apiParams = { - 'name': name, -'threshold': threshold, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get deletes queue - /// - /// Get the number of background destructive changes that are waiting to be - /// processed in the Appwrite internal queue server. - Future getQueueDeletes({int? threshold}) async { - final String apiPath = '/health/queue/deletes'; - - final Map apiParams = { - 'threshold': threshold, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get number of failed queue jobs - /// - /// Returns the amount of failed jobs in a given queue. - /// - Future getFailedJobs({required enums.Name name, int? threshold}) async { - final String apiPath = '/health/queue/failed/{name}'.replaceAll('{name}', name.value); - - final Map apiParams = { - 'threshold': threshold, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get functions queue - /// - /// Get the number of function executions that are waiting to be processed in - /// the Appwrite internal queue server. - Future getQueueFunctions({int? threshold}) async { - final String apiPath = '/health/queue/functions'; - - final Map apiParams = { - 'threshold': threshold, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get logs queue - /// - /// Get the number of logs that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueLogs({int? threshold}) async { - final String apiPath = '/health/queue/logs'; - - final Map apiParams = { - 'threshold': threshold, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get mails queue - /// - /// Get the number of mails that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueMails({int? threshold}) async { - final String apiPath = '/health/queue/mails'; - - final Map apiParams = { - 'threshold': threshold, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get messaging queue - /// - /// Get the number of messages that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueMessaging({int? threshold}) async { - final String apiPath = '/health/queue/messaging'; - - final Map apiParams = { - 'threshold': threshold, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get migrations queue - /// - /// Get the number of migrations that are waiting to be processed in the - /// Appwrite internal queue server. - Future getQueueMigrations({int? threshold}) async { - final String apiPath = '/health/queue/migrations'; - - final Map apiParams = { - 'threshold': threshold, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get usage queue - /// - /// Get the number of metrics that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueUsage({int? threshold}) async { - final String apiPath = '/health/queue/usage'; - - final Map apiParams = { - 'threshold': threshold, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get usage dump queue - /// - /// Get the number of projects containing metrics that are waiting to be - /// processed in the Appwrite internal queue server. - Future getQueueUsageDump({int? threshold}) async { - final String apiPath = '/health/queue/usage-dump'; - - final Map apiParams = { - 'threshold': threshold, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get webhooks queue - /// - /// Get the number of webhooks that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueWebhooks({int? threshold}) async { - final String apiPath = '/health/queue/webhooks'; - - final Map apiParams = { - 'threshold': threshold, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get storage - /// - /// Check the Appwrite storage device is up and connection is successful. - Future getStorage() async { - final String apiPath = '/health/storage'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthStatus.fromMap(res.data); - - } - - /// Get local storage - /// - /// Check the Appwrite local storage device is up and connection is successful. - Future getStorageLocal() async { - final String apiPath = '/health/storage/local'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthStatus.fromMap(res.data); - - } - - /// Get time - /// - /// Check the Appwrite server time is synced with Google remote NTP server. We - /// use this technology to smoothly handle leap seconds with no disruptive - /// events. The [Network Time - /// Protocol](https://en.wikipedia.org/wiki/Network_Time_Protocol) (NTP) is - /// used by hundreds of millions of computers and devices to synchronize their - /// clocks over the Internet. If your computer sets its own clock, it likely - /// uses NTP. - Future getTime() async { - final String apiPath = '/health/time'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthTime.fromMap(res.data); - - } -} \ No newline at end of file + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthTime.fromMap(res.data); + } +} diff --git a/lib/services/locale.dart b/lib/services/locale.dart index 78372039..b287c8e9 100644 --- a/lib/services/locale.dart +++ b/lib/services/locale.dart @@ -3,194 +3,162 @@ part of '../dart_appwrite.dart'; /// The Locale service allows you to customize your app based on your users' /// location. class Locale extends Service { - Locale(super.client); + Locale(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 { - final String apiPath = '/locale'; + /// 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 { + final String apiPath = '/locale'; - final Map apiParams = { - - - }; + final Map apiParams = {}; - final Map apiHeaders = { - 'content-type': 'application/json', + final Map apiHeaders = { + 'content-type': 'application/json', + }; - }; + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + return models.Locale.fromMap(res.data); + } - return models.Locale.fromMap(res.data); + /// List Locale Codes + /// + /// List of all locale codes in [ISO + /// 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). + Future listCodes() async { + final String apiPath = '/locale/codes'; - } + final Map apiParams = {}; - /// List Locale Codes - /// - /// List of all locale codes in [ISO - /// 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). - Future listCodes() async { - final String apiPath = '/locale/codes'; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final Map apiParams = { - - - }; + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - final Map apiHeaders = { - 'content-type': 'application/json', + return models.LocaleCodeList.fromMap(res.data); + } - }; + /// List continents + /// + /// List of all continents. You can use the locale header to get the data in a + /// supported language. + Future listContinents() async { + final String apiPath = '/locale/continents'; - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + final Map apiParams = {}; - return models.LocaleCodeList.fromMap(res.data); + final Map apiHeaders = { + 'content-type': 'application/json', + }; - } + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - /// List continents - /// - /// List of all continents. You can use the locale header to get the data in a - /// supported language. - Future listContinents() async { - final String apiPath = '/locale/continents'; + return models.ContinentList.fromMap(res.data); + } - final Map apiParams = { - - - }; + /// List countries + /// + /// List of all countries. You can use the locale header to get the data in a + /// supported language. + Future listCountries() async { + final String apiPath = '/locale/countries'; - final Map apiHeaders = { - 'content-type': 'application/json', + final Map apiParams = {}; - }; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - return models.ContinentList.fromMap(res.data); + 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 listCountriesEU() async { + final String apiPath = '/locale/countries/eu'; - /// List countries - /// - /// List of all countries. You can use the locale header to get the data in a - /// supported language. - Future listCountries() async { - final String apiPath = '/locale/countries'; + final Map apiParams = {}; - final Map apiParams = { - - - }; + final Map apiHeaders = { + 'content-type': 'application/json', + }; - final Map apiHeaders = { - 'content-type': 'application/json', + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - }; + return models.CountryList.fromMap(res.data); + } - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + /// 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 listCountriesPhones() async { + final String apiPath = '/locale/countries/phones'; - return models.CountryList.fromMap(res.data); + final Map apiParams = {}; - } + final Map apiHeaders = { + 'content-type': 'application/json', + }; - /// 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 listCountriesEU() async { - final String apiPath = '/locale/countries/eu'; + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - final Map apiParams = { - - - }; + return models.PhoneList.fromMap(res.data); + } - final Map apiHeaders = { - 'content-type': 'application/json', + /// 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 listCurrencies() async { + final String apiPath = '/locale/currencies'; - }; + final Map apiParams = {}; - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + final Map apiHeaders = { + 'content-type': 'application/json', + }; - return models.CountryList.fromMap(res.data); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - } + return models.CurrencyList.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 listCountriesPhones() async { - final String apiPath = '/locale/countries/phones'; + /// 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 listLanguages() async { + final String apiPath = '/locale/languages'; - final Map apiParams = { - - - }; + final Map apiParams = {}; - final Map apiHeaders = { - 'content-type': 'application/json', + final Map apiHeaders = { + 'content-type': 'application/json', + }; - }; + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - 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 listCurrencies() async { - final String apiPath = '/locale/currencies'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.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 listLanguages() async { - final String apiPath = '/locale/languages'; - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LanguageList.fromMap(res.data); - - } -} \ No newline at end of file + return models.LanguageList.fromMap(res.data); + } +} diff --git a/lib/services/messaging.dart b/lib/services/messaging.dart index e88b18f5..ecde5409 100644 --- a/lib/services/messaging.dart +++ b/lib/services/messaging.dart @@ -3,1251 +3,1374 @@ part of '../dart_appwrite.dart'; /// The Messaging service allows you to send messages to any provider type /// (SMTP, push notification, SMS, etc.). class Messaging extends Service { - Messaging(super.client); - - /// List messages - /// - /// Get a list of all messages from the current Appwrite project. - Future listMessages({List? queries, String? search}) async { - final String apiPath = '/messaging/messages'; - - final Map apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MessageList.fromMap(res.data); - - } - - /// Create email - /// - /// Create a new email message. - Future createEmail({required String messageId, required String subject, required String content, List? topics, List? users, List? targets, List? cc, List? bcc, List? attachments, bool? draft, bool? html, String? scheduledAt}) async { - final String apiPath = '/messaging/messages/email'; - - final Map apiParams = { - - 'messageId': messageId, -'subject': subject, -'content': content, -'topics': topics, -'users': users, -'targets': targets, -'cc': cc, -'bcc': bcc, -'attachments': attachments, -'draft': draft, -'html': html, -'scheduledAt': scheduledAt, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - - } - - /// Update email - /// - /// Update an email message by its unique ID. - /// - Future updateEmail({required String messageId, List? topics, List? users, List? targets, String? subject, String? content, bool? draft, bool? html, List? cc, List? bcc, String? scheduledAt, List? attachments}) async { - final String apiPath = '/messaging/messages/email/{messageId}'.replaceAll('{messageId}', messageId); - - final Map apiParams = { - - 'topics': topics, -'users': users, -'targets': targets, -'subject': subject, -'content': content, -'draft': draft, -'html': html, -'cc': cc, -'bcc': bcc, -'scheduledAt': scheduledAt, -'attachments': attachments, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - - } - - /// Create push notification - /// - /// Create a new push notification. - Future createPush({required String messageId, required String title, required String body, List? topics, List? users, List? targets, Map? data, String? action, String? image, String? icon, String? sound, String? color, String? tag, String? badge, bool? draft, String? scheduledAt}) async { - final String apiPath = '/messaging/messages/push'; - - final Map apiParams = { - - 'messageId': messageId, -'title': title, -'body': body, -'topics': topics, -'users': users, -'targets': targets, -'data': data, -'action': action, -'image': image, -'icon': icon, -'sound': sound, -'color': color, -'tag': tag, -'badge': badge, -'draft': draft, -'scheduledAt': scheduledAt, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - - } - - /// Update push notification - /// - /// Update a push notification by its unique ID. - /// - Future updatePush({required String messageId, List? topics, List? users, List? targets, String? title, String? body, Map? data, String? action, String? image, String? icon, String? sound, String? color, String? tag, int? badge, bool? draft, String? scheduledAt}) async { - final String apiPath = '/messaging/messages/push/{messageId}'.replaceAll('{messageId}', messageId); - - final Map apiParams = { - - 'topics': topics, -'users': users, -'targets': targets, -'title': title, -'body': body, -'data': data, -'action': action, -'image': image, -'icon': icon, -'sound': sound, -'color': color, -'tag': tag, -'badge': badge, -'draft': draft, -'scheduledAt': scheduledAt, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - - } - - /// Create SMS - /// - /// Create a new SMS message. - Future createSms({required String messageId, required String content, List? topics, List? users, List? targets, bool? draft, String? scheduledAt}) async { - final String apiPath = '/messaging/messages/sms'; - - final Map apiParams = { - - 'messageId': messageId, -'content': content, -'topics': topics, -'users': users, -'targets': targets, -'draft': draft, -'scheduledAt': scheduledAt, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - - } - - /// Update SMS - /// - /// Update an email message by its unique ID. - /// - Future updateSms({required String messageId, List? topics, List? users, List? targets, String? content, bool? draft, String? scheduledAt}) async { - final String apiPath = '/messaging/messages/sms/{messageId}'.replaceAll('{messageId}', messageId); - - final Map apiParams = { - - 'topics': topics, -'users': users, -'targets': targets, -'content': content, -'draft': draft, -'scheduledAt': scheduledAt, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - - } - - /// Get message - /// - /// Get a message by its unique ID. - /// - Future getMessage({required String messageId}) async { - final String apiPath = '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - - } - - /// Delete message - /// - /// Delete a message. If the message is not a draft or scheduled, but has been - /// sent, this will not recall the message. - Future delete({required String messageId}) async { - final String apiPath = '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List message logs - /// - /// Get the message activity logs listed by its unique ID. - Future listMessageLogs({required String messageId, List? queries}) async { - final String apiPath = '/messaging/messages/{messageId}/logs'.replaceAll('{messageId}', messageId); - - final Map apiParams = { - 'queries': queries, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - - } - - /// List message targets - /// - /// Get a list of the targets associated with a message. - Future listTargets({required String messageId, List? queries}) async { - final String apiPath = '/messaging/messages/{messageId}/targets'.replaceAll('{messageId}', messageId); - - final Map apiParams = { - 'queries': queries, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.TargetList.fromMap(res.data); - - } - - /// List providers - /// - /// Get a list of all providers from the current Appwrite project. - Future listProviders({List? queries, String? search}) async { - final String apiPath = '/messaging/providers'; - - final Map apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.ProviderList.fromMap(res.data); - - } - - /// Create APNS provider - /// - /// Create a new Apple Push Notification service provider. - Future createApnsProvider({required String providerId, required String name, String? authKey, String? authKeyId, String? teamId, String? bundleId, bool? sandbox, bool? enabled}) async { - final String apiPath = '/messaging/providers/apns'; - - final Map apiParams = { - - 'providerId': providerId, -'name': name, -'authKey': authKey, -'authKeyId': authKeyId, -'teamId': teamId, -'bundleId': bundleId, -'sandbox': sandbox, -'enabled': enabled, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update APNS provider - /// - /// Update a Apple Push Notification service provider by its unique ID. - Future updateApnsProvider({required String providerId, String? name, bool? enabled, String? authKey, String? authKeyId, String? teamId, String? bundleId, bool? sandbox}) async { - final String apiPath = '/messaging/providers/apns/{providerId}'.replaceAll('{providerId}', providerId); - - final Map apiParams = { - - 'name': name, -'enabled': enabled, -'authKey': authKey, -'authKeyId': authKeyId, -'teamId': teamId, -'bundleId': bundleId, -'sandbox': sandbox, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create FCM provider - /// - /// Create a new Firebase Cloud Messaging provider. - Future createFcmProvider({required String providerId, required String name, Map? serviceAccountJSON, bool? enabled}) async { - final String apiPath = '/messaging/providers/fcm'; - - final Map apiParams = { - - 'providerId': providerId, -'name': name, -'serviceAccountJSON': serviceAccountJSON, -'enabled': enabled, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update FCM provider - /// - /// Update a Firebase Cloud Messaging provider by its unique ID. - Future updateFcmProvider({required String providerId, String? name, bool? enabled, Map? serviceAccountJSON}) async { - final String apiPath = '/messaging/providers/fcm/{providerId}'.replaceAll('{providerId}', providerId); - - final Map apiParams = { - - 'name': name, -'enabled': enabled, -'serviceAccountJSON': serviceAccountJSON, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create Mailgun provider - /// - /// Create a new Mailgun provider. - Future createMailgunProvider({required String providerId, required String name, String? apiKey, String? domain, bool? isEuRegion, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { - final String apiPath = '/messaging/providers/mailgun'; - - final Map apiParams = { - - 'providerId': providerId, -'name': name, -'apiKey': apiKey, -'domain': domain, -'isEuRegion': isEuRegion, -'fromName': fromName, -'fromEmail': fromEmail, -'replyToName': replyToName, -'replyToEmail': replyToEmail, -'enabled': enabled, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update Mailgun provider - /// - /// Update a Mailgun provider by its unique ID. - Future updateMailgunProvider({required String providerId, String? name, String? apiKey, String? domain, bool? isEuRegion, bool? enabled, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail}) async { - final String apiPath = '/messaging/providers/mailgun/{providerId}'.replaceAll('{providerId}', providerId); - - final Map apiParams = { - - 'name': name, -'apiKey': apiKey, -'domain': domain, -'isEuRegion': isEuRegion, -'enabled': enabled, -'fromName': fromName, -'fromEmail': fromEmail, -'replyToName': replyToName, -'replyToEmail': replyToEmail, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create Msg91 provider - /// - /// Create a new MSG91 provider. - Future createMsg91Provider({required String providerId, required String name, String? templateId, String? senderId, String? authKey, bool? enabled}) async { - final String apiPath = '/messaging/providers/msg91'; - - final Map apiParams = { - - 'providerId': providerId, -'name': name, -'templateId': templateId, -'senderId': senderId, -'authKey': authKey, -'enabled': enabled, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update Msg91 provider - /// - /// Update a MSG91 provider by its unique ID. - Future updateMsg91Provider({required String providerId, String? name, bool? enabled, String? templateId, String? senderId, String? authKey}) async { - final String apiPath = '/messaging/providers/msg91/{providerId}'.replaceAll('{providerId}', providerId); - - final Map apiParams = { - - 'name': name, -'enabled': enabled, -'templateId': templateId, -'senderId': senderId, -'authKey': authKey, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create Sendgrid provider - /// - /// Create a new Sendgrid provider. - Future createSendgridProvider({required String providerId, required String name, String? apiKey, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { - final String apiPath = '/messaging/providers/sendgrid'; - - final Map apiParams = { - - 'providerId': providerId, -'name': name, -'apiKey': apiKey, -'fromName': fromName, -'fromEmail': fromEmail, -'replyToName': replyToName, -'replyToEmail': replyToEmail, -'enabled': enabled, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update Sendgrid provider - /// - /// Update a Sendgrid provider by its unique ID. - Future updateSendgridProvider({required String providerId, String? name, bool? enabled, String? apiKey, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail}) async { - final String apiPath = '/messaging/providers/sendgrid/{providerId}'.replaceAll('{providerId}', providerId); - - final Map apiParams = { - - 'name': name, -'enabled': enabled, -'apiKey': apiKey, -'fromName': fromName, -'fromEmail': fromEmail, -'replyToName': replyToName, -'replyToEmail': replyToEmail, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create SMTP provider - /// - /// Create a new SMTP provider. - Future createSmtpProvider({required String providerId, required String name, required String host, int? port, String? username, String? password, enums.SmtpEncryption? encryption, bool? autoTLS, String? mailer, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { - final String apiPath = '/messaging/providers/smtp'; - - final Map apiParams = { - - 'providerId': providerId, -'name': name, -'host': host, -'port': port, -'username': username, -'password': password, -'encryption': encryption?.value, -'autoTLS': autoTLS, -'mailer': mailer, -'fromName': fromName, -'fromEmail': fromEmail, -'replyToName': replyToName, -'replyToEmail': replyToEmail, -'enabled': enabled, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update SMTP provider - /// - /// Update a SMTP provider by its unique ID. - Future updateSmtpProvider({required String providerId, String? name, String? host, int? port, String? username, String? password, enums.SmtpEncryption? encryption, bool? autoTLS, String? mailer, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { - final String apiPath = '/messaging/providers/smtp/{providerId}'.replaceAll('{providerId}', providerId); - - final Map apiParams = { - - 'name': name, -'host': host, -'port': port, -'username': username, -'password': password, -'encryption': encryption?.value, -'autoTLS': autoTLS, -'mailer': mailer, -'fromName': fromName, -'fromEmail': fromEmail, -'replyToName': replyToName, -'replyToEmail': replyToEmail, -'enabled': enabled, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create Telesign provider - /// - /// Create a new Telesign provider. - Future createTelesignProvider({required String providerId, required String name, String? from, String? customerId, String? apiKey, bool? enabled}) async { - final String apiPath = '/messaging/providers/telesign'; - - final Map apiParams = { - - 'providerId': providerId, -'name': name, -'from': from, -'customerId': customerId, -'apiKey': apiKey, -'enabled': enabled, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update Telesign provider - /// - /// Update a Telesign provider by its unique ID. - Future updateTelesignProvider({required String providerId, String? name, bool? enabled, String? customerId, String? apiKey, String? from}) async { - final String apiPath = '/messaging/providers/telesign/{providerId}'.replaceAll('{providerId}', providerId); - - final Map apiParams = { - - 'name': name, -'enabled': enabled, -'customerId': customerId, -'apiKey': apiKey, -'from': from, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create Textmagic provider - /// - /// Create a new Textmagic provider. - Future createTextmagicProvider({required String providerId, required String name, String? from, String? username, String? apiKey, bool? enabled}) async { - final String apiPath = '/messaging/providers/textmagic'; - - final Map apiParams = { - - 'providerId': providerId, -'name': name, -'from': from, -'username': username, -'apiKey': apiKey, -'enabled': enabled, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update Textmagic provider - /// - /// Update a Textmagic provider by its unique ID. - Future updateTextmagicProvider({required String providerId, String? name, bool? enabled, String? username, String? apiKey, String? from}) async { - final String apiPath = '/messaging/providers/textmagic/{providerId}'.replaceAll('{providerId}', providerId); - - final Map apiParams = { - - 'name': name, -'enabled': enabled, -'username': username, -'apiKey': apiKey, -'from': from, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create Twilio provider - /// - /// Create a new Twilio provider. - Future createTwilioProvider({required String providerId, required String name, String? from, String? accountSid, String? authToken, bool? enabled}) async { - final String apiPath = '/messaging/providers/twilio'; - - final Map apiParams = { - - 'providerId': providerId, -'name': name, -'from': from, -'accountSid': accountSid, -'authToken': authToken, -'enabled': enabled, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update Twilio provider - /// - /// Update a Twilio provider by its unique ID. - Future updateTwilioProvider({required String providerId, String? name, bool? enabled, String? accountSid, String? authToken, String? from}) async { - final String apiPath = '/messaging/providers/twilio/{providerId}'.replaceAll('{providerId}', providerId); - - final Map apiParams = { - - 'name': name, -'enabled': enabled, -'accountSid': accountSid, -'authToken': authToken, -'from': from, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create Vonage provider - /// - /// Create a new Vonage provider. - Future createVonageProvider({required String providerId, required String name, String? from, String? apiKey, String? apiSecret, bool? enabled}) async { - final String apiPath = '/messaging/providers/vonage'; - - final Map apiParams = { - - 'providerId': providerId, -'name': name, -'from': from, -'apiKey': apiKey, -'apiSecret': apiSecret, -'enabled': enabled, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update Vonage provider - /// - /// Update a Vonage provider by its unique ID. - Future updateVonageProvider({required String providerId, String? name, bool? enabled, String? apiKey, String? apiSecret, String? from}) async { - final String apiPath = '/messaging/providers/vonage/{providerId}'.replaceAll('{providerId}', providerId); - - final Map apiParams = { - - 'name': name, -'enabled': enabled, -'apiKey': apiKey, -'apiSecret': apiSecret, -'from': from, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Get provider - /// - /// Get a provider by its unique ID. - /// - Future getProvider({required String providerId}) async { - final String apiPath = '/messaging/providers/{providerId}'.replaceAll('{providerId}', providerId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Delete provider - /// - /// Delete a provider by its unique ID. - Future deleteProvider({required String providerId}) async { - final String apiPath = '/messaging/providers/{providerId}'.replaceAll('{providerId}', providerId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List provider logs - /// - /// Get the provider activity logs listed by its unique ID. - Future listProviderLogs({required String providerId, List? queries}) async { - final String apiPath = '/messaging/providers/{providerId}/logs'.replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'queries': queries, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - - } - - /// List subscriber logs - /// - /// Get the subscriber activity logs listed by its unique ID. - Future listSubscriberLogs({required String subscriberId, List? queries}) async { - final String apiPath = '/messaging/subscribers/{subscriberId}/logs'.replaceAll('{subscriberId}', subscriberId); - - final Map apiParams = { - 'queries': queries, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - - } - - /// List topics - /// - /// Get a list of all topics from the current Appwrite project. - Future listTopics({List? queries, String? search}) async { - final String apiPath = '/messaging/topics'; - - final Map apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.TopicList.fromMap(res.data); - - } - - /// Create topic - /// - /// Create a new topic. - Future createTopic({required String topicId, required String name, List? subscribe}) async { - final String apiPath = '/messaging/topics'; - - final Map apiParams = { - - 'topicId': topicId, -'name': name, -'subscribe': subscribe, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Topic.fromMap(res.data); - - } - - /// Get topic - /// - /// Get a topic by its unique ID. - /// - Future getTopic({required String topicId}) async { - final String apiPath = '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Topic.fromMap(res.data); - - } - - /// Update topic - /// - /// Update a topic by its unique ID. - /// - Future updateTopic({required String topicId, String? name, List? subscribe}) async { - final String apiPath = '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); - - final Map apiParams = { - - 'name': name, -'subscribe': subscribe, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Topic.fromMap(res.data); - - } - - /// Delete topic - /// - /// Delete a topic by its unique ID. - Future deleteTopic({required String topicId}) async { - final String apiPath = '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List topic logs - /// - /// Get the topic activity logs listed by its unique ID. - Future listTopicLogs({required String topicId, List? queries}) async { - final String apiPath = '/messaging/topics/{topicId}/logs'.replaceAll('{topicId}', topicId); - - final Map apiParams = { - 'queries': queries, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - - } - - /// List subscribers - /// - /// Get a list of all subscribers from the current Appwrite project. - Future listSubscribers({required String topicId, List? queries, String? search}) async { - final String apiPath = '/messaging/topics/{topicId}/subscribers'.replaceAll('{topicId}', topicId); - - final Map apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SubscriberList.fromMap(res.data); - - } - - /// Create subscriber - /// - /// Create a new subscriber. - Future createSubscriber({required String topicId, required String subscriberId, required String targetId}) async { - final String apiPath = '/messaging/topics/{topicId}/subscribers'.replaceAll('{topicId}', topicId); - - final Map apiParams = { - - 'subscriberId': subscriberId, -'targetId': targetId, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Subscriber.fromMap(res.data); - - } - - /// Get subscriber - /// - /// Get a subscriber by its unique ID. - /// - Future getSubscriber({required String topicId, required String subscriberId}) async { - final String apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replaceAll('{topicId}', topicId).replaceAll('{subscriberId}', subscriberId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Subscriber.fromMap(res.data); - - } - - /// Delete subscriber - /// - /// Delete a subscriber by its unique ID. - Future deleteSubscriber({required String topicId, required String subscriberId}) async { - final String apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replaceAll('{topicId}', topicId).replaceAll('{subscriberId}', subscriberId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } -} \ No newline at end of file + Messaging(super.client); + + /// List messages + /// + /// Get a list of all messages from the current Appwrite project. + Future listMessages( + {List? queries, String? search}) async { + final String apiPath = '/messaging/messages'; + + final Map apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MessageList.fromMap(res.data); + } + + /// Create email + /// + /// Create a new email message. + Future createEmail( + {required String messageId, + required String subject, + required String content, + List? topics, + List? users, + List? targets, + List? cc, + List? bcc, + List? attachments, + bool? draft, + bool? html, + String? scheduledAt}) async { + final String apiPath = '/messaging/messages/email'; + + final Map apiParams = { + 'messageId': messageId, + 'subject': subject, + 'content': content, + 'topics': topics, + 'users': users, + 'targets': targets, + 'cc': cc, + 'bcc': bcc, + 'attachments': attachments, + 'draft': draft, + 'html': html, + 'scheduledAt': scheduledAt, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + } + + /// Update email + /// + /// Update an email message by its unique ID. + /// + Future updateEmail( + {required String messageId, + List? topics, + List? users, + List? targets, + String? subject, + String? content, + bool? draft, + bool? html, + List? cc, + List? bcc, + String? scheduledAt, + List? attachments}) async { + final String apiPath = '/messaging/messages/email/{messageId}' + .replaceAll('{messageId}', messageId); + + final Map apiParams = { + 'topics': topics, + 'users': users, + 'targets': targets, + 'subject': subject, + 'content': content, + 'draft': draft, + 'html': html, + 'cc': cc, + 'bcc': bcc, + 'scheduledAt': scheduledAt, + 'attachments': attachments, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + } + + /// Create push notification + /// + /// Create a new push notification. + Future createPush( + {required String messageId, + required String title, + required String body, + List? topics, + List? users, + List? targets, + Map? data, + String? action, + String? image, + String? icon, + String? sound, + String? color, + String? tag, + String? badge, + bool? draft, + String? scheduledAt}) async { + final String apiPath = '/messaging/messages/push'; + + final Map apiParams = { + 'messageId': messageId, + 'title': title, + 'body': body, + 'topics': topics, + 'users': users, + 'targets': targets, + 'data': data, + 'action': action, + 'image': image, + 'icon': icon, + 'sound': sound, + 'color': color, + 'tag': tag, + 'badge': badge, + 'draft': draft, + 'scheduledAt': scheduledAt, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + } + + /// Update push notification + /// + /// Update a push notification by its unique ID. + /// + Future updatePush( + {required String messageId, + List? topics, + List? users, + List? targets, + String? title, + String? body, + Map? data, + String? action, + String? image, + String? icon, + String? sound, + String? color, + String? tag, + int? badge, + bool? draft, + String? scheduledAt}) async { + final String apiPath = '/messaging/messages/push/{messageId}' + .replaceAll('{messageId}', messageId); + + final Map apiParams = { + 'topics': topics, + 'users': users, + 'targets': targets, + 'title': title, + 'body': body, + 'data': data, + 'action': action, + 'image': image, + 'icon': icon, + 'sound': sound, + 'color': color, + 'tag': tag, + 'badge': badge, + 'draft': draft, + 'scheduledAt': scheduledAt, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + } + + /// Create SMS + /// + /// Create a new SMS message. + Future createSms( + {required String messageId, + required String content, + List? topics, + List? users, + List? targets, + bool? draft, + String? scheduledAt}) async { + final String apiPath = '/messaging/messages/sms'; + + final Map apiParams = { + 'messageId': messageId, + 'content': content, + 'topics': topics, + 'users': users, + 'targets': targets, + 'draft': draft, + 'scheduledAt': scheduledAt, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + } + + /// Update SMS + /// + /// Update an email message by its unique ID. + /// + Future updateSms( + {required String messageId, + List? topics, + List? users, + List? targets, + String? content, + bool? draft, + String? scheduledAt}) async { + final String apiPath = '/messaging/messages/sms/{messageId}' + .replaceAll('{messageId}', messageId); + + final Map apiParams = { + 'topics': topics, + 'users': users, + 'targets': targets, + 'content': content, + 'draft': draft, + 'scheduledAt': scheduledAt, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + } + + /// Get message + /// + /// Get a message by its unique ID. + /// + Future getMessage({required String messageId}) async { + final String apiPath = + '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + } + + /// Delete message + /// + /// Delete a message. If the message is not a draft or scheduled, but has been + /// sent, this will not recall the message. + Future delete({required String messageId}) async { + final String apiPath = + '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List message logs + /// + /// Get the message activity logs listed by its unique ID. + Future listMessageLogs( + {required String messageId, List? queries}) async { + final String apiPath = '/messaging/messages/{messageId}/logs' + .replaceAll('{messageId}', messageId); + + final Map apiParams = { + 'queries': queries, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + } + + /// List message targets + /// + /// Get a list of the targets associated with a message. + Future listTargets( + {required String messageId, List? queries}) async { + final String apiPath = '/messaging/messages/{messageId}/targets' + .replaceAll('{messageId}', messageId); + + final Map apiParams = { + 'queries': queries, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.TargetList.fromMap(res.data); + } + + /// List providers + /// + /// Get a list of all providers from the current Appwrite project. + Future listProviders( + {List? queries, String? search}) async { + final String apiPath = '/messaging/providers'; + + final Map apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.ProviderList.fromMap(res.data); + } + + /// Create APNS provider + /// + /// Create a new Apple Push Notification service provider. + Future createApnsProvider( + {required String providerId, + required String name, + String? authKey, + String? authKeyId, + String? teamId, + String? bundleId, + bool? sandbox, + bool? enabled}) async { + final String apiPath = '/messaging/providers/apns'; + + final Map apiParams = { + 'providerId': providerId, + 'name': name, + 'authKey': authKey, + 'authKeyId': authKeyId, + 'teamId': teamId, + 'bundleId': bundleId, + 'sandbox': sandbox, + 'enabled': enabled, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update APNS provider + /// + /// Update a Apple Push Notification service provider by its unique ID. + Future updateApnsProvider( + {required String providerId, + String? name, + bool? enabled, + String? authKey, + String? authKeyId, + String? teamId, + String? bundleId, + bool? sandbox}) async { + final String apiPath = '/messaging/providers/apns/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map apiParams = { + 'name': name, + 'enabled': enabled, + 'authKey': authKey, + 'authKeyId': authKeyId, + 'teamId': teamId, + 'bundleId': bundleId, + 'sandbox': sandbox, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create FCM provider + /// + /// Create a new Firebase Cloud Messaging provider. + Future createFcmProvider( + {required String providerId, + required String name, + Map? serviceAccountJSON, + bool? enabled}) async { + final String apiPath = '/messaging/providers/fcm'; + + final Map apiParams = { + 'providerId': providerId, + 'name': name, + 'serviceAccountJSON': serviceAccountJSON, + 'enabled': enabled, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update FCM provider + /// + /// Update a Firebase Cloud Messaging provider by its unique ID. + Future updateFcmProvider( + {required String providerId, + String? name, + bool? enabled, + Map? serviceAccountJSON}) async { + final String apiPath = '/messaging/providers/fcm/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map apiParams = { + 'name': name, + 'enabled': enabled, + 'serviceAccountJSON': serviceAccountJSON, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create Mailgun provider + /// + /// Create a new Mailgun provider. + Future createMailgunProvider( + {required String providerId, + required String name, + String? apiKey, + String? domain, + bool? isEuRegion, + String? fromName, + String? fromEmail, + String? replyToName, + String? replyToEmail, + bool? enabled}) async { + final String apiPath = '/messaging/providers/mailgun'; + + final Map apiParams = { + 'providerId': providerId, + 'name': name, + 'apiKey': apiKey, + 'domain': domain, + 'isEuRegion': isEuRegion, + 'fromName': fromName, + 'fromEmail': fromEmail, + 'replyToName': replyToName, + 'replyToEmail': replyToEmail, + 'enabled': enabled, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update Mailgun provider + /// + /// Update a Mailgun provider by its unique ID. + Future updateMailgunProvider( + {required String providerId, + String? name, + String? apiKey, + String? domain, + bool? isEuRegion, + bool? enabled, + String? fromName, + String? fromEmail, + String? replyToName, + String? replyToEmail}) async { + final String apiPath = '/messaging/providers/mailgun/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map apiParams = { + 'name': name, + 'apiKey': apiKey, + 'domain': domain, + 'isEuRegion': isEuRegion, + 'enabled': enabled, + 'fromName': fromName, + 'fromEmail': fromEmail, + 'replyToName': replyToName, + 'replyToEmail': replyToEmail, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create Msg91 provider + /// + /// Create a new MSG91 provider. + Future createMsg91Provider( + {required String providerId, + required String name, + String? templateId, + String? senderId, + String? authKey, + bool? enabled}) async { + final String apiPath = '/messaging/providers/msg91'; + + final Map apiParams = { + 'providerId': providerId, + 'name': name, + 'templateId': templateId, + 'senderId': senderId, + 'authKey': authKey, + 'enabled': enabled, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update Msg91 provider + /// + /// Update a MSG91 provider by its unique ID. + Future updateMsg91Provider( + {required String providerId, + String? name, + bool? enabled, + String? templateId, + String? senderId, + String? authKey}) async { + final String apiPath = '/messaging/providers/msg91/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map apiParams = { + 'name': name, + 'enabled': enabled, + 'templateId': templateId, + 'senderId': senderId, + 'authKey': authKey, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create Sendgrid provider + /// + /// Create a new Sendgrid provider. + Future createSendgridProvider( + {required String providerId, + required String name, + String? apiKey, + String? fromName, + String? fromEmail, + String? replyToName, + String? replyToEmail, + bool? enabled}) async { + final String apiPath = '/messaging/providers/sendgrid'; + + final Map apiParams = { + 'providerId': providerId, + 'name': name, + 'apiKey': apiKey, + 'fromName': fromName, + 'fromEmail': fromEmail, + 'replyToName': replyToName, + 'replyToEmail': replyToEmail, + 'enabled': enabled, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update Sendgrid provider + /// + /// Update a Sendgrid provider by its unique ID. + Future updateSendgridProvider( + {required String providerId, + String? name, + bool? enabled, + String? apiKey, + String? fromName, + String? fromEmail, + String? replyToName, + String? replyToEmail}) async { + final String apiPath = '/messaging/providers/sendgrid/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map apiParams = { + 'name': name, + 'enabled': enabled, + 'apiKey': apiKey, + 'fromName': fromName, + 'fromEmail': fromEmail, + 'replyToName': replyToName, + 'replyToEmail': replyToEmail, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create SMTP provider + /// + /// Create a new SMTP provider. + Future createSmtpProvider( + {required String providerId, + required String name, + required String host, + int? port, + String? username, + String? password, + enums.SmtpEncryption? encryption, + bool? autoTLS, + String? mailer, + String? fromName, + String? fromEmail, + String? replyToName, + String? replyToEmail, + bool? enabled}) async { + final String apiPath = '/messaging/providers/smtp'; + + final Map apiParams = { + 'providerId': providerId, + 'name': name, + 'host': host, + 'port': port, + 'username': username, + 'password': password, + 'encryption': encryption?.value, + 'autoTLS': autoTLS, + 'mailer': mailer, + 'fromName': fromName, + 'fromEmail': fromEmail, + 'replyToName': replyToName, + 'replyToEmail': replyToEmail, + 'enabled': enabled, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update SMTP provider + /// + /// Update a SMTP provider by its unique ID. + Future updateSmtpProvider( + {required String providerId, + String? name, + String? host, + int? port, + String? username, + String? password, + enums.SmtpEncryption? encryption, + bool? autoTLS, + String? mailer, + String? fromName, + String? fromEmail, + String? replyToName, + String? replyToEmail, + bool? enabled}) async { + final String apiPath = '/messaging/providers/smtp/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map apiParams = { + 'name': name, + 'host': host, + 'port': port, + 'username': username, + 'password': password, + 'encryption': encryption?.value, + 'autoTLS': autoTLS, + 'mailer': mailer, + 'fromName': fromName, + 'fromEmail': fromEmail, + 'replyToName': replyToName, + 'replyToEmail': replyToEmail, + 'enabled': enabled, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create Telesign provider + /// + /// Create a new Telesign provider. + Future createTelesignProvider( + {required String providerId, + required String name, + String? from, + String? customerId, + String? apiKey, + bool? enabled}) async { + final String apiPath = '/messaging/providers/telesign'; + + final Map apiParams = { + 'providerId': providerId, + 'name': name, + 'from': from, + 'customerId': customerId, + 'apiKey': apiKey, + 'enabled': enabled, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update Telesign provider + /// + /// Update a Telesign provider by its unique ID. + Future updateTelesignProvider( + {required String providerId, + String? name, + bool? enabled, + String? customerId, + String? apiKey, + String? from}) async { + final String apiPath = '/messaging/providers/telesign/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map apiParams = { + 'name': name, + 'enabled': enabled, + 'customerId': customerId, + 'apiKey': apiKey, + 'from': from, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create Textmagic provider + /// + /// Create a new Textmagic provider. + Future createTextmagicProvider( + {required String providerId, + required String name, + String? from, + String? username, + String? apiKey, + bool? enabled}) async { + final String apiPath = '/messaging/providers/textmagic'; + + final Map apiParams = { + 'providerId': providerId, + 'name': name, + 'from': from, + 'username': username, + 'apiKey': apiKey, + 'enabled': enabled, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update Textmagic provider + /// + /// Update a Textmagic provider by its unique ID. + Future updateTextmagicProvider( + {required String providerId, + String? name, + bool? enabled, + String? username, + String? apiKey, + String? from}) async { + final String apiPath = '/messaging/providers/textmagic/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map apiParams = { + 'name': name, + 'enabled': enabled, + 'username': username, + 'apiKey': apiKey, + 'from': from, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create Twilio provider + /// + /// Create a new Twilio provider. + Future createTwilioProvider( + {required String providerId, + required String name, + String? from, + String? accountSid, + String? authToken, + bool? enabled}) async { + final String apiPath = '/messaging/providers/twilio'; + + final Map apiParams = { + 'providerId': providerId, + 'name': name, + 'from': from, + 'accountSid': accountSid, + 'authToken': authToken, + 'enabled': enabled, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update Twilio provider + /// + /// Update a Twilio provider by its unique ID. + Future updateTwilioProvider( + {required String providerId, + String? name, + bool? enabled, + String? accountSid, + String? authToken, + String? from}) async { + final String apiPath = '/messaging/providers/twilio/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map apiParams = { + 'name': name, + 'enabled': enabled, + 'accountSid': accountSid, + 'authToken': authToken, + 'from': from, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create Vonage provider + /// + /// Create a new Vonage provider. + Future createVonageProvider( + {required String providerId, + required String name, + String? from, + String? apiKey, + String? apiSecret, + bool? enabled}) async { + final String apiPath = '/messaging/providers/vonage'; + + final Map apiParams = { + 'providerId': providerId, + 'name': name, + 'from': from, + 'apiKey': apiKey, + 'apiSecret': apiSecret, + 'enabled': enabled, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update Vonage provider + /// + /// Update a Vonage provider by its unique ID. + Future updateVonageProvider( + {required String providerId, + String? name, + bool? enabled, + String? apiKey, + String? apiSecret, + String? from}) async { + final String apiPath = '/messaging/providers/vonage/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map apiParams = { + 'name': name, + 'enabled': enabled, + 'apiKey': apiKey, + 'apiSecret': apiSecret, + 'from': from, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Get provider + /// + /// Get a provider by its unique ID. + /// + Future getProvider({required String providerId}) async { + final String apiPath = '/messaging/providers/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Delete provider + /// + /// Delete a provider by its unique ID. + Future deleteProvider({required String providerId}) async { + final String apiPath = '/messaging/providers/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List provider logs + /// + /// Get the provider activity logs listed by its unique ID. + Future listProviderLogs( + {required String providerId, List? queries}) async { + final String apiPath = '/messaging/providers/{providerId}/logs' + .replaceAll('{providerId}', providerId); + + final Map apiParams = { + 'queries': queries, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + } + + /// List subscriber logs + /// + /// Get the subscriber activity logs listed by its unique ID. + Future listSubscriberLogs( + {required String subscriberId, List? queries}) async { + final String apiPath = '/messaging/subscribers/{subscriberId}/logs' + .replaceAll('{subscriberId}', subscriberId); + + final Map apiParams = { + 'queries': queries, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + } + + /// List topics + /// + /// Get a list of all topics from the current Appwrite project. + Future listTopics( + {List? queries, String? search}) async { + final String apiPath = '/messaging/topics'; + + final Map apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.TopicList.fromMap(res.data); + } + + /// Create topic + /// + /// Create a new topic. + Future createTopic( + {required String topicId, + required String name, + List? subscribe}) async { + final String apiPath = '/messaging/topics'; + + final Map apiParams = { + 'topicId': topicId, + 'name': name, + 'subscribe': subscribe, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Topic.fromMap(res.data); + } + + /// Get topic + /// + /// Get a topic by its unique ID. + /// + Future getTopic({required String topicId}) async { + final String apiPath = + '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Topic.fromMap(res.data); + } + + /// Update topic + /// + /// Update a topic by its unique ID. + /// + Future updateTopic( + {required String topicId, String? name, List? subscribe}) async { + final String apiPath = + '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); + + final Map apiParams = { + 'name': name, + 'subscribe': subscribe, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Topic.fromMap(res.data); + } + + /// Delete topic + /// + /// Delete a topic by its unique ID. + Future deleteTopic({required String topicId}) async { + final String apiPath = + '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List topic logs + /// + /// Get the topic activity logs listed by its unique ID. + Future listTopicLogs( + {required String topicId, List? queries}) async { + final String apiPath = + '/messaging/topics/{topicId}/logs'.replaceAll('{topicId}', topicId); + + final Map apiParams = { + 'queries': queries, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + } + + /// List subscribers + /// + /// Get a list of all subscribers from the current Appwrite project. + Future listSubscribers( + {required String topicId, List? queries, String? search}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers' + .replaceAll('{topicId}', topicId); + + final Map apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SubscriberList.fromMap(res.data); + } + + /// Create subscriber + /// + /// Create a new subscriber. + Future createSubscriber( + {required String topicId, + required String subscriberId, + required String targetId}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers' + .replaceAll('{topicId}', topicId); + + final Map apiParams = { + 'subscriberId': subscriberId, + 'targetId': targetId, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Subscriber.fromMap(res.data); + } + + /// Get subscriber + /// + /// Get a subscriber by its unique ID. + /// + Future getSubscriber( + {required String topicId, required String subscriberId}) async { + final String apiPath = + '/messaging/topics/{topicId}/subscribers/{subscriberId}' + .replaceAll('{topicId}', topicId) + .replaceAll('{subscriberId}', subscriberId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Subscriber.fromMap(res.data); + } + + /// Delete subscriber + /// + /// Delete a subscriber by its unique ID. + Future deleteSubscriber( + {required String topicId, required String subscriberId}) async { + final String apiPath = + '/messaging/topics/{topicId}/subscribers/{subscriberId}' + .replaceAll('{topicId}', topicId) + .replaceAll('{subscriberId}', subscriberId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } +} diff --git a/lib/services/storage.dart b/lib/services/storage.dart index 6ffbeafe..14354786 100644 --- a/lib/services/storage.dart +++ b/lib/services/storage.dart @@ -2,356 +2,382 @@ part of '../dart_appwrite.dart'; /// The Storage service allows you to manage your project files. class Storage extends Service { - Storage(super.client); - - /// List buckets - /// - /// Get a list of all the storage buckets. You can use the query params to - /// filter your results. - Future listBuckets({List? queries, String? search}) async { - final String apiPath = '/storage/buckets'; - - final Map apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.BucketList.fromMap(res.data); - - } - - /// Create bucket - /// - /// Create a new storage bucket. - Future createBucket({required String bucketId, required String name, List? permissions, bool? fileSecurity, bool? enabled, int? maximumFileSize, List? allowedFileExtensions, enums.Compression? compression, bool? encryption, bool? antivirus}) async { - final String apiPath = '/storage/buckets'; - - final Map apiParams = { - - 'bucketId': bucketId, -'name': name, -'permissions': permissions, -'fileSecurity': fileSecurity, -'enabled': enabled, -'maximumFileSize': maximumFileSize, -'allowedFileExtensions': allowedFileExtensions, -'compression': compression?.value, -'encryption': encryption, -'antivirus': antivirus, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Bucket.fromMap(res.data); - - } - - /// Get bucket - /// - /// Get a storage bucket by its unique ID. This endpoint response returns a - /// JSON object with the storage bucket metadata. - Future getBucket({required String bucketId}) async { - final String apiPath = '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Bucket.fromMap(res.data); - - } - - /// Update bucket - /// - /// Update a storage bucket by its unique ID. - Future updateBucket({required String bucketId, required String name, List? permissions, bool? fileSecurity, bool? enabled, int? maximumFileSize, List? allowedFileExtensions, enums.Compression? compression, bool? encryption, bool? antivirus}) async { - final String apiPath = '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); - - final Map apiParams = { - - 'name': name, -'permissions': permissions, -'fileSecurity': fileSecurity, -'enabled': enabled, -'maximumFileSize': maximumFileSize, -'allowedFileExtensions': allowedFileExtensions, -'compression': compression?.value, -'encryption': encryption, -'antivirus': antivirus, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Bucket.fromMap(res.data); - - } - - /// Delete bucket - /// - /// Delete a storage bucket by its unique ID. - Future deleteBucket({required String bucketId}) async { - final String apiPath = '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List files - /// - /// Get a list of all the user files. You can use the query params to filter - /// your results. - Future listFiles({required String bucketId, List? queries, String? search}) async { - final String apiPath = '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); - - final Map apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - 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](https://appwrite.io/docs/server/storage#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 Payload file, List? permissions, Function(UploadProgress)? onProgress}) async { - final String apiPath = '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); - - final Map apiParams = { - - 'fileId': fileId, -'file': file, -'permissions': permissions, - - }; - - final Map apiHeaders = { - 'content-type': 'multipart/form-data', - - }; - - String idParamName = ''; - idParamName = 'fileId'; - final paramName = 'file'; - final res = await client.chunkedUpload( - path: apiPath, - params: apiParams, - paramName: paramName, - idParamName: idParamName, - headers: apiHeaders, - onProgress: onProgress, - ); - - 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 { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.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, String? name, List? permissions}) async { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); - - final Map apiParams = { - - 'name': name, -'permissions': permissions, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// 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 apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); - - final Map params = { - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, 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, enums.ImageGravity? gravity, int? quality, int? borderWidth, String? borderColor, int? borderRadius, double? opacity, int? rotation, String? background, enums.ImageFormat? output}) async { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); - - final Map params = { - 'width': width, -'height': height, -'gravity': gravity?.value, -'quality': quality, -'borderWidth': borderWidth, -'borderColor': borderColor, -'borderRadius': borderRadius, -'opacity': opacity, -'rotation': rotation, -'background': background, -'output': output?.value, - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, 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 { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); - - final Map params = { - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: params, responseType: ResponseType.bytes); - return res.data; - } -} \ No newline at end of file + Storage(super.client); + + /// List buckets + /// + /// Get a list of all the storage buckets. You can use the query params to + /// filter your results. + Future listBuckets( + {List? queries, String? search}) async { + final String apiPath = '/storage/buckets'; + + final Map apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.BucketList.fromMap(res.data); + } + + /// Create bucket + /// + /// Create a new storage bucket. + Future createBucket( + {required String bucketId, + required String name, + List? permissions, + bool? fileSecurity, + bool? enabled, + int? maximumFileSize, + List? allowedFileExtensions, + enums.Compression? compression, + bool? encryption, + bool? antivirus}) async { + final String apiPath = '/storage/buckets'; + + final Map apiParams = { + 'bucketId': bucketId, + 'name': name, + 'permissions': permissions, + 'fileSecurity': fileSecurity, + 'enabled': enabled, + 'maximumFileSize': maximumFileSize, + 'allowedFileExtensions': allowedFileExtensions, + 'compression': compression?.value, + 'encryption': encryption, + 'antivirus': antivirus, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Bucket.fromMap(res.data); + } + + /// Get bucket + /// + /// Get a storage bucket by its unique ID. This endpoint response returns a + /// JSON object with the storage bucket metadata. + Future getBucket({required String bucketId}) async { + final String apiPath = + '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Bucket.fromMap(res.data); + } + + /// Update bucket + /// + /// Update a storage bucket by its unique ID. + Future updateBucket( + {required String bucketId, + required String name, + List? permissions, + bool? fileSecurity, + bool? enabled, + int? maximumFileSize, + List? allowedFileExtensions, + enums.Compression? compression, + bool? encryption, + bool? antivirus}) async { + final String apiPath = + '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); + + final Map apiParams = { + 'name': name, + 'permissions': permissions, + 'fileSecurity': fileSecurity, + 'enabled': enabled, + 'maximumFileSize': maximumFileSize, + 'allowedFileExtensions': allowedFileExtensions, + 'compression': compression?.value, + 'encryption': encryption, + 'antivirus': antivirus, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Bucket.fromMap(res.data); + } + + /// Delete bucket + /// + /// Delete a storage bucket by its unique ID. + Future deleteBucket({required String bucketId}) async { + final String apiPath = + '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List files + /// + /// Get a list of all the user files. You can use the query params to filter + /// your results. + Future listFiles( + {required String bucketId, List? queries, String? search}) async { + final String apiPath = + '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); + + final Map apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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](https://appwrite.io/docs/server/storage#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 Payload file, + List? permissions, + Function(UploadProgress)? onProgress}) async { + final String apiPath = + '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); + + final Map apiParams = { + 'fileId': fileId, + 'file': file, + 'permissions': permissions, + }; + + final Map apiHeaders = { + 'content-type': 'multipart/form-data', + }; + + String idParamName = ''; + idParamName = 'fileId'; + final paramName = 'file'; + final res = await client.chunkedUpload( + path: apiPath, + params: apiParams, + paramName: paramName, + idParamName: idParamName, + headers: apiHeaders, + onProgress: onProgress, + ); + + 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 { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}' + .replaceAll('{bucketId}', bucketId) + .replaceAll('{fileId}', fileId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.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, + String? name, + List? permissions}) async { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}' + .replaceAll('{bucketId}', bucketId) + .replaceAll('{fileId}', fileId); + + final Map apiParams = { + 'name': name, + 'permissions': permissions, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}' + .replaceAll('{bucketId}', bucketId) + .replaceAll('{fileId}', fileId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// 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 apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download' + .replaceAll('{bucketId}', bucketId) + .replaceAll('{fileId}', fileId); + + final Map params = { + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, 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, + enums.ImageGravity? gravity, + int? quality, + int? borderWidth, + String? borderColor, + int? borderRadius, + double? opacity, + int? rotation, + String? background, + enums.ImageFormat? output}) async { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview' + .replaceAll('{bucketId}', bucketId) + .replaceAll('{fileId}', fileId); + + final Map params = { + 'width': width, + 'height': height, + 'gravity': gravity?.value, + 'quality': quality, + 'borderWidth': borderWidth, + 'borderColor': borderColor, + 'borderRadius': borderRadius, + 'opacity': opacity, + 'rotation': rotation, + 'background': background, + 'output': output?.value, + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, 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 { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view' + .replaceAll('{bucketId}', bucketId) + .replaceAll('{fileId}', fileId); + + final Map params = { + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: params, responseType: ResponseType.bytes); + return res.data; + } +} diff --git a/lib/services/teams.dart b/lib/services/teams.dart index 4d7ee475..27f5aff5 100644 --- a/lib/services/teams.dart +++ b/lib/services/teams.dart @@ -3,350 +3,340 @@ part of '../dart_appwrite.dart'; /// 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(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. - Future list({List? queries, String? search}) async { - final String apiPath = '/teams'; - - final Map apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams'; - - final Map apiParams = { - - 'teamId': teamId, -'name': name, -'roles': roles, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Team.fromMap(res.data); - - } - - /// Update name - /// - /// Update the team's name by its unique ID. - Future updateName({required String teamId, required String name}) async { - final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); - - final Map apiParams = { - - 'name': name, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List 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 listMemberships({required String teamId, List? queries, String? search}) async { - final String apiPath = '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); - - final Map apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MembershipList.fromMap(res.data); - - } - - /// Create team membership - /// - /// Invite a new member to join your team. Provide an ID for existing users, or - /// invite unregistered users using an email or phone number. If initiated from - /// a Client SDK, Appwrite will send an email or sms with a link to join the - /// team to the invited user, and an account will be created for them if one - /// doesn't exist. If initiated from a Server SDK, the new member will be added - /// automatically to the team. - /// - /// You only need to provide one of a user ID, email, or phone number. Appwrite - /// will prioritize accepting the user ID > email > phone number if you provide - /// more than one of these parameters. - /// - /// Use the `url` parameter to redirect the user from the invitation email to - /// your app. After the user is redirected, use the [Update Team Membership - /// Status](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus) - /// 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) - /// Appwrite will accept the only redirect URLs under the domains you have - /// added as a platform on the Appwrite Console. - /// - Future createMembership({required String teamId, required List roles, String? email, String? userId, String? phone, String? url, String? name}) async { - final String apiPath = '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); - - final Map apiParams = { - - 'email': email, -'userId': userId, -'phone': phone, -'roles': roles, -'url': url, -'name': name, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Membership.fromMap(res.data); - - } - - /// Update membership - /// - /// 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](https://appwrite.io/docs/permissions). - /// - Future updateMembership({required String teamId, required String membershipId, required List roles}) async { - final String apiPath = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); - - final Map apiParams = { - - 'roles': roles, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// 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 apiPath = '/teams/{teamId}/memberships/{membershipId}/status'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); - - final Map apiParams = { - - 'userId': userId, -'secret': secret, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Membership.fromMap(res.data); - - } - - /// Get team preferences - /// - /// Get the team's shared preferences by its unique ID. If a preference doesn't - /// need to be shared by all team members, prefer storing them in [user - /// preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs). - Future getPrefs({required String teamId}) async { - final String apiPath = '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - - } - - /// Update preferences - /// - /// Update the team's preferences by its unique ID. The object you pass is - /// stored as is and replaces any previous value. The maximum allowed prefs - /// size is 64kB and throws an error if exceeded. - Future updatePrefs({required String teamId, required Map prefs}) async { - final String apiPath = '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); - - final Map apiParams = { - - 'prefs': prefs, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - - } -} \ No newline at end of file + Teams(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. + Future list({List? queries, String? search}) async { + final String apiPath = '/teams'; + + final Map apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams'; + + final Map apiParams = { + 'teamId': teamId, + 'name': name, + 'roles': roles, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Team.fromMap(res.data); + } + + /// Update name + /// + /// Update the team's name by its unique ID. + Future updateName( + {required String teamId, required String name}) async { + final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + 'name': name, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List 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 listMemberships( + {required String teamId, List? queries, String? search}) async { + final String apiPath = + '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MembershipList.fromMap(res.data); + } + + /// Create team membership + /// + /// Invite a new member to join your team. Provide an ID for existing users, or + /// invite unregistered users using an email or phone number. If initiated from + /// a Client SDK, Appwrite will send an email or sms with a link to join the + /// team to the invited user, and an account will be created for them if one + /// doesn't exist. If initiated from a Server SDK, the new member will be added + /// automatically to the team. + /// + /// You only need to provide one of a user ID, email, or phone number. Appwrite + /// will prioritize accepting the user ID > email > phone number if you provide + /// more than one of these parameters. + /// + /// Use the `url` parameter to redirect the user from the invitation email to + /// your app. After the user is redirected, use the [Update Team Membership + /// Status](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus) + /// 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) + /// Appwrite will accept the only redirect URLs under the domains you have + /// added as a platform on the Appwrite Console. + /// + Future createMembership( + {required String teamId, + required List roles, + String? email, + String? userId, + String? phone, + String? url, + String? name}) async { + final String apiPath = + '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + 'email': email, + 'userId': userId, + 'phone': phone, + 'roles': roles, + 'url': url, + 'name': name, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams/{teamId}/memberships/{membershipId}' + .replaceAll('{teamId}', teamId) + .replaceAll('{membershipId}', membershipId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Membership.fromMap(res.data); + } + + /// Update membership + /// + /// 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](https://appwrite.io/docs/permissions). + /// + Future updateMembership( + {required String teamId, + required String membershipId, + required List roles}) async { + final String apiPath = '/teams/{teamId}/memberships/{membershipId}' + .replaceAll('{teamId}', teamId) + .replaceAll('{membershipId}', membershipId); + + final Map apiParams = { + 'roles': roles, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams/{teamId}/memberships/{membershipId}' + .replaceAll('{teamId}', teamId) + .replaceAll('{membershipId}', membershipId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// 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 apiPath = '/teams/{teamId}/memberships/{membershipId}/status' + .replaceAll('{teamId}', teamId) + .replaceAll('{membershipId}', membershipId); + + final Map apiParams = { + 'userId': userId, + 'secret': secret, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Membership.fromMap(res.data); + } + + /// Get team preferences + /// + /// Get the team's shared preferences by its unique ID. If a preference doesn't + /// need to be shared by all team members, prefer storing them in [user + /// preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs). + Future getPrefs({required String teamId}) async { + final String apiPath = + '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + } + + /// Update preferences + /// + /// Update the team's preferences by its unique ID. The object you pass is + /// stored as is and replaces any previous value. The maximum allowed prefs + /// size is 64kB and throws an error if exceeded. + Future updatePrefs( + {required String teamId, required Map prefs}) async { + final String apiPath = + '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + 'prefs': prefs, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + } +} diff --git a/lib/services/users.dart b/lib/services/users.dart index ac4bac14..74c375eb 100644 --- a/lib/services/users.dart +++ b/lib/services/users.dart @@ -2,1055 +2,1023 @@ part of '../dart_appwrite.dart'; /// The Users service allows you to manage your project users. class Users extends Service { - Users(super.client); - - /// List users - /// - /// Get a list of all the project's users. You can use the query params to - /// filter your results. - Future list({List? queries, String? search}) async { - final String apiPath = '/users'; - - final Map apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.UserList.fromMap(res.data); - - } - - /// Create user - /// - /// Create a new user. - Future create({required String userId, String? email, String? phone, String? password, String? name}) async { - final String apiPath = '/users'; - - final Map apiParams = { - - 'userId': userId, -'email': email, -'phone': phone, -'password': password, -'name': name, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create user with Argon2 password - /// - /// Create a new user. Password provided must be hashed with the - /// [Argon2](https://en.wikipedia.org/wiki/Argon2) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createArgon2User({required String userId, required String email, required String password, String? name}) async { - final String apiPath = '/users/argon2'; - - final Map apiParams = { - - 'userId': userId, -'email': email, -'password': password, -'name': name, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create user with bcrypt password - /// - /// Create a new user. Password provided must be hashed with the - /// [Bcrypt](https://en.wikipedia.org/wiki/Bcrypt) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createBcryptUser({required String userId, required String email, required String password, String? name}) async { - final String apiPath = '/users/bcrypt'; - - final Map apiParams = { - - 'userId': userId, -'email': email, -'password': password, -'name': name, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// List Identities - /// - /// Get identities for all users. - Future listIdentities({List? queries, String? search}) async { - final String apiPath = '/users/identities'; - - final Map apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.IdentityList.fromMap(res.data); - - } - - /// Delete identity - /// - /// Delete an identity by its unique ID. - Future deleteIdentity({required String identityId}) async { - final String apiPath = '/users/identities/{identityId}'.replaceAll('{identityId}', identityId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Create user with MD5 password - /// - /// Create a new user. Password provided must be hashed with the - /// [MD5](https://en.wikipedia.org/wiki/MD5) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createMD5User({required String userId, required String email, required String password, String? name}) async { - final String apiPath = '/users/md5'; - - final Map apiParams = { - - 'userId': userId, -'email': email, -'password': password, -'name': name, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create user with PHPass password - /// - /// Create a new user. Password provided must be hashed with the - /// [PHPass](https://www.openwall.com/phpass/) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createPHPassUser({required String userId, required String email, required String password, String? name}) async { - final String apiPath = '/users/phpass'; - - final Map apiParams = { - - 'userId': userId, -'email': email, -'password': password, -'name': name, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create user with Scrypt password - /// - /// Create a new user. Password provided must be hashed with the - /// [Scrypt](https://github.com/Tarsnap/scrypt) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createScryptUser({required String userId, required String email, required String password, required String passwordSalt, required int passwordCpu, required int passwordMemory, required int passwordParallel, required int passwordLength, String? name}) async { - final String apiPath = '/users/scrypt'; - - final Map apiParams = { - - 'userId': userId, -'email': email, -'password': password, -'passwordSalt': passwordSalt, -'passwordCpu': passwordCpu, -'passwordMemory': passwordMemory, -'passwordParallel': passwordParallel, -'passwordLength': passwordLength, -'name': name, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create user with Scrypt modified password - /// - /// Create a new user. Password provided must be hashed with the [Scrypt - /// Modified](https://gist.github.com/Meldiron/eecf84a0225eccb5a378d45bb27462cc) - /// algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createScryptModifiedUser({required String userId, required String email, required String password, required String passwordSalt, required String passwordSaltSeparator, required String passwordSignerKey, String? name}) async { - final String apiPath = '/users/scrypt-modified'; - - final Map apiParams = { - - 'userId': userId, -'email': email, -'password': password, -'passwordSalt': passwordSalt, -'passwordSaltSeparator': passwordSaltSeparator, -'passwordSignerKey': passwordSignerKey, -'name': name, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create user with SHA password - /// - /// Create a new user. Password provided must be hashed with the - /// [SHA](https://en.wikipedia.org/wiki/Secure_Hash_Algorithm) algorithm. Use - /// the [POST /users](https://appwrite.io/docs/server/users#usersCreate) - /// endpoint to create users with a plain text password. - Future createSHAUser({required String userId, required String email, required String password, enums.PasswordHash? passwordVersion, String? name}) async { - final String apiPath = '/users/sha'; - - final Map apiParams = { - - 'userId': userId, -'email': email, -'password': password, -'passwordVersion': passwordVersion?.value, -'name': name, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Get user - /// - /// Get a user by its unique ID. - Future get({required String userId}) async { - final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Delete user - /// - /// Delete a user by its unique ID, thereby releasing it's ID. Since ID is - /// released and can be reused, all user-related resources like documents or - /// storage files should be deleted before user deletion. If you want to keep - /// ID reserved, use the - /// [updateStatus](https://appwrite.io/docs/server/users#usersUpdateStatus) - /// endpoint instead. - Future delete({required String userId}) async { - final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Update email - /// - /// Update the user email by its unique ID. - Future updateEmail({required String userId, required String email}) async { - final String apiPath = '/users/{userId}/email'.replaceAll('{userId}', userId); - - final Map apiParams = { - - 'email': email, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create user JWT - /// - /// Use this endpoint to create a JSON Web Token for user by its unique ID. You - /// can use the resulting JWT to authenticate on behalf of the user. The JWT - /// secret will become invalid if the session it uses gets deleted. - Future createJWT({required String userId, String? sessionId, int? duration}) async { - final String apiPath = '/users/{userId}/jwts'.replaceAll('{userId}', userId); - - final Map apiParams = { - - 'sessionId': sessionId, -'duration': duration, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Jwt.fromMap(res.data); - - } - - /// Update user labels - /// - /// Update the user labels by its unique ID. - /// - /// Labels can be used to grant access to resources. While teams are a way for - /// user's to share access to a resource, labels can be defined by the - /// developer to grant access without an invitation. See the [Permissions - /// docs](https://appwrite.io/docs/permissions) for more info. - Future updateLabels({required String userId, required List labels}) async { - final String apiPath = '/users/{userId}/labels'.replaceAll('{userId}', userId); - - final Map apiParams = { - - 'labels': labels, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// List user logs - /// - /// Get the user activity logs list by its unique ID. - Future listLogs({required String userId, List? queries}) async { - final String apiPath = '/users/{userId}/logs'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'queries': queries, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - - } - - /// List user memberships - /// - /// Get the user membership list by its unique ID. - Future listMemberships({required String userId}) async { - final String apiPath = '/users/{userId}/memberships'.replaceAll('{userId}', userId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MembershipList.fromMap(res.data); - - } - - /// Update MFA - /// - /// Enable or disable MFA on a user account. - Future updateMfa({required String userId, required bool mfa}) async { - final String apiPath = '/users/{userId}/mfa'.replaceAll('{userId}', userId); - - final Map apiParams = { - - 'mfa': mfa, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Delete Authenticator - /// - /// Delete an authenticator app. - Future deleteMfaAuthenticator({required String userId, required enums.AuthenticatorType type}) async { - final String apiPath = '/users/{userId}/mfa/authenticators/{type}'.replaceAll('{userId}', userId).replaceAll('{type}', type.value); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// List Factors - /// - /// List the factors available on the account to be used as a MFA challange. - Future listMfaFactors({required String userId}) async { - final String apiPath = '/users/{userId}/mfa/factors'.replaceAll('{userId}', userId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaFactors.fromMap(res.data); - - } - - /// Get MFA Recovery Codes - /// - /// Get recovery codes that can be used as backup for MFA flow by User ID. - /// Before getting codes, they must be generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. - Future getMfaRecoveryCodes({required String userId}) async { - final String apiPath = '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - - } - - /// Regenerate MFA Recovery Codes - /// - /// Regenerate recovery codes that can be used as backup for MFA flow by User - /// ID. Before regenerating codes, they must be first generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. - Future updateMfaRecoveryCodes({required String userId}) async { - final String apiPath = '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - - } - - /// Create MFA Recovery Codes - /// - /// Generate recovery codes used as backup for MFA flow for User ID. Recovery - /// codes can be used as a MFA verification type in - /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) - /// method by client SDK. - Future createMfaRecoveryCodes({required String userId}) async { - final String apiPath = '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - - } - - /// Update name - /// - /// Update the user name by its unique ID. - Future updateName({required String userId, required String name}) async { - final String apiPath = '/users/{userId}/name'.replaceAll('{userId}', userId); - - final Map apiParams = { - - 'name': name, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Update password - /// - /// Update the user password by its unique ID. - Future updatePassword({required String userId, required String password}) async { - final String apiPath = '/users/{userId}/password'.replaceAll('{userId}', userId); - - final Map apiParams = { - - 'password': password, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Update phone - /// - /// Update the user phone by its unique ID. - Future updatePhone({required String userId, required String number}) async { - final String apiPath = '/users/{userId}/phone'.replaceAll('{userId}', userId); - - final Map apiParams = { - - 'number': number, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Get user preferences - /// - /// Get the user preferences by its unique ID. - Future getPrefs({required String userId}) async { - final String apiPath = '/users/{userId}/prefs'.replaceAll('{userId}', userId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - - } - - /// Update user preferences - /// - /// Update the user preferences by its unique ID. 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 String userId, required Map prefs}) async { - final String apiPath = '/users/{userId}/prefs'.replaceAll('{userId}', userId); - - final Map apiParams = { - - 'prefs': prefs, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - - } - - /// List user sessions - /// - /// Get the user sessions list by its unique ID. - Future listSessions({required String userId}) async { - final String apiPath = '/users/{userId}/sessions'.replaceAll('{userId}', userId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SessionList.fromMap(res.data); - - } - - /// Create session - /// - /// Creates a session for a user. Returns an immediately usable session object. - /// - /// If you want to generate a token for a custom authentication flow, use the - /// [POST - /// /users/{userId}/tokens](https://appwrite.io/docs/server/users#createToken) - /// endpoint. - Future createSession({required String userId}) async { - final String apiPath = '/users/{userId}/sessions'.replaceAll('{userId}', userId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - - } - - /// Delete user sessions - /// - /// Delete all user's sessions by using the user's unique ID. - Future deleteSessions({required String userId}) async { - final String apiPath = '/users/{userId}/sessions'.replaceAll('{userId}', userId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Delete user session - /// - /// Delete a user sessions by its unique ID. - Future deleteSession({required String userId, required String sessionId}) async { - final String apiPath = '/users/{userId}/sessions/{sessionId}'.replaceAll('{userId}', userId).replaceAll('{sessionId}', sessionId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Update user status - /// - /// Update the user status by its unique ID. Use this endpoint as an - /// alternative to deleting a user if you want to keep user's ID reserved. - Future updateStatus({required String userId, required bool status}) async { - final String apiPath = '/users/{userId}/status'.replaceAll('{userId}', userId); - - final Map apiParams = { - - 'status': status, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// List User Targets - /// - /// List the messaging targets that are associated with a user. - Future listTargets({required String userId, List? queries}) async { - final String apiPath = '/users/{userId}/targets'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'queries': queries, - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.TargetList.fromMap(res.data); - - } - - /// Create User Target - /// - /// Create a messaging target. - Future createTarget({required String userId, required String targetId, required enums.MessagingProviderType providerType, required String identifier, String? providerId, String? name}) async { - final String apiPath = '/users/{userId}/targets'.replaceAll('{userId}', userId); - - final Map apiParams = { - - 'targetId': targetId, -'providerType': providerType.value, -'identifier': identifier, -'providerId': providerId, -'name': name, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Target.fromMap(res.data); - - } - - /// Get User Target - /// - /// Get a user's push notification target by ID. - Future getTarget({required String userId, required String targetId}) async { - final String apiPath = '/users/{userId}/targets/{targetId}'.replaceAll('{userId}', userId).replaceAll('{targetId}', targetId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Target.fromMap(res.data); - - } - - /// Update User target - /// - /// Update a messaging target. - Future updateTarget({required String userId, required String targetId, String? identifier, String? providerId, String? name}) async { - final String apiPath = '/users/{userId}/targets/{targetId}'.replaceAll('{userId}', userId).replaceAll('{targetId}', targetId); - - final Map apiParams = { - - 'identifier': identifier, -'providerId': providerId, -'name': name, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Target.fromMap(res.data); - - } - - /// Delete user target - /// - /// Delete a messaging target. - Future deleteTarget({required String userId, required String targetId}) async { - final String apiPath = '/users/{userId}/targets/{targetId}'.replaceAll('{userId}', userId).replaceAll('{targetId}', targetId); - - final Map apiParams = { - - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Create token - /// - /// Returns a token with a secret key for creating a session. Use the user ID - /// and secret and submit a request to the [PUT - /// /account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. - /// - Future createToken({required String userId, int? length, int? expire}) async { - final String apiPath = '/users/{userId}/tokens'.replaceAll('{userId}', userId); - - final Map apiParams = { - - 'length': length, -'expire': expire, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// Update email verification - /// - /// Update the user email verification status by its unique ID. - Future updateEmailVerification({required String userId, required bool emailVerification}) async { - final String apiPath = '/users/{userId}/verification'.replaceAll('{userId}', userId); - - final Map apiParams = { - - 'emailVerification': emailVerification, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Update phone verification - /// - /// Update the user phone verification status by its unique ID. - Future updatePhoneVerification({required String userId, required bool phoneVerification}) async { - final String apiPath = '/users/{userId}/verification/phone'.replaceAll('{userId}', userId); - - final Map apiParams = { - - 'phoneVerification': phoneVerification, - - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } -} \ No newline at end of file + Users(super.client); + + /// List users + /// + /// Get a list of all the project's users. You can use the query params to + /// filter your results. + Future list({List? queries, String? search}) async { + final String apiPath = '/users'; + + final Map apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.UserList.fromMap(res.data); + } + + /// Create user + /// + /// Create a new user. + Future create( + {required String userId, + String? email, + String? phone, + String? password, + String? name}) async { + final String apiPath = '/users'; + + final Map apiParams = { + 'userId': userId, + 'email': email, + 'phone': phone, + 'password': password, + 'name': name, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create user with Argon2 password + /// + /// Create a new user. Password provided must be hashed with the + /// [Argon2](https://en.wikipedia.org/wiki/Argon2) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createArgon2User( + {required String userId, + required String email, + required String password, + String? name}) async { + final String apiPath = '/users/argon2'; + + final Map apiParams = { + 'userId': userId, + 'email': email, + 'password': password, + 'name': name, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create user with bcrypt password + /// + /// Create a new user. Password provided must be hashed with the + /// [Bcrypt](https://en.wikipedia.org/wiki/Bcrypt) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createBcryptUser( + {required String userId, + required String email, + required String password, + String? name}) async { + final String apiPath = '/users/bcrypt'; + + final Map apiParams = { + 'userId': userId, + 'email': email, + 'password': password, + 'name': name, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// List Identities + /// + /// Get identities for all users. + Future listIdentities( + {List? queries, String? search}) async { + final String apiPath = '/users/identities'; + + final Map apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.IdentityList.fromMap(res.data); + } + + /// Delete identity + /// + /// Delete an identity by its unique ID. + Future deleteIdentity({required String identityId}) async { + final String apiPath = + '/users/identities/{identityId}'.replaceAll('{identityId}', identityId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Create user with MD5 password + /// + /// Create a new user. Password provided must be hashed with the + /// [MD5](https://en.wikipedia.org/wiki/MD5) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createMD5User( + {required String userId, + required String email, + required String password, + String? name}) async { + final String apiPath = '/users/md5'; + + final Map apiParams = { + 'userId': userId, + 'email': email, + 'password': password, + 'name': name, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create user with PHPass password + /// + /// Create a new user. Password provided must be hashed with the + /// [PHPass](https://www.openwall.com/phpass/) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createPHPassUser( + {required String userId, + required String email, + required String password, + String? name}) async { + final String apiPath = '/users/phpass'; + + final Map apiParams = { + 'userId': userId, + 'email': email, + 'password': password, + 'name': name, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create user with Scrypt password + /// + /// Create a new user. Password provided must be hashed with the + /// [Scrypt](https://github.com/Tarsnap/scrypt) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createScryptUser( + {required String userId, + required String email, + required String password, + required String passwordSalt, + required int passwordCpu, + required int passwordMemory, + required int passwordParallel, + required int passwordLength, + String? name}) async { + final String apiPath = '/users/scrypt'; + + final Map apiParams = { + 'userId': userId, + 'email': email, + 'password': password, + 'passwordSalt': passwordSalt, + 'passwordCpu': passwordCpu, + 'passwordMemory': passwordMemory, + 'passwordParallel': passwordParallel, + 'passwordLength': passwordLength, + 'name': name, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create user with Scrypt modified password + /// + /// Create a new user. Password provided must be hashed with the [Scrypt + /// Modified](https://gist.github.com/Meldiron/eecf84a0225eccb5a378d45bb27462cc) + /// algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createScryptModifiedUser( + {required String userId, + required String email, + required String password, + required String passwordSalt, + required String passwordSaltSeparator, + required String passwordSignerKey, + String? name}) async { + final String apiPath = '/users/scrypt-modified'; + + final Map apiParams = { + 'userId': userId, + 'email': email, + 'password': password, + 'passwordSalt': passwordSalt, + 'passwordSaltSeparator': passwordSaltSeparator, + 'passwordSignerKey': passwordSignerKey, + 'name': name, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create user with SHA password + /// + /// Create a new user. Password provided must be hashed with the + /// [SHA](https://en.wikipedia.org/wiki/Secure_Hash_Algorithm) algorithm. Use + /// the [POST /users](https://appwrite.io/docs/server/users#usersCreate) + /// endpoint to create users with a plain text password. + Future createSHAUser( + {required String userId, + required String email, + required String password, + enums.PasswordHash? passwordVersion, + String? name}) async { + final String apiPath = '/users/sha'; + + final Map apiParams = { + 'userId': userId, + 'email': email, + 'password': password, + 'passwordVersion': passwordVersion?.value, + 'name': name, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Get user + /// + /// Get a user by its unique ID. + Future get({required String userId}) async { + final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Delete user + /// + /// Delete a user by its unique ID, thereby releasing it's ID. Since ID is + /// released and can be reused, all user-related resources like documents or + /// storage files should be deleted before user deletion. If you want to keep + /// ID reserved, use the + /// [updateStatus](https://appwrite.io/docs/server/users#usersUpdateStatus) + /// endpoint instead. + Future delete({required String userId}) async { + final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Update email + /// + /// Update the user email by its unique ID. + Future updateEmail( + {required String userId, required String email}) async { + final String apiPath = + '/users/{userId}/email'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'email': email, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create user JWT + /// + /// Use this endpoint to create a JSON Web Token for user by its unique ID. You + /// can use the resulting JWT to authenticate on behalf of the user. The JWT + /// secret will become invalid if the session it uses gets deleted. + Future createJWT( + {required String userId, String? sessionId, int? duration}) async { + final String apiPath = + '/users/{userId}/jwts'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'sessionId': sessionId, + 'duration': duration, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Jwt.fromMap(res.data); + } + + /// Update user labels + /// + /// Update the user labels by its unique ID. + /// + /// Labels can be used to grant access to resources. While teams are a way for + /// user's to share access to a resource, labels can be defined by the + /// developer to grant access without an invitation. See the [Permissions + /// docs](https://appwrite.io/docs/permissions) for more info. + Future updateLabels( + {required String userId, required List labels}) async { + final String apiPath = + '/users/{userId}/labels'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'labels': labels, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// List user logs + /// + /// Get the user activity logs list by its unique ID. + Future listLogs( + {required String userId, List? queries}) async { + final String apiPath = + '/users/{userId}/logs'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'queries': queries, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + } + + /// List user memberships + /// + /// Get the user membership list by its unique ID. + Future listMemberships( + {required String userId}) async { + final String apiPath = + '/users/{userId}/memberships'.replaceAll('{userId}', userId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MembershipList.fromMap(res.data); + } + + /// Update MFA + /// + /// Enable or disable MFA on a user account. + Future updateMfa( + {required String userId, required bool mfa}) async { + final String apiPath = '/users/{userId}/mfa'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'mfa': mfa, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Delete Authenticator + /// + /// Delete an authenticator app. + Future deleteMfaAuthenticator( + {required String userId, required enums.AuthenticatorType type}) async { + final String apiPath = '/users/{userId}/mfa/authenticators/{type}' + .replaceAll('{userId}', userId) + .replaceAll('{type}', type.value); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// List Factors + /// + /// List the factors available on the account to be used as a MFA challange. + Future listMfaFactors({required String userId}) async { + final String apiPath = + '/users/{userId}/mfa/factors'.replaceAll('{userId}', userId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaFactors.fromMap(res.data); + } + + /// Get MFA Recovery Codes + /// + /// Get recovery codes that can be used as backup for MFA flow by User ID. + /// Before getting codes, they must be generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. + Future getMfaRecoveryCodes( + {required String userId}) async { + final String apiPath = + '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + } + + /// Regenerate MFA Recovery Codes + /// + /// Regenerate recovery codes that can be used as backup for MFA flow by User + /// ID. Before regenerating codes, they must be first generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. + Future updateMfaRecoveryCodes( + {required String userId}) async { + final String apiPath = + '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + } + + /// Create MFA Recovery Codes + /// + /// Generate recovery codes used as backup for MFA flow for User ID. Recovery + /// codes can be used as a MFA verification type in + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method by client SDK. + Future createMfaRecoveryCodes( + {required String userId}) async { + final String apiPath = + '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + } + + /// Update name + /// + /// Update the user name by its unique ID. + Future updateName( + {required String userId, required String name}) async { + final String apiPath = + '/users/{userId}/name'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'name': name, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Update password + /// + /// Update the user password by its unique ID. + Future updatePassword( + {required String userId, required String password}) async { + final String apiPath = + '/users/{userId}/password'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'password': password, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Update phone + /// + /// Update the user phone by its unique ID. + Future updatePhone( + {required String userId, required String number}) async { + final String apiPath = + '/users/{userId}/phone'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'number': number, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Get user preferences + /// + /// Get the user preferences by its unique ID. + Future getPrefs({required String userId}) async { + final String apiPath = + '/users/{userId}/prefs'.replaceAll('{userId}', userId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + } + + /// Update user preferences + /// + /// Update the user preferences by its unique ID. 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 String userId, required Map prefs}) async { + final String apiPath = + '/users/{userId}/prefs'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'prefs': prefs, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + } + + /// List user sessions + /// + /// Get the user sessions list by its unique ID. + Future listSessions({required String userId}) async { + final String apiPath = + '/users/{userId}/sessions'.replaceAll('{userId}', userId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SessionList.fromMap(res.data); + } + + /// Create session + /// + /// Creates a session for a user. Returns an immediately usable session object. + /// + /// If you want to generate a token for a custom authentication flow, use the + /// [POST + /// /users/{userId}/tokens](https://appwrite.io/docs/server/users#createToken) + /// endpoint. + Future createSession({required String userId}) async { + final String apiPath = + '/users/{userId}/sessions'.replaceAll('{userId}', userId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + } + + /// Delete user sessions + /// + /// Delete all user's sessions by using the user's unique ID. + Future deleteSessions({required String userId}) async { + final String apiPath = + '/users/{userId}/sessions'.replaceAll('{userId}', userId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Delete user session + /// + /// Delete a user sessions by its unique ID. + Future deleteSession( + {required String userId, required String sessionId}) async { + final String apiPath = '/users/{userId}/sessions/{sessionId}' + .replaceAll('{userId}', userId) + .replaceAll('{sessionId}', sessionId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Update user status + /// + /// Update the user status by its unique ID. Use this endpoint as an + /// alternative to deleting a user if you want to keep user's ID reserved. + Future updateStatus( + {required String userId, required bool status}) async { + final String apiPath = + '/users/{userId}/status'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'status': status, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// List User Targets + /// + /// List the messaging targets that are associated with a user. + Future listTargets( + {required String userId, List? queries}) async { + final String apiPath = + '/users/{userId}/targets'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'queries': queries, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.TargetList.fromMap(res.data); + } + + /// Create User Target + /// + /// Create a messaging target. + Future createTarget( + {required String userId, + required String targetId, + required enums.MessagingProviderType providerType, + required String identifier, + String? providerId, + String? name}) async { + final String apiPath = + '/users/{userId}/targets'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'targetId': targetId, + 'providerType': providerType.value, + 'identifier': identifier, + 'providerId': providerId, + 'name': name, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Target.fromMap(res.data); + } + + /// Get User Target + /// + /// Get a user's push notification target by ID. + Future getTarget( + {required String userId, required String targetId}) async { + final String apiPath = '/users/{userId}/targets/{targetId}' + .replaceAll('{userId}', userId) + .replaceAll('{targetId}', targetId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Target.fromMap(res.data); + } + + /// Update User target + /// + /// Update a messaging target. + Future updateTarget( + {required String userId, + required String targetId, + String? identifier, + String? providerId, + String? name}) async { + final String apiPath = '/users/{userId}/targets/{targetId}' + .replaceAll('{userId}', userId) + .replaceAll('{targetId}', targetId); + + final Map apiParams = { + 'identifier': identifier, + 'providerId': providerId, + 'name': name, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Target.fromMap(res.data); + } + + /// Delete user target + /// + /// Delete a messaging target. + Future deleteTarget( + {required String userId, required String targetId}) async { + final String apiPath = '/users/{userId}/targets/{targetId}' + .replaceAll('{userId}', userId) + .replaceAll('{targetId}', targetId); + + final Map apiParams = {}; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Create token + /// + /// Returns a token with a secret key for creating a session. Use the user ID + /// and secret and submit a request to the [PUT + /// /account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. + /// + Future createToken( + {required String userId, int? length, int? expire}) async { + final String apiPath = + '/users/{userId}/tokens'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'length': length, + 'expire': expire, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// Update email verification + /// + /// Update the user email verification status by its unique ID. + Future updateEmailVerification( + {required String userId, required bool emailVerification}) async { + final String apiPath = + '/users/{userId}/verification'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'emailVerification': emailVerification, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Update phone verification + /// + /// Update the user phone verification status by its unique ID. + Future updatePhoneVerification( + {required String userId, required bool phoneVerification}) async { + final String apiPath = + '/users/{userId}/verification/phone'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'phoneVerification': phoneVerification, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } +} diff --git a/lib/src/client.dart b/lib/src/client.dart index 8dee2426..bac07cfb 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -8,7 +8,7 @@ import 'upload_progress.dart'; /// [Client] that handles requests to Appwrite abstract class Client { /// The size for cunked uploads in bytes. - static const int CHUNK_SIZE = 5*1024*1024; + static const int CHUNK_SIZE = 5 * 1024 * 1024; /// Holds configuration such as project. late Map config; @@ -27,7 +27,7 @@ abstract class Client { Future webAuth(Uri url); /// Set self signed to [status]. - /// + /// /// If self signed is true, [Client] will ignore invalid certificates. /// This is helpful in environments where your Appwrite /// instance does not have a valid SSL certificate. @@ -78,7 +78,8 @@ abstract class Client { }); /// Send the API request. - Future call(HttpMethod method, { + Future call( + HttpMethod method, { String path = '', Map headers = const {}, Map params = const {}, diff --git a/lib/src/client_base.dart b/lib/src/client_base.dart index 21992eb0..95476465 100644 --- a/lib/src/client_base.dart +++ b/lib/src/client_base.dart @@ -2,21 +2,25 @@ import 'response.dart'; import 'client.dart'; import 'enums.dart'; -abstract class ClientBase implements Client { +abstract class ClientBase implements Client { /// Your project ID @override ClientBase setProject(value); + /// Your secret API key @override ClientBase setKey(value); + /// Your secret JSON Web Token @override ClientBase setJWT(value); @override ClientBase setLocale(value); + /// The user session to authenticate with @override ClientBase setSession(value); + /// The user agent string of the client that made the request @override ClientBase setForwardedUserAgent(value); diff --git a/lib/src/client_browser.dart b/lib/src/client_browser.dart index af7cf916..e9da960a 100644 --- a/lib/src/client_browser.dart +++ b/lib/src/client_browser.dart @@ -16,7 +16,7 @@ ClientBase createClient({ ClientBrowser(endPoint: endPoint, selfSigned: selfSigned); class ClientBrowser extends ClientBase with ClientMixin { - static const int CHUNK_SIZE = 5*1024*1024; + static const int CHUNK_SIZE = 5 * 1024 * 1024; String _endPoint; Map? _headers; @override @@ -34,7 +34,7 @@ class ClientBrowser extends ClientBase with ClientMixin { 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', 'x-sdk-version': '13.0.0-rc1', - 'X-Appwrite-Response-Format' : '1.6.0', + 'X-Appwrite-Response-Format': '1.6.0', }; config = {}; @@ -46,47 +46,52 @@ class ClientBrowser extends ClientBase with ClientMixin { @override String get endPoint => _endPoint; - /// Your project ID - @override - ClientBrowser setProject(value) { - config['project'] = value; - addHeader('X-Appwrite-Project', value); - return this; - } - /// Your secret API key - @override - ClientBrowser setKey(value) { - config['key'] = value; - addHeader('X-Appwrite-Key', value); - return this; - } - /// Your secret JSON Web Token - @override - ClientBrowser setJWT(value) { - config['jWT'] = value; - addHeader('X-Appwrite-JWT', value); - return this; - } - @override - ClientBrowser setLocale(value) { - config['locale'] = value; - addHeader('X-Appwrite-Locale', value); - return this; - } - /// The user session to authenticate with - @override - ClientBrowser setSession(value) { - config['session'] = value; - addHeader('X-Appwrite-Session', value); - return this; - } - /// The user agent string of the client that made the request - @override - ClientBrowser setForwardedUserAgent(value) { - config['forwardedUserAgent'] = value; - addHeader('X-Forwarded-User-Agent', value); - return this; - } + /// Your project ID + @override + ClientBrowser setProject(value) { + config['project'] = value; + addHeader('X-Appwrite-Project', value); + return this; + } + + /// Your secret API key + @override + ClientBrowser setKey(value) { + config['key'] = value; + addHeader('X-Appwrite-Key', value); + return this; + } + + /// Your secret JSON Web Token + @override + ClientBrowser setJWT(value) { + config['jWT'] = value; + addHeader('X-Appwrite-JWT', value); + return this; + } + + @override + ClientBrowser setLocale(value) { + config['locale'] = value; + addHeader('X-Appwrite-Locale', value); + return this; + } + + /// The user session to authenticate with + @override + ClientBrowser setSession(value) { + config['session'] = value; + addHeader('X-Appwrite-Session', value); + return this; + } + + /// The user agent string of the client that made the request + @override + ClientBrowser setForwardedUserAgent(value) { + config['forwardedUserAgent'] = value; + addHeader('X-Forwarded-User-Agent', value); + return this; + } @override ClientBrowser setSelfSigned({bool status = true}) { @@ -131,7 +136,8 @@ class ClientBrowser extends ClientBase with ClientMixin { late Response res; if (size <= CHUNK_SIZE) { - params[paramName] = http.MultipartFile.fromBytes(paramName, file.data!, filename: file.filename); + params[paramName] = http.MultipartFile.fromBytes(paramName, file.data!, + filename: file.filename); return call( HttpMethod.post, path: path, @@ -157,9 +163,10 @@ class ClientBrowser extends ClientBase with ClientMixin { while (offset < size) { List chunk = []; final end = min(offset + CHUNK_SIZE, size); - chunk = file.toBinary(length: offset, length: min(CHUNK_SIZE, size - offset)); - params[paramName] = - http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename); + chunk = + file.toBinary(length: offset, length: min(CHUNK_SIZE, size - offset)); + params[paramName] = http.MultipartFile.fromBytes(paramName, chunk, + filename: file.filename); headers['content-range'] = 'bytes $offset-${min((offset + CHUNK_SIZE - 1), size - 1)}/$size'; res = await call(HttpMethod.post, diff --git a/lib/src/client_io.dart b/lib/src/client_io.dart index 0877997e..de1c2d3f 100644 --- a/lib/src/client_io.dart +++ b/lib/src/client_io.dart @@ -21,7 +21,7 @@ ClientBase createClient({ ); class ClientIO extends ClientBase with ClientMixin { - static const int CHUNK_SIZE = 5*1024*1024; + static const int CHUNK_SIZE = 5 * 1024 * 1024; String _endPoint; Map? _headers; @override @@ -44,8 +44,9 @@ class ClientIO extends ClientBase with ClientMixin { 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', 'x-sdk-version': '13.0.0-rc1', - 'user-agent' : 'AppwriteDartSDK/13.0.0-rc1 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', - 'X-Appwrite-Response-Format' : '1.6.0', + 'user-agent': + 'AppwriteDartSDK/13.0.0-rc1 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', + 'X-Appwrite-Response-Format': '1.6.0', }; config = {}; @@ -57,47 +58,52 @@ class ClientIO extends ClientBase with ClientMixin { @override String get endPoint => _endPoint; - /// Your project ID - @override - ClientIO setProject(value) { - config['project'] = value; - addHeader('X-Appwrite-Project', value); - return this; - } - /// Your secret API key - @override - ClientIO setKey(value) { - config['key'] = value; - addHeader('X-Appwrite-Key', value); - return this; - } - /// Your secret JSON Web Token - @override - ClientIO setJWT(value) { - config['jWT'] = value; - addHeader('X-Appwrite-JWT', value); - return this; - } - @override - ClientIO setLocale(value) { - config['locale'] = value; - addHeader('X-Appwrite-Locale', value); - return this; - } - /// The user session to authenticate with - @override - ClientIO setSession(value) { - config['session'] = value; - addHeader('X-Appwrite-Session', value); - return this; - } - /// The user agent string of the client that made the request - @override - ClientIO setForwardedUserAgent(value) { - config['forwardedUserAgent'] = value; - addHeader('X-Forwarded-User-Agent', value); - return this; - } + /// Your project ID + @override + ClientIO setProject(value) { + config['project'] = value; + addHeader('X-Appwrite-Project', value); + return this; + } + + /// Your secret API key + @override + ClientIO setKey(value) { + config['key'] = value; + addHeader('X-Appwrite-Key', value); + return this; + } + + /// Your secret JSON Web Token + @override + ClientIO setJWT(value) { + config['jWT'] = value; + addHeader('X-Appwrite-JWT', value); + return this; + } + + @override + ClientIO setLocale(value) { + config['locale'] = value; + addHeader('X-Appwrite-Locale', value); + return this; + } + + /// The user session to authenticate with + @override + ClientIO setSession(value) { + config['session'] = value; + addHeader('X-Appwrite-Session', value); + return this; + } + + /// The user agent string of the client that made the request + @override + ClientIO setForwardedUserAgent(value) { + config['forwardedUserAgent'] = value; + addHeader('X-Forwarded-User-Agent', value); + return this; + } @override ClientIO setSelfSigned({bool status = true}) { @@ -185,13 +191,14 @@ class ClientIO extends ClientBase with ClientMixin { while (offset < size) { List chunk = []; if (file.data != null) { - chunk = file.toBinary(offset: offset, length: min(CHUNK_SIZE, size - offset)); + chunk = file.toBinary( + offset: offset, length: min(CHUNK_SIZE, size - offset)); } else { raf!.setPositionSync(offset); chunk = raf.readSync(CHUNK_SIZE); } - params[paramName] = - http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename); + params[paramName] = http.MultipartFile.fromBytes(paramName, chunk, + filename: file.filename); headers['content-range'] = 'bytes $offset-${min((offset + CHUNK_SIZE - 1), size - 1)}/$size'; res = await call(HttpMethod.post, diff --git a/lib/src/client_mixin.dart b/lib/src/client_mixin.dart index f7dd73a7..5f35191d 100644 --- a/lib/src/client_mixin.dart +++ b/lib/src/client_mixin.dart @@ -50,7 +50,7 @@ mixin ClientMixin { } } else if (method == HttpMethod.get) { if (params.isNotEmpty) { - params = params.map((key, value){ + params = params.map((key, value) { if (value is int || value is double) { return MapEntry(key, value.toString()); } @@ -76,7 +76,8 @@ mixin ClientMixin { return request; } - Future prepareResponse(http.Response res, {ResponseType? responseType}) async { + Future prepareResponse(http.Response res, + {ResponseType? responseType}) async { responseType ??= ResponseType.json; String? warnings = res.headers['x-appwrite-warning']; @@ -106,8 +107,10 @@ mixin ClientMixin { } else { data = res.body; } - } else if((res.headers['content-type'] ?? '').contains('multipart/form-data')) { - data = await _parseMultipart(res.headers['content-type']!, Stream.value(res.bodyBytes)); + } else if ((res.headers['content-type'] ?? '') + .contains('multipart/form-data')) { + data = await _parseMultipart( + res.headers['content-type']!, Stream.value(res.bodyBytes)); return Response(data: data); } else { if (responseType == ResponseType.bytes) { @@ -119,19 +122,24 @@ mixin ClientMixin { return Response(data: data); } - Future toResponse(http.StreamedResponse streamedResponse) async { - if(streamedResponse.statusCode == 204) { - return http.Response('', - streamedResponse.statusCode, - headers: streamedResponse.headers.map((k,v) => k.toLowerCase()=='content-type' ? MapEntry(k, 'text/plain') : MapEntry(k,v)), - request: streamedResponse.request, - isRedirect: streamedResponse.isRedirect, - persistentConnection: streamedResponse.persistentConnection, - reasonPhrase: streamedResponse.reasonPhrase, - ); - } else { - return await http.Response.fromStream(streamedResponse); - } + Future toResponse( + http.StreamedResponse streamedResponse) async { + if (streamedResponse.statusCode == 204) { + return http.Response( + '', + streamedResponse.statusCode, + headers: streamedResponse.headers.map((k, v) => + k.toLowerCase() == 'content-type' + ? MapEntry(k, 'text/plain') + : MapEntry(k, v)), + request: streamedResponse.request, + isRedirect: streamedResponse.isRedirect, + persistentConnection: streamedResponse.persistentConnection, + reasonPhrase: streamedResponse.reasonPhrase, + ); + } else { + return await http.Response.fromStream(streamedResponse); + } } Future> _decodeMimeMultipart(MimeMultipart part) async { @@ -179,8 +187,9 @@ mixin ClientMixin { final Map out = {}; for (final item in data) { if (item!.name == 'responseBody') { - out[item.name] = - Payload.fromBinary(data: await _decodeMimeMultipart(item.value), filename: item.filename); + out[item.name] = Payload.fromBinary( + data: await _decodeMimeMultipart(item.value), + filename: item.filename); } else { out[item.name] = await item.value; } @@ -248,4 +257,4 @@ class _FormData { final String? filename; _FormData._(this.name, this.filename, this.value); -} \ No newline at end of file +} diff --git a/lib/src/enums/authentication_factor.dart b/lib/src/enums/authentication_factor.dart index 00d12830..1d5271eb 100644 --- a/lib/src/enums/authentication_factor.dart +++ b/lib/src/enums/authentication_factor.dart @@ -1,16 +1,14 @@ part of '../../enums.dart'; enum AuthenticationFactor { - email(value: 'email'), - phone(value: 'phone'), - totp(value: 'totp'), - recoverycode(value: 'recoverycode'); + email(value: 'email'), + phone(value: 'phone'), + totp(value: 'totp'), + recoverycode(value: 'recoverycode'); - const AuthenticationFactor({ - required this.value - }); + const AuthenticationFactor({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/authenticator_type.dart b/lib/src/enums/authenticator_type.dart index 10460393..c1fe8584 100644 --- a/lib/src/enums/authenticator_type.dart +++ b/lib/src/enums/authenticator_type.dart @@ -1,13 +1,11 @@ part of '../../enums.dart'; enum AuthenticatorType { - totp(value: 'totp'); + totp(value: 'totp'); - const AuthenticatorType({ - required this.value - }); + const AuthenticatorType({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/browser.dart b/lib/src/enums/browser.dart index 386fa11d..949f4c47 100644 --- a/lib/src/enums/browser.dart +++ b/lib/src/enums/browser.dart @@ -1,26 +1,24 @@ part of '../../enums.dart'; enum Browser { - avantBrowser(value: 'aa'), - androidWebViewBeta(value: 'an'), - googleChrome(value: 'ch'), - googleChromeIOS(value: 'ci'), - googleChromeMobile(value: 'cm'), - chromium(value: 'cr'), - mozillaFirefox(value: 'ff'), - safari(value: 'sf'), - mobileSafari(value: 'mf'), - microsoftEdge(value: 'ps'), - microsoftEdgeIOS(value: 'oi'), - operaMini(value: 'om'), - opera(value: 'op'), - operaNext(value: 'on'); + avantBrowser(value: 'aa'), + androidWebViewBeta(value: 'an'), + googleChrome(value: 'ch'), + googleChromeIOS(value: 'ci'), + googleChromeMobile(value: 'cm'), + chromium(value: 'cr'), + mozillaFirefox(value: 'ff'), + safari(value: 'sf'), + mobileSafari(value: 'mf'), + microsoftEdge(value: 'ps'), + microsoftEdgeIOS(value: 'oi'), + operaMini(value: 'om'), + opera(value: 'op'), + operaNext(value: 'on'); - const Browser({ - required this.value - }); + const Browser({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/compression.dart b/lib/src/enums/compression.dart index 209acfb8..768930d9 100644 --- a/lib/src/enums/compression.dart +++ b/lib/src/enums/compression.dart @@ -1,15 +1,13 @@ part of '../../enums.dart'; enum Compression { - none(value: 'none'), - gzip(value: 'gzip'), - zstd(value: 'zstd'); + none(value: 'none'), + gzip(value: 'gzip'), + zstd(value: 'zstd'); - const Compression({ - required this.value - }); + const Compression({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/credit_card.dart b/lib/src/enums/credit_card.dart index 7d54fa80..3a6b256a 100644 --- a/lib/src/enums/credit_card.dart +++ b/lib/src/enums/credit_card.dart @@ -1,28 +1,26 @@ part of '../../enums.dart'; enum CreditCard { - americanExpress(value: 'amex'), - argencard(value: 'argencard'), - cabal(value: 'cabal'), - cencosud(value: 'cencosud'), - dinersClub(value: 'diners'), - discover(value: 'discover'), - elo(value: 'elo'), - hipercard(value: 'hipercard'), - jCB(value: 'jcb'), - mastercard(value: 'mastercard'), - naranja(value: 'naranja'), - tarjetaShopping(value: 'targeta-shopping'), - unionChinaPay(value: 'union-china-pay'), - visa(value: 'visa'), - mIR(value: 'mir'), - maestro(value: 'maestro'); + americanExpress(value: 'amex'), + argencard(value: 'argencard'), + cabal(value: 'cabal'), + cencosud(value: 'cencosud'), + dinersClub(value: 'diners'), + discover(value: 'discover'), + elo(value: 'elo'), + hipercard(value: 'hipercard'), + jCB(value: 'jcb'), + mastercard(value: 'mastercard'), + naranja(value: 'naranja'), + tarjetaShopping(value: 'targeta-shopping'), + unionChinaPay(value: 'union-china-pay'), + visa(value: 'visa'), + mIR(value: 'mir'), + maestro(value: 'maestro'); - const CreditCard({ - required this.value - }); + const CreditCard({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/execution_method.dart b/lib/src/enums/execution_method.dart index 7d2d7016..42954430 100644 --- a/lib/src/enums/execution_method.dart +++ b/lib/src/enums/execution_method.dart @@ -1,18 +1,16 @@ part of '../../enums.dart'; enum ExecutionMethod { - gET(value: 'GET'), - pOST(value: 'POST'), - pUT(value: 'PUT'), - pATCH(value: 'PATCH'), - dELETE(value: 'DELETE'), - oPTIONS(value: 'OPTIONS'); + gET(value: 'GET'), + pOST(value: 'POST'), + pUT(value: 'PUT'), + pATCH(value: 'PATCH'), + dELETE(value: 'DELETE'), + oPTIONS(value: 'OPTIONS'); - const ExecutionMethod({ - required this.value - }); + const ExecutionMethod({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/flag.dart b/lib/src/enums/flag.dart index 27c25cac..a44cb81d 100644 --- a/lib/src/enums/flag.dart +++ b/lib/src/enums/flag.dart @@ -1,207 +1,205 @@ part of '../../enums.dart'; enum Flag { - afghanistan(value: 'af'), - angola(value: 'ao'), - albania(value: 'al'), - andorra(value: 'ad'), - unitedArabEmirates(value: 'ae'), - argentina(value: 'ar'), - armenia(value: 'am'), - antiguaAndBarbuda(value: 'ag'), - australia(value: 'au'), - austria(value: 'at'), - azerbaijan(value: 'az'), - burundi(value: 'bi'), - belgium(value: 'be'), - benin(value: 'bj'), - burkinaFaso(value: 'bf'), - bangladesh(value: 'bd'), - bulgaria(value: 'bg'), - bahrain(value: 'bh'), - bahamas(value: 'bs'), - bosniaAndHerzegovina(value: 'ba'), - belarus(value: 'by'), - belize(value: 'bz'), - bolivia(value: 'bo'), - brazil(value: 'br'), - barbados(value: 'bb'), - bruneiDarussalam(value: 'bn'), - bhutan(value: 'bt'), - botswana(value: 'bw'), - centralAfricanRepublic(value: 'cf'), - canada(value: 'ca'), - switzerland(value: 'ch'), - chile(value: 'cl'), - china(value: 'cn'), - coteDIvoire(value: 'ci'), - cameroon(value: 'cm'), - democraticRepublicOfTheCongo(value: 'cd'), - republicOfTheCongo(value: 'cg'), - colombia(value: 'co'), - comoros(value: 'km'), - capeVerde(value: 'cv'), - costaRica(value: 'cr'), - cuba(value: 'cu'), - cyprus(value: 'cy'), - czechRepublic(value: 'cz'), - germany(value: 'de'), - djibouti(value: 'dj'), - dominica(value: 'dm'), - denmark(value: 'dk'), - dominicanRepublic(value: 'do'), - algeria(value: 'dz'), - ecuador(value: 'ec'), - egypt(value: 'eg'), - eritrea(value: 'er'), - spain(value: 'es'), - estonia(value: 'ee'), - ethiopia(value: 'et'), - finland(value: 'fi'), - fiji(value: 'fj'), - france(value: 'fr'), - micronesiaFederatedStatesOf(value: 'fm'), - gabon(value: 'ga'), - unitedKingdom(value: 'gb'), - georgia(value: 'ge'), - ghana(value: 'gh'), - guinea(value: 'gn'), - gambia(value: 'gm'), - guineaBissau(value: 'gw'), - equatorialGuinea(value: 'gq'), - greece(value: 'gr'), - grenada(value: 'gd'), - guatemala(value: 'gt'), - guyana(value: 'gy'), - honduras(value: 'hn'), - croatia(value: 'hr'), - haiti(value: 'ht'), - hungary(value: 'hu'), - indonesia(value: 'id'), - india(value: 'in'), - ireland(value: 'ie'), - iranIslamicRepublicOf(value: 'ir'), - iraq(value: 'iq'), - iceland(value: 'is'), - israel(value: 'il'), - italy(value: 'it'), - jamaica(value: 'jm'), - jordan(value: 'jo'), - japan(value: 'jp'), - kazakhstan(value: 'kz'), - kenya(value: 'ke'), - kyrgyzstan(value: 'kg'), - cambodia(value: 'kh'), - kiribati(value: 'ki'), - saintKittsAndNevis(value: 'kn'), - southKorea(value: 'kr'), - kuwait(value: 'kw'), - laoPeopleSDemocraticRepublic(value: 'la'), - lebanon(value: 'lb'), - liberia(value: 'lr'), - libya(value: 'ly'), - saintLucia(value: 'lc'), - liechtenstein(value: 'li'), - sriLanka(value: 'lk'), - lesotho(value: 'ls'), - lithuania(value: 'lt'), - luxembourg(value: 'lu'), - latvia(value: 'lv'), - morocco(value: 'ma'), - monaco(value: 'mc'), - moldova(value: 'md'), - madagascar(value: 'mg'), - maldives(value: 'mv'), - mexico(value: 'mx'), - marshallIslands(value: 'mh'), - northMacedonia(value: 'mk'), - mali(value: 'ml'), - malta(value: 'mt'), - myanmar(value: 'mm'), - montenegro(value: 'me'), - mongolia(value: 'mn'), - mozambique(value: 'mz'), - mauritania(value: 'mr'), - mauritius(value: 'mu'), - malawi(value: 'mw'), - malaysia(value: 'my'), - namibia(value: 'na'), - niger(value: 'ne'), - nigeria(value: 'ng'), - nicaragua(value: 'ni'), - netherlands(value: 'nl'), - norway(value: 'no'), - nepal(value: 'np'), - nauru(value: 'nr'), - newZealand(value: 'nz'), - oman(value: 'om'), - pakistan(value: 'pk'), - panama(value: 'pa'), - peru(value: 'pe'), - philippines(value: 'ph'), - palau(value: 'pw'), - papuaNewGuinea(value: 'pg'), - poland(value: 'pl'), - frenchPolynesia(value: 'pf'), - northKorea(value: 'kp'), - portugal(value: 'pt'), - paraguay(value: 'py'), - qatar(value: 'qa'), - romania(value: 'ro'), - russia(value: 'ru'), - rwanda(value: 'rw'), - saudiArabia(value: 'sa'), - sudan(value: 'sd'), - senegal(value: 'sn'), - singapore(value: 'sg'), - solomonIslands(value: 'sb'), - sierraLeone(value: 'sl'), - elSalvador(value: 'sv'), - sanMarino(value: 'sm'), - somalia(value: 'so'), - serbia(value: 'rs'), - southSudan(value: 'ss'), - saoTomeAndPrincipe(value: 'st'), - suriname(value: 'sr'), - slovakia(value: 'sk'), - slovenia(value: 'si'), - sweden(value: 'se'), - eswatini(value: 'sz'), - seychelles(value: 'sc'), - syria(value: 'sy'), - chad(value: 'td'), - togo(value: 'tg'), - thailand(value: 'th'), - tajikistan(value: 'tj'), - turkmenistan(value: 'tm'), - timorLeste(value: 'tl'), - tonga(value: 'to'), - trinidadAndTobago(value: 'tt'), - tunisia(value: 'tn'), - turkey(value: 'tr'), - tuvalu(value: 'tv'), - tanzania(value: 'tz'), - uganda(value: 'ug'), - ukraine(value: 'ua'), - uruguay(value: 'uy'), - unitedStates(value: 'us'), - uzbekistan(value: 'uz'), - vaticanCity(value: 'va'), - saintVincentAndTheGrenadines(value: 'vc'), - venezuela(value: 've'), - vietnam(value: 'vn'), - vanuatu(value: 'vu'), - samoa(value: 'ws'), - yemen(value: 'ye'), - southAfrica(value: 'za'), - zambia(value: 'zm'), - zimbabwe(value: 'zw'); + afghanistan(value: 'af'), + angola(value: 'ao'), + albania(value: 'al'), + andorra(value: 'ad'), + unitedArabEmirates(value: 'ae'), + argentina(value: 'ar'), + armenia(value: 'am'), + antiguaAndBarbuda(value: 'ag'), + australia(value: 'au'), + austria(value: 'at'), + azerbaijan(value: 'az'), + burundi(value: 'bi'), + belgium(value: 'be'), + benin(value: 'bj'), + burkinaFaso(value: 'bf'), + bangladesh(value: 'bd'), + bulgaria(value: 'bg'), + bahrain(value: 'bh'), + bahamas(value: 'bs'), + bosniaAndHerzegovina(value: 'ba'), + belarus(value: 'by'), + belize(value: 'bz'), + bolivia(value: 'bo'), + brazil(value: 'br'), + barbados(value: 'bb'), + bruneiDarussalam(value: 'bn'), + bhutan(value: 'bt'), + botswana(value: 'bw'), + centralAfricanRepublic(value: 'cf'), + canada(value: 'ca'), + switzerland(value: 'ch'), + chile(value: 'cl'), + china(value: 'cn'), + coteDIvoire(value: 'ci'), + cameroon(value: 'cm'), + democraticRepublicOfTheCongo(value: 'cd'), + republicOfTheCongo(value: 'cg'), + colombia(value: 'co'), + comoros(value: 'km'), + capeVerde(value: 'cv'), + costaRica(value: 'cr'), + cuba(value: 'cu'), + cyprus(value: 'cy'), + czechRepublic(value: 'cz'), + germany(value: 'de'), + djibouti(value: 'dj'), + dominica(value: 'dm'), + denmark(value: 'dk'), + dominicanRepublic(value: 'do'), + algeria(value: 'dz'), + ecuador(value: 'ec'), + egypt(value: 'eg'), + eritrea(value: 'er'), + spain(value: 'es'), + estonia(value: 'ee'), + ethiopia(value: 'et'), + finland(value: 'fi'), + fiji(value: 'fj'), + france(value: 'fr'), + micronesiaFederatedStatesOf(value: 'fm'), + gabon(value: 'ga'), + unitedKingdom(value: 'gb'), + georgia(value: 'ge'), + ghana(value: 'gh'), + guinea(value: 'gn'), + gambia(value: 'gm'), + guineaBissau(value: 'gw'), + equatorialGuinea(value: 'gq'), + greece(value: 'gr'), + grenada(value: 'gd'), + guatemala(value: 'gt'), + guyana(value: 'gy'), + honduras(value: 'hn'), + croatia(value: 'hr'), + haiti(value: 'ht'), + hungary(value: 'hu'), + indonesia(value: 'id'), + india(value: 'in'), + ireland(value: 'ie'), + iranIslamicRepublicOf(value: 'ir'), + iraq(value: 'iq'), + iceland(value: 'is'), + israel(value: 'il'), + italy(value: 'it'), + jamaica(value: 'jm'), + jordan(value: 'jo'), + japan(value: 'jp'), + kazakhstan(value: 'kz'), + kenya(value: 'ke'), + kyrgyzstan(value: 'kg'), + cambodia(value: 'kh'), + kiribati(value: 'ki'), + saintKittsAndNevis(value: 'kn'), + southKorea(value: 'kr'), + kuwait(value: 'kw'), + laoPeopleSDemocraticRepublic(value: 'la'), + lebanon(value: 'lb'), + liberia(value: 'lr'), + libya(value: 'ly'), + saintLucia(value: 'lc'), + liechtenstein(value: 'li'), + sriLanka(value: 'lk'), + lesotho(value: 'ls'), + lithuania(value: 'lt'), + luxembourg(value: 'lu'), + latvia(value: 'lv'), + morocco(value: 'ma'), + monaco(value: 'mc'), + moldova(value: 'md'), + madagascar(value: 'mg'), + maldives(value: 'mv'), + mexico(value: 'mx'), + marshallIslands(value: 'mh'), + northMacedonia(value: 'mk'), + mali(value: 'ml'), + malta(value: 'mt'), + myanmar(value: 'mm'), + montenegro(value: 'me'), + mongolia(value: 'mn'), + mozambique(value: 'mz'), + mauritania(value: 'mr'), + mauritius(value: 'mu'), + malawi(value: 'mw'), + malaysia(value: 'my'), + namibia(value: 'na'), + niger(value: 'ne'), + nigeria(value: 'ng'), + nicaragua(value: 'ni'), + netherlands(value: 'nl'), + norway(value: 'no'), + nepal(value: 'np'), + nauru(value: 'nr'), + newZealand(value: 'nz'), + oman(value: 'om'), + pakistan(value: 'pk'), + panama(value: 'pa'), + peru(value: 'pe'), + philippines(value: 'ph'), + palau(value: 'pw'), + papuaNewGuinea(value: 'pg'), + poland(value: 'pl'), + frenchPolynesia(value: 'pf'), + northKorea(value: 'kp'), + portugal(value: 'pt'), + paraguay(value: 'py'), + qatar(value: 'qa'), + romania(value: 'ro'), + russia(value: 'ru'), + rwanda(value: 'rw'), + saudiArabia(value: 'sa'), + sudan(value: 'sd'), + senegal(value: 'sn'), + singapore(value: 'sg'), + solomonIslands(value: 'sb'), + sierraLeone(value: 'sl'), + elSalvador(value: 'sv'), + sanMarino(value: 'sm'), + somalia(value: 'so'), + serbia(value: 'rs'), + southSudan(value: 'ss'), + saoTomeAndPrincipe(value: 'st'), + suriname(value: 'sr'), + slovakia(value: 'sk'), + slovenia(value: 'si'), + sweden(value: 'se'), + eswatini(value: 'sz'), + seychelles(value: 'sc'), + syria(value: 'sy'), + chad(value: 'td'), + togo(value: 'tg'), + thailand(value: 'th'), + tajikistan(value: 'tj'), + turkmenistan(value: 'tm'), + timorLeste(value: 'tl'), + tonga(value: 'to'), + trinidadAndTobago(value: 'tt'), + tunisia(value: 'tn'), + turkey(value: 'tr'), + tuvalu(value: 'tv'), + tanzania(value: 'tz'), + uganda(value: 'ug'), + ukraine(value: 'ua'), + uruguay(value: 'uy'), + unitedStates(value: 'us'), + uzbekistan(value: 'uz'), + vaticanCity(value: 'va'), + saintVincentAndTheGrenadines(value: 'vc'), + venezuela(value: 've'), + vietnam(value: 'vn'), + vanuatu(value: 'vu'), + samoa(value: 'ws'), + yemen(value: 'ye'), + southAfrica(value: 'za'), + zambia(value: 'zm'), + zimbabwe(value: 'zw'); - const Flag({ - required this.value - }); + const Flag({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/image_format.dart b/lib/src/enums/image_format.dart index 66527dfa..2ab5d7b9 100644 --- a/lib/src/enums/image_format.dart +++ b/lib/src/enums/image_format.dart @@ -1,17 +1,15 @@ part of '../../enums.dart'; enum ImageFormat { - jpg(value: 'jpg'), - jpeg(value: 'jpeg'), - gif(value: 'gif'), - png(value: 'png'), - webp(value: 'webp'); + jpg(value: 'jpg'), + jpeg(value: 'jpeg'), + gif(value: 'gif'), + png(value: 'png'), + webp(value: 'webp'); - const ImageFormat({ - required this.value - }); + const ImageFormat({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/image_gravity.dart b/lib/src/enums/image_gravity.dart index 79bc4d62..88029044 100644 --- a/lib/src/enums/image_gravity.dart +++ b/lib/src/enums/image_gravity.dart @@ -1,21 +1,19 @@ part of '../../enums.dart'; enum ImageGravity { - center(value: 'center'), - topLeft(value: 'top-left'), - top(value: 'top'), - topRight(value: 'top-right'), - left(value: 'left'), - right(value: 'right'), - bottomLeft(value: 'bottom-left'), - bottom(value: 'bottom'), - bottomRight(value: 'bottom-right'); + center(value: 'center'), + topLeft(value: 'top-left'), + top(value: 'top'), + topRight(value: 'top-right'), + left(value: 'left'), + right(value: 'right'), + bottomLeft(value: 'bottom-left'), + bottom(value: 'bottom'), + bottomRight(value: 'bottom-right'); - const ImageGravity({ - required this.value - }); + const ImageGravity({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/index_type.dart b/lib/src/enums/index_type.dart index 8d86530d..b101d35f 100644 --- a/lib/src/enums/index_type.dart +++ b/lib/src/enums/index_type.dart @@ -1,15 +1,13 @@ part of '../../enums.dart'; enum IndexType { - key(value: 'key'), - fulltext(value: 'fulltext'), - unique(value: 'unique'); + key(value: 'key'), + fulltext(value: 'fulltext'), + unique(value: 'unique'); - const IndexType({ - required this.value - }); + const IndexType({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/messaging_provider_type.dart b/lib/src/enums/messaging_provider_type.dart index a6859648..c69bf01e 100644 --- a/lib/src/enums/messaging_provider_type.dart +++ b/lib/src/enums/messaging_provider_type.dart @@ -1,15 +1,13 @@ part of '../../enums.dart'; enum MessagingProviderType { - email(value: 'email'), - sms(value: 'sms'), - push(value: 'push'); + email(value: 'email'), + sms(value: 'sms'), + push(value: 'push'); - const MessagingProviderType({ - required this.value - }); + const MessagingProviderType({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/name.dart b/lib/src/enums/name.dart index 638017f7..cb35c288 100644 --- a/lib/src/enums/name.dart +++ b/lib/src/enums/name.dart @@ -1,24 +1,22 @@ part of '../../enums.dart'; enum Name { - v1Database(value: 'v1-database'), - v1Deletes(value: 'v1-deletes'), - v1Audits(value: 'v1-audits'), - v1Mails(value: 'v1-mails'), - v1Functions(value: 'v1-functions'), - v1Usage(value: 'v1-usage'), - v1UsageDump(value: 'v1-usage-dump'), - v1Webhooks(value: 'v1-webhooks'), - v1Certificates(value: 'v1-certificates'), - v1Builds(value: 'v1-builds'), - v1Messaging(value: 'v1-messaging'), - v1Migrations(value: 'v1-migrations'); + v1Database(value: 'v1-database'), + v1Deletes(value: 'v1-deletes'), + v1Audits(value: 'v1-audits'), + v1Mails(value: 'v1-mails'), + v1Functions(value: 'v1-functions'), + v1Usage(value: 'v1-usage'), + v1UsageDump(value: 'v1-usage-dump'), + v1Webhooks(value: 'v1-webhooks'), + v1Certificates(value: 'v1-certificates'), + v1Builds(value: 'v1-builds'), + v1Messaging(value: 'v1-messaging'), + v1Migrations(value: 'v1-migrations'); - const Name({ - required this.value - }); + const Name({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/o_auth_provider.dart b/lib/src/enums/o_auth_provider.dart index b09e9df2..2bc1a82a 100644 --- a/lib/src/enums/o_auth_provider.dart +++ b/lib/src/enums/o_auth_provider.dart @@ -1,51 +1,49 @@ part of '../../enums.dart'; enum OAuthProvider { - amazon(value: 'amazon'), - apple(value: 'apple'), - auth0(value: 'auth0'), - authentik(value: 'authentik'), - autodesk(value: 'autodesk'), - bitbucket(value: 'bitbucket'), - bitly(value: 'bitly'), - box(value: 'box'), - dailymotion(value: 'dailymotion'), - discord(value: 'discord'), - disqus(value: 'disqus'), - dropbox(value: 'dropbox'), - etsy(value: 'etsy'), - facebook(value: 'facebook'), - github(value: 'github'), - gitlab(value: 'gitlab'), - google(value: 'google'), - linkedin(value: 'linkedin'), - microsoft(value: 'microsoft'), - notion(value: 'notion'), - oidc(value: 'oidc'), - okta(value: 'okta'), - paypal(value: 'paypal'), - paypalSandbox(value: 'paypalSandbox'), - podio(value: 'podio'), - salesforce(value: 'salesforce'), - slack(value: 'slack'), - spotify(value: 'spotify'), - stripe(value: 'stripe'), - tradeshift(value: 'tradeshift'), - tradeshiftBox(value: 'tradeshiftBox'), - twitch(value: 'twitch'), - wordpress(value: 'wordpress'), - yahoo(value: 'yahoo'), - yammer(value: 'yammer'), - yandex(value: 'yandex'), - zoho(value: 'zoho'), - zoom(value: 'zoom'), - mock(value: 'mock'); + amazon(value: 'amazon'), + apple(value: 'apple'), + auth0(value: 'auth0'), + authentik(value: 'authentik'), + autodesk(value: 'autodesk'), + bitbucket(value: 'bitbucket'), + bitly(value: 'bitly'), + box(value: 'box'), + dailymotion(value: 'dailymotion'), + discord(value: 'discord'), + disqus(value: 'disqus'), + dropbox(value: 'dropbox'), + etsy(value: 'etsy'), + facebook(value: 'facebook'), + github(value: 'github'), + gitlab(value: 'gitlab'), + google(value: 'google'), + linkedin(value: 'linkedin'), + microsoft(value: 'microsoft'), + notion(value: 'notion'), + oidc(value: 'oidc'), + okta(value: 'okta'), + paypal(value: 'paypal'), + paypalSandbox(value: 'paypalSandbox'), + podio(value: 'podio'), + salesforce(value: 'salesforce'), + slack(value: 'slack'), + spotify(value: 'spotify'), + stripe(value: 'stripe'), + tradeshift(value: 'tradeshift'), + tradeshiftBox(value: 'tradeshiftBox'), + twitch(value: 'twitch'), + wordpress(value: 'wordpress'), + yahoo(value: 'yahoo'), + yammer(value: 'yammer'), + yandex(value: 'yandex'), + zoho(value: 'zoho'), + zoom(value: 'zoom'), + mock(value: 'mock'); - const OAuthProvider({ - required this.value - }); + const OAuthProvider({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/password_hash.dart b/lib/src/enums/password_hash.dart index 510ee260..9d98c26a 100644 --- a/lib/src/enums/password_hash.dart +++ b/lib/src/enums/password_hash.dart @@ -1,23 +1,21 @@ part of '../../enums.dart'; enum PasswordHash { - sha1(value: 'sha1'), - sha224(value: 'sha224'), - sha256(value: 'sha256'), - sha384(value: 'sha384'), - sha512224(value: 'sha512/224'), - sha512256(value: 'sha512/256'), - sha512(value: 'sha512'), - sha3224(value: 'sha3-224'), - sha3256(value: 'sha3-256'), - sha3384(value: 'sha3-384'), - sha3512(value: 'sha3-512'); + sha1(value: 'sha1'), + sha224(value: 'sha224'), + sha256(value: 'sha256'), + sha384(value: 'sha384'), + sha512224(value: 'sha512/224'), + sha512256(value: 'sha512/256'), + sha512(value: 'sha512'), + sha3224(value: 'sha3-224'), + sha3256(value: 'sha3-256'), + sha3384(value: 'sha3-384'), + sha3512(value: 'sha3-512'); - const PasswordHash({ - required this.value - }); + const PasswordHash({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/relation_mutate.dart b/lib/src/enums/relation_mutate.dart index 9f4c1a85..b215a8fa 100644 --- a/lib/src/enums/relation_mutate.dart +++ b/lib/src/enums/relation_mutate.dart @@ -1,15 +1,13 @@ part of '../../enums.dart'; enum RelationMutate { - cascade(value: 'cascade'), - restrict(value: 'restrict'), - setNull(value: 'setNull'); + cascade(value: 'cascade'), + restrict(value: 'restrict'), + setNull(value: 'setNull'); - const RelationMutate({ - required this.value - }); + const RelationMutate({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/relationship_type.dart b/lib/src/enums/relationship_type.dart index 301bc61d..30efc944 100644 --- a/lib/src/enums/relationship_type.dart +++ b/lib/src/enums/relationship_type.dart @@ -1,16 +1,14 @@ part of '../../enums.dart'; enum RelationshipType { - oneToOne(value: 'oneToOne'), - manyToOne(value: 'manyToOne'), - manyToMany(value: 'manyToMany'), - oneToMany(value: 'oneToMany'); + oneToOne(value: 'oneToOne'), + manyToOne(value: 'manyToOne'), + manyToMany(value: 'manyToMany'), + oneToMany(value: 'oneToMany'); - const RelationshipType({ - required this.value - }); + const RelationshipType({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/runtime.dart b/lib/src/enums/runtime.dart index 6a0aec49..a4868100 100644 --- a/lib/src/enums/runtime.dart +++ b/lib/src/enums/runtime.dart @@ -1,61 +1,59 @@ part of '../../enums.dart'; enum Runtime { - node145(value: 'node-14.5'), - node160(value: 'node-16.0'), - node180(value: 'node-18.0'), - node190(value: 'node-19.0'), - node200(value: 'node-20.0'), - node210(value: 'node-21.0'), - php80(value: 'php-8.0'), - php81(value: 'php-8.1'), - php82(value: 'php-8.2'), - php83(value: 'php-8.3'), - ruby30(value: 'ruby-3.0'), - ruby31(value: 'ruby-3.1'), - ruby32(value: 'ruby-3.2'), - ruby33(value: 'ruby-3.3'), - python38(value: 'python-3.8'), - python39(value: 'python-3.9'), - python310(value: 'python-3.10'), - python311(value: 'python-3.11'), - python312(value: 'python-3.12'), - pythonMl311(value: 'python-ml-3.11'), - deno121(value: 'deno-1.21'), - deno124(value: 'deno-1.24'), - deno135(value: 'deno-1.35'), - deno140(value: 'deno-1.40'), - dart215(value: 'dart-2.15'), - dart216(value: 'dart-2.16'), - dart217(value: 'dart-2.17'), - dart218(value: 'dart-2.18'), - dart30(value: 'dart-3.0'), - dart31(value: 'dart-3.1'), - dart33(value: 'dart-3.3'), - dotnet31(value: 'dotnet-3.1'), - dotnet60(value: 'dotnet-6.0'), - dotnet70(value: 'dotnet-7.0'), - java80(value: 'java-8.0'), - java110(value: 'java-11.0'), - java170(value: 'java-17.0'), - java180(value: 'java-18.0'), - java210(value: 'java-21.0'), - swift55(value: 'swift-5.5'), - swift58(value: 'swift-5.8'), - swift59(value: 'swift-5.9'), - kotlin16(value: 'kotlin-1.6'), - kotlin18(value: 'kotlin-1.8'), - kotlin19(value: 'kotlin-1.9'), - cpp17(value: 'cpp-17'), - cpp20(value: 'cpp-20'), - bun10(value: 'bun-1.0'), - go123(value: 'go-1.23'); + node145(value: 'node-14.5'), + node160(value: 'node-16.0'), + node180(value: 'node-18.0'), + node190(value: 'node-19.0'), + node200(value: 'node-20.0'), + node210(value: 'node-21.0'), + php80(value: 'php-8.0'), + php81(value: 'php-8.1'), + php82(value: 'php-8.2'), + php83(value: 'php-8.3'), + ruby30(value: 'ruby-3.0'), + ruby31(value: 'ruby-3.1'), + ruby32(value: 'ruby-3.2'), + ruby33(value: 'ruby-3.3'), + python38(value: 'python-3.8'), + python39(value: 'python-3.9'), + python310(value: 'python-3.10'), + python311(value: 'python-3.11'), + python312(value: 'python-3.12'), + pythonMl311(value: 'python-ml-3.11'), + deno121(value: 'deno-1.21'), + deno124(value: 'deno-1.24'), + deno135(value: 'deno-1.35'), + deno140(value: 'deno-1.40'), + dart215(value: 'dart-2.15'), + dart216(value: 'dart-2.16'), + dart217(value: 'dart-2.17'), + dart218(value: 'dart-2.18'), + dart30(value: 'dart-3.0'), + dart31(value: 'dart-3.1'), + dart33(value: 'dart-3.3'), + dotnet31(value: 'dotnet-3.1'), + dotnet60(value: 'dotnet-6.0'), + dotnet70(value: 'dotnet-7.0'), + java80(value: 'java-8.0'), + java110(value: 'java-11.0'), + java170(value: 'java-17.0'), + java180(value: 'java-18.0'), + java210(value: 'java-21.0'), + swift55(value: 'swift-5.5'), + swift58(value: 'swift-5.8'), + swift59(value: 'swift-5.9'), + kotlin16(value: 'kotlin-1.6'), + kotlin18(value: 'kotlin-1.8'), + kotlin19(value: 'kotlin-1.9'), + cpp17(value: 'cpp-17'), + cpp20(value: 'cpp-20'), + bun10(value: 'bun-1.0'), + go123(value: 'go-1.23'); - const Runtime({ - required this.value - }); + const Runtime({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/smtp_encryption.dart b/lib/src/enums/smtp_encryption.dart index 6c880ed6..cb6cee26 100644 --- a/lib/src/enums/smtp_encryption.dart +++ b/lib/src/enums/smtp_encryption.dart @@ -1,15 +1,13 @@ part of '../../enums.dart'; enum SmtpEncryption { - none(value: 'none'), - ssl(value: 'ssl'), - tls(value: 'tls'); + none(value: 'none'), + ssl(value: 'ssl'), + tls(value: 'tls'); - const SmtpEncryption({ - required this.value - }); + const SmtpEncryption({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/exception.dart b/lib/src/exception.dart index f579bfb8..679e27b8 100644 --- a/lib/src/exception.dart +++ b/lib/src/exception.dart @@ -13,7 +13,7 @@ class AppwriteException implements Exception { /// Initializes an Appwrite Exception. AppwriteException([this.message = "", this.code, this.type, this.response]); - + /// Returns the error type, message, and code. @override String toString() { diff --git a/lib/src/models/algo_argon2.dart b/lib/src/models/algo_argon2.dart index 92fa2593..9ad2e41e 100644 --- a/lib/src/models/algo_argon2.dart +++ b/lib/src/models/algo_argon2.dart @@ -2,40 +2,46 @@ part of '../../models.dart'; /// AlgoArgon2 class AlgoArgon2 implements Model { - /// Algo type. - final String type; - /// Memory used to compute hash. - final int memoryCost; - /// Amount of time consumed to compute hash - final int timeCost; - /// Number of threads used to compute hash. - final int threads; + /// Algo type. + final String type; - AlgoArgon2({ - required this.type, - required this.memoryCost, - required this.timeCost, - required this.threads, - }); + /// Memory used to compute hash. + final int memoryCost; - factory AlgoArgon2.fromMap(Map map) { - return AlgoArgon2( - type: map['type'].toString(), - memoryCost: (map['memoryCost'] is String) ? - int.tryParse(map['memoryCost']) ?? 0:map['memoryCost'] ?? 0, - timeCost: (map['timeCost'] is String) ? - int.tryParse(map['timeCost']) ?? 0:map['timeCost'] ?? 0, - threads: (map['threads'] is String) ? - int.tryParse(map['threads']) ?? 0:map['threads'] ?? 0, - ); - } + /// Amount of time consumed to compute hash + final int timeCost; - Map toMap() { - return { - "type": type, - "memoryCost": memoryCost, - "timeCost": timeCost, - "threads": threads, - }; - } + /// Number of threads used to compute hash. + final int threads; + + AlgoArgon2({ + required this.type, + required this.memoryCost, + required this.timeCost, + required this.threads, + }); + + factory AlgoArgon2.fromMap(Map map) { + return AlgoArgon2( + type: map['type'].toString(), + memoryCost: (map['memoryCost'] is String) + ? int.tryParse(map['memoryCost']) ?? 0 + : map['memoryCost'] ?? 0, + timeCost: (map['timeCost'] is String) + ? int.tryParse(map['timeCost']) ?? 0 + : map['timeCost'] ?? 0, + threads: (map['threads'] is String) + ? int.tryParse(map['threads']) ?? 0 + : map['threads'] ?? 0, + ); + } + + Map toMap() { + return { + "type": type, + "memoryCost": memoryCost, + "timeCost": timeCost, + "threads": threads, + }; + } } diff --git a/lib/src/models/algo_bcrypt.dart b/lib/src/models/algo_bcrypt.dart index c9f67200..2ba0c398 100644 --- a/lib/src/models/algo_bcrypt.dart +++ b/lib/src/models/algo_bcrypt.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoBcrypt class AlgoBcrypt implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoBcrypt({ - required this.type, - }); + AlgoBcrypt({ + required this.type, + }); - factory AlgoBcrypt.fromMap(Map map) { - return AlgoBcrypt( - type: map['type'].toString(), - ); - } + factory AlgoBcrypt.fromMap(Map map) { + return AlgoBcrypt( + type: map['type'].toString(), + ); + } - Map toMap() { - return { - "type": type, - }; - } + Map toMap() { + return { + "type": type, + }; + } } diff --git a/lib/src/models/algo_md5.dart b/lib/src/models/algo_md5.dart index 2fabb416..8bdfca6f 100644 --- a/lib/src/models/algo_md5.dart +++ b/lib/src/models/algo_md5.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoMD5 class AlgoMd5 implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoMd5({ - required this.type, - }); + AlgoMd5({ + required this.type, + }); - factory AlgoMd5.fromMap(Map map) { - return AlgoMd5( - type: map['type'].toString(), - ); - } + factory AlgoMd5.fromMap(Map map) { + return AlgoMd5( + type: map['type'].toString(), + ); + } - Map toMap() { - return { - "type": type, - }; - } + Map toMap() { + return { + "type": type, + }; + } } diff --git a/lib/src/models/algo_phpass.dart b/lib/src/models/algo_phpass.dart index fdcee07a..4f5f9179 100644 --- a/lib/src/models/algo_phpass.dart +++ b/lib/src/models/algo_phpass.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoPHPass class AlgoPhpass implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoPhpass({ - required this.type, - }); + AlgoPhpass({ + required this.type, + }); - factory AlgoPhpass.fromMap(Map map) { - return AlgoPhpass( - type: map['type'].toString(), - ); - } + factory AlgoPhpass.fromMap(Map map) { + return AlgoPhpass( + type: map['type'].toString(), + ); + } - Map toMap() { - return { - "type": type, - }; - } + Map toMap() { + return { + "type": type, + }; + } } diff --git a/lib/src/models/algo_scrypt.dart b/lib/src/models/algo_scrypt.dart index c3e55453..ee54b5e4 100644 --- a/lib/src/models/algo_scrypt.dart +++ b/lib/src/models/algo_scrypt.dart @@ -2,46 +2,54 @@ part of '../../models.dart'; /// AlgoScrypt class AlgoScrypt implements Model { - /// Algo type. - final String type; - /// CPU complexity of computed hash. - final int costCpu; - /// Memory complexity of computed hash. - final int costMemory; - /// Parallelization of computed hash. - final int costParallel; - /// Length used to compute hash. - final int length; - - AlgoScrypt({ - required this.type, - required this.costCpu, - required this.costMemory, - required this.costParallel, - required this.length, - }); - - factory AlgoScrypt.fromMap(Map map) { - return AlgoScrypt( - type: map['type'].toString(), - costCpu: (map['costCpu'] is String) ? - int.tryParse(map['costCpu']) ?? 0:map['costCpu'] ?? 0, - costMemory: (map['costMemory'] is String) ? - int.tryParse(map['costMemory']) ?? 0:map['costMemory'] ?? 0, - costParallel: (map['costParallel'] is String) ? - int.tryParse(map['costParallel']) ?? 0:map['costParallel'] ?? 0, - length: (map['length'] is String) ? - int.tryParse(map['length']) ?? 0:map['length'] ?? 0, - ); - } - - Map toMap() { - return { - "type": type, - "costCpu": costCpu, - "costMemory": costMemory, - "costParallel": costParallel, - "length": length, - }; - } + /// Algo type. + final String type; + + /// CPU complexity of computed hash. + final int costCpu; + + /// Memory complexity of computed hash. + final int costMemory; + + /// Parallelization of computed hash. + final int costParallel; + + /// Length used to compute hash. + final int length; + + AlgoScrypt({ + required this.type, + required this.costCpu, + required this.costMemory, + required this.costParallel, + required this.length, + }); + + factory AlgoScrypt.fromMap(Map map) { + return AlgoScrypt( + type: map['type'].toString(), + costCpu: (map['costCpu'] is String) + ? int.tryParse(map['costCpu']) ?? 0 + : map['costCpu'] ?? 0, + costMemory: (map['costMemory'] is String) + ? int.tryParse(map['costMemory']) ?? 0 + : map['costMemory'] ?? 0, + costParallel: (map['costParallel'] is String) + ? int.tryParse(map['costParallel']) ?? 0 + : map['costParallel'] ?? 0, + length: (map['length'] is String) + ? int.tryParse(map['length']) ?? 0 + : map['length'] ?? 0, + ); + } + + Map toMap() { + return { + "type": type, + "costCpu": costCpu, + "costMemory": costMemory, + "costParallel": costParallel, + "length": length, + }; + } } diff --git a/lib/src/models/algo_scrypt_modified.dart b/lib/src/models/algo_scrypt_modified.dart index b10b14a6..0e80700f 100644 --- a/lib/src/models/algo_scrypt_modified.dart +++ b/lib/src/models/algo_scrypt_modified.dart @@ -2,37 +2,40 @@ part of '../../models.dart'; /// AlgoScryptModified class AlgoScryptModified implements Model { - /// Algo type. - final String type; - /// Salt used to compute hash. - final String salt; - /// Separator used to compute hash. - final String saltSeparator; - /// Key used to compute hash. - final String signerKey; + /// Algo type. + final String type; - AlgoScryptModified({ - required this.type, - required this.salt, - required this.saltSeparator, - required this.signerKey, - }); + /// Salt used to compute hash. + final String salt; - factory AlgoScryptModified.fromMap(Map map) { - return AlgoScryptModified( - type: map['type'].toString(), - salt: map['salt'].toString(), - saltSeparator: map['saltSeparator'].toString(), - signerKey: map['signerKey'].toString(), - ); - } + /// Separator used to compute hash. + final String saltSeparator; - Map toMap() { - return { - "type": type, - "salt": salt, - "saltSeparator": saltSeparator, - "signerKey": signerKey, - }; - } + /// Key used to compute hash. + final String signerKey; + + AlgoScryptModified({ + required this.type, + required this.salt, + required this.saltSeparator, + required this.signerKey, + }); + + factory AlgoScryptModified.fromMap(Map map) { + return AlgoScryptModified( + type: map['type'].toString(), + salt: map['salt'].toString(), + saltSeparator: map['saltSeparator'].toString(), + signerKey: map['signerKey'].toString(), + ); + } + + Map toMap() { + return { + "type": type, + "salt": salt, + "saltSeparator": saltSeparator, + "signerKey": signerKey, + }; + } } diff --git a/lib/src/models/algo_sha.dart b/lib/src/models/algo_sha.dart index 5f3e1654..47068be0 100644 --- a/lib/src/models/algo_sha.dart +++ b/lib/src/models/algo_sha.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoSHA class AlgoSha implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoSha({ - required this.type, - }); + AlgoSha({ + required this.type, + }); - factory AlgoSha.fromMap(Map map) { - return AlgoSha( - type: map['type'].toString(), - ); - } + factory AlgoSha.fromMap(Map map) { + return AlgoSha( + type: map['type'].toString(), + ); + } - Map toMap() { - return { - "type": type, - }; - } + Map toMap() { + return { + "type": type, + }; + } } diff --git a/lib/src/models/attribute_boolean.dart b/lib/src/models/attribute_boolean.dart index 480c2042..0b8ca599 100644 --- a/lib/src/models/attribute_boolean.dart +++ b/lib/src/models/attribute_boolean.dart @@ -2,52 +2,58 @@ part of '../../models.dart'; /// AttributeBoolean class AttributeBoolean implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final bool? xdefault; - - AttributeBoolean({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - this.xdefault, - }); - - factory AttributeBoolean.fromMap(Map map) { - return AttributeBoolean( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - xdefault: map['default'], - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + + /// Attribute type. + final String type; + + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final bool? xdefault; + + AttributeBoolean({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + this.xdefault, + }); + + factory AttributeBoolean.fromMap(Map map) { + return AttributeBoolean( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + xdefault: map['default'], + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_datetime.dart b/lib/src/models/attribute_datetime.dart index 078a0723..c4c96637 100644 --- a/lib/src/models/attribute_datetime.dart +++ b/lib/src/models/attribute_datetime.dart @@ -2,57 +2,64 @@ part of '../../models.dart'; /// AttributeDatetime class AttributeDatetime implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// ISO 8601 format. - final String format; - /// Default value for attribute when not provided. Only null is optional - final String? xdefault; - - AttributeDatetime({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.format, - this.xdefault, - }); - - factory AttributeDatetime.fromMap(Map map) { - return AttributeDatetime( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "format": format, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + + /// Attribute type. + final String type; + + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// ISO 8601 format. + final String format; + + /// Default value for attribute when not provided. Only null is optional + final String? xdefault; + + AttributeDatetime({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.format, + this.xdefault, + }); + + factory AttributeDatetime.fromMap(Map map) { + return AttributeDatetime( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_email.dart b/lib/src/models/attribute_email.dart index 08a67934..5d2fc8bd 100644 --- a/lib/src/models/attribute_email.dart +++ b/lib/src/models/attribute_email.dart @@ -2,57 +2,64 @@ part of '../../models.dart'; /// AttributeEmail class AttributeEmail implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// String format. - final String format; - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeEmail({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.format, - this.xdefault, - }); - - factory AttributeEmail.fromMap(Map map) { - return AttributeEmail( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "format": format, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + + /// Attribute type. + final String type; + + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// String format. + final String format; + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeEmail({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.format, + this.xdefault, + }); + + factory AttributeEmail.fromMap(Map map) { + return AttributeEmail( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_enum.dart b/lib/src/models/attribute_enum.dart index d461ecf4..0017a44e 100644 --- a/lib/src/models/attribute_enum.dart +++ b/lib/src/models/attribute_enum.dart @@ -2,62 +2,70 @@ part of '../../models.dart'; /// AttributeEnum class AttributeEnum implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// Array of elements in enumerated type. - final List elements; - /// String format. - final String format; - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeEnum({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.elements, - required this.format, - this.xdefault, - }); - - factory AttributeEnum.fromMap(Map map) { - return AttributeEnum( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - elements: map['elements'] ?? [], - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "elements": elements, - "format": format, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + + /// Attribute type. + final String type; + + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// Array of elements in enumerated type. + final List elements; + + /// String format. + final String format; + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeEnum({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.elements, + required this.format, + this.xdefault, + }); + + factory AttributeEnum.fromMap(Map map) { + return AttributeEnum( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + elements: map['elements'] ?? [], + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "elements": elements, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_float.dart b/lib/src/models/attribute_float.dart index 6d085aa4..7c982afb 100644 --- a/lib/src/models/attribute_float.dart +++ b/lib/src/models/attribute_float.dart @@ -2,62 +2,70 @@ part of '../../models.dart'; /// AttributeFloat class AttributeFloat implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// Minimum value to enforce for new documents. - final double? min; - /// Maximum value to enforce for new documents. - final double? max; - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final double? xdefault; - - AttributeFloat({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - this.min, - this.max, - this.xdefault, - }); - - factory AttributeFloat.fromMap(Map map) { - return AttributeFloat( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - min: map['min']?.toDouble(), - max: map['max']?.toDouble(), - xdefault: map['default']?.toDouble(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "min": min, - "max": max, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + + /// Attribute type. + final String type; + + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// Minimum value to enforce for new documents. + final double? min; + + /// Maximum value to enforce for new documents. + final double? max; + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final double? xdefault; + + AttributeFloat({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + this.min, + this.max, + this.xdefault, + }); + + factory AttributeFloat.fromMap(Map map) { + return AttributeFloat( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + min: map['min']?.toDouble(), + max: map['max']?.toDouble(), + xdefault: map['default']?.toDouble(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "min": min, + "max": max, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_integer.dart b/lib/src/models/attribute_integer.dart index 83e36858..4c74127c 100644 --- a/lib/src/models/attribute_integer.dart +++ b/lib/src/models/attribute_integer.dart @@ -2,65 +2,72 @@ part of '../../models.dart'; /// AttributeInteger class AttributeInteger implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// Minimum value to enforce for new documents. - final int? min; - /// Maximum value to enforce for new documents. - final int? max; - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final int? xdefault; + /// Attribute Key. + final String key; - AttributeInteger({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - this.min, - this.max, - this.xdefault, - }); + /// Attribute type. + final String type; - factory AttributeInteger.fromMap(Map map) { - return AttributeInteger( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - min: (map['min'] is String) ? - int.tryParse(map['min']):map['min'], - max: (map['max'] is String) ? - int.tryParse(map['max']):map['max'], - xdefault: (map['default'] is String) ? - int.tryParse(map['default']):map['default'], - ); - } + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "min": min, - "max": max, - "default": xdefault, - }; - } + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// Minimum value to enforce for new documents. + final int? min; + + /// Maximum value to enforce for new documents. + final int? max; + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final int? xdefault; + + AttributeInteger({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + this.min, + this.max, + this.xdefault, + }); + + factory AttributeInteger.fromMap(Map map) { + return AttributeInteger( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + min: (map['min'] is String) ? int.tryParse(map['min']) : map['min'], + max: (map['max'] is String) ? int.tryParse(map['max']) : map['max'], + xdefault: (map['default'] is String) + ? int.tryParse(map['default']) + : map['default'], + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "min": min, + "max": max, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_ip.dart b/lib/src/models/attribute_ip.dart index 960f7064..a63dd566 100644 --- a/lib/src/models/attribute_ip.dart +++ b/lib/src/models/attribute_ip.dart @@ -2,57 +2,64 @@ part of '../../models.dart'; /// AttributeIP class AttributeIp implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// String format. - final String format; - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeIp({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.format, - this.xdefault, - }); - - factory AttributeIp.fromMap(Map map) { - return AttributeIp( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "format": format, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + + /// Attribute type. + final String type; + + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// String format. + final String format; + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeIp({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.format, + this.xdefault, + }); + + factory AttributeIp.fromMap(Map map) { + return AttributeIp( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_list.dart b/lib/src/models/attribute_list.dart index e15a0b35..bf51398c 100644 --- a/lib/src/models/attribute_list.dart +++ b/lib/src/models/attribute_list.dart @@ -2,28 +2,30 @@ part of '../../models.dart'; /// Attributes List class AttributeList implements Model { - /// Total number of attributes in the given collection. - final int total; - /// List of attributes. - final List attributes; + /// Total number of attributes in the given collection. + final int total; - AttributeList({ - required this.total, - required this.attributes, - }); + /// List of attributes. + final List attributes; - factory AttributeList.fromMap(Map map) { - return AttributeList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - attributes: map['attributes'] ?? [], - ); - } + AttributeList({ + required this.total, + required this.attributes, + }); - Map toMap() { - return { - "total": total, - "attributes": attributes, - }; - } + factory AttributeList.fromMap(Map map) { + return AttributeList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + attributes: map['attributes'] ?? [], + ); + } + + Map toMap() { + return { + "total": total, + "attributes": attributes, + }; + } } diff --git a/lib/src/models/attribute_relationship.dart b/lib/src/models/attribute_relationship.dart index d22c30d4..0230d9f9 100644 --- a/lib/src/models/attribute_relationship.dart +++ b/lib/src/models/attribute_relationship.dart @@ -2,77 +2,88 @@ part of '../../models.dart'; /// AttributeRelationship class AttributeRelationship implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// The ID of the related collection. - final String relatedCollection; - /// The type of the relationship. - final String relationType; - /// Is the relationship two-way? - final bool twoWay; - /// The key of the two-way relationship. - final String twoWayKey; - /// How deleting the parent document will propagate to child documents. - final String onDelete; - /// Whether this is the parent or child side of the relationship - final String side; + /// Attribute Key. + final String key; - AttributeRelationship({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.relatedCollection, - required this.relationType, - required this.twoWay, - required this.twoWayKey, - required this.onDelete, - required this.side, - }); + /// Attribute type. + final String type; - factory AttributeRelationship.fromMap(Map map) { - return AttributeRelationship( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - relatedCollection: map['relatedCollection'].toString(), - relationType: map['relationType'].toString(), - twoWay: map['twoWay'], - twoWayKey: map['twoWayKey'].toString(), - onDelete: map['onDelete'].toString(), - side: map['side'].toString(), - ); - } + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "relatedCollection": relatedCollection, - "relationType": relationType, - "twoWay": twoWay, - "twoWayKey": twoWayKey, - "onDelete": onDelete, - "side": side, - }; - } + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// The ID of the related collection. + final String relatedCollection; + + /// The type of the relationship. + final String relationType; + + /// Is the relationship two-way? + final bool twoWay; + + /// The key of the two-way relationship. + final String twoWayKey; + + /// How deleting the parent document will propagate to child documents. + final String onDelete; + + /// Whether this is the parent or child side of the relationship + final String side; + + AttributeRelationship({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.relatedCollection, + required this.relationType, + required this.twoWay, + required this.twoWayKey, + required this.onDelete, + required this.side, + }); + + factory AttributeRelationship.fromMap(Map map) { + return AttributeRelationship( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + relatedCollection: map['relatedCollection'].toString(), + relationType: map['relationType'].toString(), + twoWay: map['twoWay'], + twoWayKey: map['twoWayKey'].toString(), + onDelete: map['onDelete'].toString(), + side: map['side'].toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "relatedCollection": relatedCollection, + "relationType": relationType, + "twoWay": twoWay, + "twoWayKey": twoWayKey, + "onDelete": onDelete, + "side": side, + }; + } } diff --git a/lib/src/models/attribute_string.dart b/lib/src/models/attribute_string.dart index c483317c..39c82811 100644 --- a/lib/src/models/attribute_string.dart +++ b/lib/src/models/attribute_string.dart @@ -2,58 +2,66 @@ part of '../../models.dart'; /// AttributeString class AttributeString implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// Attribute size. - final int size; - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeString({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.size, - this.xdefault, - }); - - factory AttributeString.fromMap(Map map) { - return AttributeString( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - size: (map['size'] is String) ? - int.tryParse(map['size']) ?? 0:map['size'] ?? 0, - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "size": size, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + + /// Attribute type. + final String type; + + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// Attribute size. + final int size; + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeString({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.size, + this.xdefault, + }); + + factory AttributeString.fromMap(Map map) { + return AttributeString( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + size: (map['size'] is String) + ? int.tryParse(map['size']) ?? 0 + : map['size'] ?? 0, + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "size": size, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_url.dart b/lib/src/models/attribute_url.dart index 691cfcf6..0a0d183f 100644 --- a/lib/src/models/attribute_url.dart +++ b/lib/src/models/attribute_url.dart @@ -2,57 +2,64 @@ part of '../../models.dart'; /// AttributeURL class AttributeUrl implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// String format. - final String format; - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeUrl({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.format, - this.xdefault, - }); - - factory AttributeUrl.fromMap(Map map) { - return AttributeUrl( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "format": format, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + + /// Attribute type. + final String type; + + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// String format. + final String format; + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeUrl({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.format, + this.xdefault, + }); + + factory AttributeUrl.fromMap(Map map) { + return AttributeUrl( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/bucket.dart b/lib/src/models/bucket.dart index b72c0392..4db92627 100644 --- a/lib/src/models/bucket.dart +++ b/lib/src/models/bucket.dart @@ -2,78 +2,90 @@ part of '../../models.dart'; /// Bucket class Bucket implements Model { - /// Bucket ID. - final String $id; - /// Bucket creation time in ISO 8601 format. - final String $createdAt; - /// Bucket update date in ISO 8601 format. - final String $updatedAt; - /// Bucket permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List $permissions; - /// Whether file-level security is enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). - final bool fileSecurity; - /// Bucket name. - final String name; - /// Bucket enabled. - final bool enabled; - /// Maximum file size supported. - final int maximumFileSize; - /// Allowed file extensions. - final List allowedFileExtensions; - /// Compression algorithm choosen for compression. Will be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd). - final String compression; - /// Bucket is encrypted. - final bool encryption; - /// Virus scanning is enabled. - final bool antivirus; + /// Bucket ID. + final String $id; - Bucket({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.fileSecurity, - required this.name, - required this.enabled, - required this.maximumFileSize, - required this.allowedFileExtensions, - required this.compression, - required this.encryption, - required this.antivirus, - }); + /// Bucket creation time in ISO 8601 format. + final String $createdAt; - factory Bucket.fromMap(Map map) { - return Bucket( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - fileSecurity: map['fileSecurity'], - name: map['name'].toString(), - enabled: map['enabled'], - maximumFileSize: (map['maximumFileSize'] is String) ? - int.tryParse(map['maximumFileSize']) ?? 0:map['maximumFileSize'] ?? 0, - allowedFileExtensions: map['allowedFileExtensions'] ?? [], - compression: map['compression'].toString(), - encryption: map['encryption'], - antivirus: map['antivirus'], - ); - } + /// Bucket update date in ISO 8601 format. + final String $updatedAt; - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "fileSecurity": fileSecurity, - "name": name, - "enabled": enabled, - "maximumFileSize": maximumFileSize, - "allowedFileExtensions": allowedFileExtensions, - "compression": compression, - "encryption": encryption, - "antivirus": antivirus, - }; - } + /// Bucket permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List $permissions; + + /// Whether file-level security is enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). + final bool fileSecurity; + + /// Bucket name. + final String name; + + /// Bucket enabled. + final bool enabled; + + /// Maximum file size supported. + final int maximumFileSize; + + /// Allowed file extensions. + final List allowedFileExtensions; + + /// Compression algorithm choosen for compression. Will be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd). + final String compression; + + /// Bucket is encrypted. + final bool encryption; + + /// Virus scanning is enabled. + final bool antivirus; + + Bucket({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.fileSecurity, + required this.name, + required this.enabled, + required this.maximumFileSize, + required this.allowedFileExtensions, + required this.compression, + required this.encryption, + required this.antivirus, + }); + + factory Bucket.fromMap(Map map) { + return Bucket( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + fileSecurity: map['fileSecurity'], + name: map['name'].toString(), + enabled: map['enabled'], + maximumFileSize: (map['maximumFileSize'] is String) + ? int.tryParse(map['maximumFileSize']) ?? 0 + : map['maximumFileSize'] ?? 0, + allowedFileExtensions: map['allowedFileExtensions'] ?? [], + compression: map['compression'].toString(), + encryption: map['encryption'], + antivirus: map['antivirus'], + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "fileSecurity": fileSecurity, + "name": name, + "enabled": enabled, + "maximumFileSize": maximumFileSize, + "allowedFileExtensions": allowedFileExtensions, + "compression": compression, + "encryption": encryption, + "antivirus": antivirus, + }; + } } diff --git a/lib/src/models/bucket_list.dart b/lib/src/models/bucket_list.dart index 7687eb6e..70b61a9e 100644 --- a/lib/src/models/bucket_list.dart +++ b/lib/src/models/bucket_list.dart @@ -2,28 +2,30 @@ part of '../../models.dart'; /// Buckets List class BucketList implements Model { - /// Total number of buckets documents that matched your query. - final int total; - /// List of buckets. - final List buckets; + /// Total number of buckets documents that matched your query. + final int total; - BucketList({ - required this.total, - required this.buckets, - }); + /// List of buckets. + final List buckets; - factory BucketList.fromMap(Map map) { - return BucketList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - buckets: List.from(map['buckets'].map((p) => Bucket.fromMap(p))), - ); - } + BucketList({ + required this.total, + required this.buckets, + }); - Map toMap() { - return { - "total": total, - "buckets": buckets.map((p) => p.toMap()).toList(), - }; - } + factory BucketList.fromMap(Map map) { + return BucketList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + buckets: List.from(map['buckets'].map((p) => Bucket.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "buckets": buckets.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/build.dart b/lib/src/models/build.dart index 4c12e283..65bde1ba 100644 --- a/lib/src/models/build.dart +++ b/lib/src/models/build.dart @@ -2,64 +2,74 @@ part of '../../models.dart'; /// Build class Build implements Model { - /// Build ID. - final String $id; - /// The deployment that created this build. - final String deploymentId; - /// The build status. There are a few different types and each one means something different. \nFailed - The deployment build has failed. More details can usually be found in buildStderr\nReady - The deployment build was successful and the deployment is ready to be deployed\nProcessing - The deployment is currently waiting to have a build triggered\nBuilding - The deployment is currently being built - final String status; - /// The stdout of the build. - final String stdout; - /// The stderr of the build. - final String stderr; - /// The deployment creation date in ISO 8601 format. - final String startTime; - /// The time the build was finished in ISO 8601 format. - final String endTime; - /// The build duration in seconds. - final int duration; - /// The code size in bytes. - final int size; + /// Build ID. + final String $id; - Build({ - required this.$id, - required this.deploymentId, - required this.status, - required this.stdout, - required this.stderr, - required this.startTime, - required this.endTime, - required this.duration, - required this.size, - }); + /// The deployment that created this build. + final String deploymentId; - factory Build.fromMap(Map map) { - return Build( - $id: map['\$id'].toString(), - deploymentId: map['deploymentId'].toString(), - status: map['status'].toString(), - stdout: map['stdout'].toString(), - stderr: map['stderr'].toString(), - startTime: map['startTime'].toString(), - endTime: map['endTime'].toString(), - duration: (map['duration'] is String) ? - int.tryParse(map['duration']) ?? 0:map['duration'] ?? 0, - size: (map['size'] is String) ? - int.tryParse(map['size']) ?? 0:map['size'] ?? 0, - ); - } + /// The build status. There are a few different types and each one means something different. \nFailed - The deployment build has failed. More details can usually be found in buildStderr\nReady - The deployment build was successful and the deployment is ready to be deployed\nProcessing - The deployment is currently waiting to have a build triggered\nBuilding - The deployment is currently being built + final String status; - Map toMap() { - return { - "\$id": $id, - "deploymentId": deploymentId, - "status": status, - "stdout": stdout, - "stderr": stderr, - "startTime": startTime, - "endTime": endTime, - "duration": duration, - "size": size, - }; - } + /// The stdout of the build. + final String stdout; + + /// The stderr of the build. + final String stderr; + + /// The deployment creation date in ISO 8601 format. + final String startTime; + + /// The time the build was finished in ISO 8601 format. + final String endTime; + + /// The build duration in seconds. + final int duration; + + /// The code size in bytes. + final int size; + + Build({ + required this.$id, + required this.deploymentId, + required this.status, + required this.stdout, + required this.stderr, + required this.startTime, + required this.endTime, + required this.duration, + required this.size, + }); + + factory Build.fromMap(Map map) { + return Build( + $id: map['\$id'].toString(), + deploymentId: map['deploymentId'].toString(), + status: map['status'].toString(), + stdout: map['stdout'].toString(), + stderr: map['stderr'].toString(), + startTime: map['startTime'].toString(), + endTime: map['endTime'].toString(), + duration: (map['duration'] is String) + ? int.tryParse(map['duration']) ?? 0 + : map['duration'] ?? 0, + size: (map['size'] is String) + ? int.tryParse(map['size']) ?? 0 + : map['size'] ?? 0, + ); + } + + Map toMap() { + return { + "\$id": $id, + "deploymentId": deploymentId, + "status": status, + "stdout": stdout, + "stderr": stderr, + "startTime": startTime, + "endTime": endTime, + "duration": duration, + "size": size, + }; + } } diff --git a/lib/src/models/collection.dart b/lib/src/models/collection.dart index d4649f55..2595cd2f 100644 --- a/lib/src/models/collection.dart +++ b/lib/src/models/collection.dart @@ -2,67 +2,76 @@ part of '../../models.dart'; /// Collection class Collection implements Model { - /// Collection ID. - final String $id; - /// Collection creation date in ISO 8601 format. - final String $createdAt; - /// Collection update date in ISO 8601 format. - final String $updatedAt; - /// Collection permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List $permissions; - /// Database ID. - final String databaseId; - /// Collection name. - final String name; - /// Collection enabled. Can be 'enabled' or 'disabled'. When disabled, the collection is inaccessible to users, but remains accessible to Server SDKs using API keys. - final bool enabled; - /// Whether document-level permissions are enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). - final bool documentSecurity; - /// Collection attributes. - final List attributes; - /// Collection indexes. - final List indexes; + /// Collection ID. + final String $id; - Collection({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.databaseId, - required this.name, - required this.enabled, - required this.documentSecurity, - required this.attributes, - required this.indexes, - }); + /// Collection creation date in ISO 8601 format. + final String $createdAt; - factory Collection.fromMap(Map map) { - return Collection( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - databaseId: map['databaseId'].toString(), - name: map['name'].toString(), - enabled: map['enabled'], - documentSecurity: map['documentSecurity'], - attributes: map['attributes'] ?? [], - indexes: List.from(map['indexes'].map((p) => Index.fromMap(p))), - ); - } + /// Collection update date in ISO 8601 format. + final String $updatedAt; - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "databaseId": databaseId, - "name": name, - "enabled": enabled, - "documentSecurity": documentSecurity, - "attributes": attributes, - "indexes": indexes.map((p) => p.toMap()).toList(), - }; - } + /// Collection permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List $permissions; + + /// Database ID. + final String databaseId; + + /// Collection name. + final String name; + + /// Collection enabled. Can be 'enabled' or 'disabled'. When disabled, the collection is inaccessible to users, but remains accessible to Server SDKs using API keys. + final bool enabled; + + /// Whether document-level permissions are enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). + final bool documentSecurity; + + /// Collection attributes. + final List attributes; + + /// Collection indexes. + final List indexes; + + Collection({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.databaseId, + required this.name, + required this.enabled, + required this.documentSecurity, + required this.attributes, + required this.indexes, + }); + + factory Collection.fromMap(Map map) { + return Collection( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + databaseId: map['databaseId'].toString(), + name: map['name'].toString(), + enabled: map['enabled'], + documentSecurity: map['documentSecurity'], + attributes: map['attributes'] ?? [], + indexes: List.from(map['indexes'].map((p) => Index.fromMap(p))), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "databaseId": databaseId, + "name": name, + "enabled": enabled, + "documentSecurity": documentSecurity, + "attributes": attributes, + "indexes": indexes.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/collection_list.dart b/lib/src/models/collection_list.dart index 732bbf89..8e9bddb5 100644 --- a/lib/src/models/collection_list.dart +++ b/lib/src/models/collection_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Collections List class CollectionList implements Model { - /// Total number of collections documents that matched your query. - final int total; - /// List of collections. - final List collections; + /// Total number of collections documents that matched your query. + final int total; - CollectionList({ - required this.total, - required this.collections, - }); + /// List of collections. + final List collections; - factory CollectionList.fromMap(Map map) { - return CollectionList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - collections: List.from(map['collections'].map((p) => Collection.fromMap(p))), - ); - } + CollectionList({ + required this.total, + required this.collections, + }); - Map toMap() { - return { - "total": total, - "collections": collections.map((p) => p.toMap()).toList(), - }; - } + factory CollectionList.fromMap(Map map) { + return CollectionList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + collections: List.from( + map['collections'].map((p) => Collection.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "collections": collections.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/continent.dart b/lib/src/models/continent.dart index e1772f0d..990b1064 100644 --- a/lib/src/models/continent.dart +++ b/lib/src/models/continent.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Continent class Continent implements Model { - /// Continent name. - final String name; - /// Continent two letter code. - final String code; + /// Continent name. + final String name; - Continent({ - required this.name, - required this.code, - }); + /// Continent two letter code. + final String code; - factory Continent.fromMap(Map map) { - return Continent( - name: map['name'].toString(), - code: map['code'].toString(), - ); - } + Continent({ + required this.name, + required this.code, + }); - Map toMap() { - return { - "name": name, - "code": code, - }; - } + factory Continent.fromMap(Map map) { + return Continent( + name: map['name'].toString(), + code: map['code'].toString(), + ); + } + + Map toMap() { + return { + "name": name, + "code": code, + }; + } } diff --git a/lib/src/models/continent_list.dart b/lib/src/models/continent_list.dart index d6c60999..6064a8a2 100644 --- a/lib/src/models/continent_list.dart +++ b/lib/src/models/continent_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Continents List class ContinentList implements Model { - /// Total number of continents documents that matched your query. - final int total; - /// List of continents. - final List continents; + /// Total number of continents documents that matched your query. + final int total; - ContinentList({ - required this.total, - required this.continents, - }); + /// List of continents. + final List continents; - factory ContinentList.fromMap(Map map) { - return ContinentList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - continents: List.from(map['continents'].map((p) => Continent.fromMap(p))), - ); - } + ContinentList({ + required this.total, + required this.continents, + }); - Map toMap() { - return { - "total": total, - "continents": continents.map((p) => p.toMap()).toList(), - }; - } + factory ContinentList.fromMap(Map map) { + return ContinentList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + continents: List.from( + map['continents'].map((p) => Continent.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "continents": continents.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/country.dart b/lib/src/models/country.dart index b8757434..d11c55db 100644 --- a/lib/src/models/country.dart +++ b/lib/src/models/country.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Country class Country implements Model { - /// Country name. - final String name; - /// Country two-character ISO 3166-1 alpha code. - final String code; + /// Country name. + final String name; - Country({ - required this.name, - required this.code, - }); + /// Country two-character ISO 3166-1 alpha code. + final String code; - factory Country.fromMap(Map map) { - return Country( - name: map['name'].toString(), - code: map['code'].toString(), - ); - } + Country({ + required this.name, + required this.code, + }); - Map toMap() { - return { - "name": name, - "code": code, - }; - } + factory Country.fromMap(Map map) { + return Country( + name: map['name'].toString(), + code: map['code'].toString(), + ); + } + + Map toMap() { + return { + "name": name, + "code": code, + }; + } } diff --git a/lib/src/models/country_list.dart b/lib/src/models/country_list.dart index 996b6aff..3ff4a391 100644 --- a/lib/src/models/country_list.dart +++ b/lib/src/models/country_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Countries List class CountryList implements Model { - /// Total number of countries documents that matched your query. - final int total; - /// List of countries. - final List countries; + /// Total number of countries documents that matched your query. + final int total; - CountryList({ - required this.total, - required this.countries, - }); + /// List of countries. + final List countries; - factory CountryList.fromMap(Map map) { - return CountryList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - countries: List.from(map['countries'].map((p) => Country.fromMap(p))), - ); - } + CountryList({ + required this.total, + required this.countries, + }); - Map toMap() { - return { - "total": total, - "countries": countries.map((p) => p.toMap()).toList(), - }; - } + factory CountryList.fromMap(Map map) { + return CountryList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + countries: + List.from(map['countries'].map((p) => Country.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "countries": countries.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/currency.dart b/lib/src/models/currency.dart index 1d0a3ed5..7ab4bb5c 100644 --- a/lib/src/models/currency.dart +++ b/lib/src/models/currency.dart @@ -2,53 +2,60 @@ part of '../../models.dart'; /// Currency class Currency implements Model { - /// Currency symbol. - final String symbol; - /// Currency name. - final String name; - /// Currency native symbol. - final String symbolNative; - /// Number of decimal digits. - final int decimalDigits; - /// Currency digit rounding. - final double rounding; - /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format. - final String code; - /// Currency plural name - final String namePlural; - - Currency({ - required this.symbol, - required this.name, - required this.symbolNative, - required this.decimalDigits, - required this.rounding, - required this.code, - required this.namePlural, - }); - - factory Currency.fromMap(Map map) { - return Currency( - symbol: map['symbol'].toString(), - name: map['name'].toString(), - symbolNative: map['symbolNative'].toString(), - decimalDigits: (map['decimalDigits'] is String) ? - int.tryParse(map['decimalDigits']) ?? 0:map['decimalDigits'] ?? 0, - rounding: map['rounding'].toDouble(), - code: map['code'].toString(), - namePlural: map['namePlural'].toString(), - ); - } - - Map toMap() { - return { - "symbol": symbol, - "name": name, - "symbolNative": symbolNative, - "decimalDigits": decimalDigits, - "rounding": rounding, - "code": code, - "namePlural": namePlural, - }; - } + /// Currency symbol. + final String symbol; + + /// Currency name. + final String name; + + /// Currency native symbol. + final String symbolNative; + + /// Number of decimal digits. + final int decimalDigits; + + /// Currency digit rounding. + final double rounding; + + /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format. + final String code; + + /// Currency plural name + final String namePlural; + + Currency({ + required this.symbol, + required this.name, + required this.symbolNative, + required this.decimalDigits, + required this.rounding, + required this.code, + required this.namePlural, + }); + + factory Currency.fromMap(Map map) { + return Currency( + symbol: map['symbol'].toString(), + name: map['name'].toString(), + symbolNative: map['symbolNative'].toString(), + decimalDigits: (map['decimalDigits'] is String) + ? int.tryParse(map['decimalDigits']) ?? 0 + : map['decimalDigits'] ?? 0, + rounding: map['rounding'].toDouble(), + code: map['code'].toString(), + namePlural: map['namePlural'].toString(), + ); + } + + Map toMap() { + return { + "symbol": symbol, + "name": name, + "symbolNative": symbolNative, + "decimalDigits": decimalDigits, + "rounding": rounding, + "code": code, + "namePlural": namePlural, + }; + } } diff --git a/lib/src/models/currency_list.dart b/lib/src/models/currency_list.dart index c1cd94e1..d5f50881 100644 --- a/lib/src/models/currency_list.dart +++ b/lib/src/models/currency_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Currencies List class CurrencyList implements Model { - /// Total number of currencies documents that matched your query. - final int total; - /// List of currencies. - final List currencies; + /// Total number of currencies documents that matched your query. + final int total; - CurrencyList({ - required this.total, - required this.currencies, - }); + /// List of currencies. + final List currencies; - factory CurrencyList.fromMap(Map map) { - return CurrencyList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - currencies: List.from(map['currencies'].map((p) => Currency.fromMap(p))), - ); - } + CurrencyList({ + required this.total, + required this.currencies, + }); - Map toMap() { - return { - "total": total, - "currencies": currencies.map((p) => p.toMap()).toList(), - }; - } + factory CurrencyList.fromMap(Map map) { + return CurrencyList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + currencies: List.from( + map['currencies'].map((p) => Currency.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "currencies": currencies.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/database.dart b/lib/src/models/database.dart index 8eb9253b..298a46a3 100644 --- a/lib/src/models/database.dart +++ b/lib/src/models/database.dart @@ -2,42 +2,46 @@ part of '../../models.dart'; /// Database class Database implements Model { - /// Database ID. - final String $id; - /// Database name. - final String name; - /// Database creation date in ISO 8601 format. - final String $createdAt; - /// Database update date in ISO 8601 format. - final String $updatedAt; - /// If database is enabled. Can be 'enabled' or 'disabled'. When disabled, the database is inaccessible to users, but remains accessible to Server SDKs using API keys. - final bool enabled; - - Database({ - required this.$id, - required this.name, - required this.$createdAt, - required this.$updatedAt, - required this.enabled, - }); - - factory Database.fromMap(Map map) { - return Database( - $id: map['\$id'].toString(), - name: map['name'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - enabled: map['enabled'], - ); - } - - Map toMap() { - return { - "\$id": $id, - "name": name, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "enabled": enabled, - }; - } + /// Database ID. + final String $id; + + /// Database name. + final String name; + + /// Database creation date in ISO 8601 format. + final String $createdAt; + + /// Database update date in ISO 8601 format. + final String $updatedAt; + + /// If database is enabled. Can be 'enabled' or 'disabled'. When disabled, the database is inaccessible to users, but remains accessible to Server SDKs using API keys. + final bool enabled; + + Database({ + required this.$id, + required this.name, + required this.$createdAt, + required this.$updatedAt, + required this.enabled, + }); + + factory Database.fromMap(Map map) { + return Database( + $id: map['\$id'].toString(), + name: map['name'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + enabled: map['enabled'], + ); + } + + Map toMap() { + return { + "\$id": $id, + "name": name, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "enabled": enabled, + }; + } } diff --git a/lib/src/models/database_list.dart b/lib/src/models/database_list.dart index 861b3c4f..0df34d5f 100644 --- a/lib/src/models/database_list.dart +++ b/lib/src/models/database_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Databases List class DatabaseList implements Model { - /// Total number of databases documents that matched your query. - final int total; - /// List of databases. - final List databases; + /// Total number of databases documents that matched your query. + final int total; - DatabaseList({ - required this.total, - required this.databases, - }); + /// List of databases. + final List databases; - factory DatabaseList.fromMap(Map map) { - return DatabaseList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - databases: List.from(map['databases'].map((p) => Database.fromMap(p))), - ); - } + DatabaseList({ + required this.total, + required this.databases, + }); - Map toMap() { - return { - "total": total, - "databases": databases.map((p) => p.toMap()).toList(), - }; - } + factory DatabaseList.fromMap(Map map) { + return DatabaseList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + databases: + List.from(map['databases'].map((p) => Database.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "databases": databases.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/deployment.dart b/lib/src/models/deployment.dart index 1c066b55..1a1ce096 100644 --- a/lib/src/models/deployment.dart +++ b/lib/src/models/deployment.dart @@ -2,140 +2,166 @@ part of '../../models.dart'; /// Deployment class Deployment implements Model { - /// Deployment ID. - final String $id; - /// Deployment creation date in ISO 8601 format. - final String $createdAt; - /// Deployment update date in ISO 8601 format. - final String $updatedAt; - /// Type of deployment. - final String type; - /// Resource ID. - final String resourceId; - /// Resource type. - final String resourceType; - /// The entrypoint file to use to execute the deployment code. - final String entrypoint; - /// The code size in bytes. - final int size; - /// The build output size in bytes. - final int buildSize; - /// The current build ID. - final String buildId; - /// Whether the deployment should be automatically activated. - final bool activate; - /// The deployment status. Possible values are "processing", "building", "waiting", "ready", and "failed". - final String status; - /// The build logs. - final String buildLogs; - /// The current build time in seconds. - final int buildTime; - /// The name of the vcs provider repository - final String providerRepositoryName; - /// The name of the vcs provider repository owner - final String providerRepositoryOwner; - /// The url of the vcs provider repository - final String providerRepositoryUrl; - /// The branch of the vcs repository - final String providerBranch; - /// The commit hash of the vcs commit - final String providerCommitHash; - /// The url of vcs commit author - final String providerCommitAuthorUrl; - /// The name of vcs commit author - final String providerCommitAuthor; - /// The commit message - final String providerCommitMessage; - /// The url of the vcs commit - final String providerCommitUrl; - /// The branch of the vcs repository - final String providerBranchUrl; - - Deployment({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.type, - required this.resourceId, - required this.resourceType, - required this.entrypoint, - required this.size, - required this.buildSize, - required this.buildId, - required this.activate, - required this.status, - required this.buildLogs, - required this.buildTime, - required this.providerRepositoryName, - required this.providerRepositoryOwner, - required this.providerRepositoryUrl, - required this.providerBranch, - required this.providerCommitHash, - required this.providerCommitAuthorUrl, - required this.providerCommitAuthor, - required this.providerCommitMessage, - required this.providerCommitUrl, - required this.providerBranchUrl, - }); - - factory Deployment.fromMap(Map map) { - return Deployment( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - type: map['type'].toString(), - resourceId: map['resourceId'].toString(), - resourceType: map['resourceType'].toString(), - entrypoint: map['entrypoint'].toString(), - size: (map['size'] is String) ? - int.tryParse(map['size']) ?? 0:map['size'] ?? 0, - buildSize: (map['buildSize'] is String) ? - int.tryParse(map['buildSize']) ?? 0:map['buildSize'] ?? 0, - buildId: map['buildId'].toString(), - activate: map['activate'], - status: map['status'].toString(), - buildLogs: map['buildLogs'].toString(), - buildTime: (map['buildTime'] is String) ? - int.tryParse(map['buildTime']) ?? 0:map['buildTime'] ?? 0, - providerRepositoryName: map['providerRepositoryName'].toString(), - providerRepositoryOwner: map['providerRepositoryOwner'].toString(), - providerRepositoryUrl: map['providerRepositoryUrl'].toString(), - providerBranch: map['providerBranch'].toString(), - providerCommitHash: map['providerCommitHash'].toString(), - providerCommitAuthorUrl: map['providerCommitAuthorUrl'].toString(), - providerCommitAuthor: map['providerCommitAuthor'].toString(), - providerCommitMessage: map['providerCommitMessage'].toString(), - providerCommitUrl: map['providerCommitUrl'].toString(), - providerBranchUrl: map['providerBranchUrl'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "type": type, - "resourceId": resourceId, - "resourceType": resourceType, - "entrypoint": entrypoint, - "size": size, - "buildSize": buildSize, - "buildId": buildId, - "activate": activate, - "status": status, - "buildLogs": buildLogs, - "buildTime": buildTime, - "providerRepositoryName": providerRepositoryName, - "providerRepositoryOwner": providerRepositoryOwner, - "providerRepositoryUrl": providerRepositoryUrl, - "providerBranch": providerBranch, - "providerCommitHash": providerCommitHash, - "providerCommitAuthorUrl": providerCommitAuthorUrl, - "providerCommitAuthor": providerCommitAuthor, - "providerCommitMessage": providerCommitMessage, - "providerCommitUrl": providerCommitUrl, - "providerBranchUrl": providerBranchUrl, - }; - } + /// Deployment ID. + final String $id; + + /// Deployment creation date in ISO 8601 format. + final String $createdAt; + + /// Deployment update date in ISO 8601 format. + final String $updatedAt; + + /// Type of deployment. + final String type; + + /// Resource ID. + final String resourceId; + + /// Resource type. + final String resourceType; + + /// The entrypoint file to use to execute the deployment code. + final String entrypoint; + + /// The code size in bytes. + final int size; + + /// The build output size in bytes. + final int buildSize; + + /// The current build ID. + final String buildId; + + /// Whether the deployment should be automatically activated. + final bool activate; + + /// The deployment status. Possible values are "processing", "building", "waiting", "ready", and "failed". + final String status; + + /// The build logs. + final String buildLogs; + + /// The current build time in seconds. + final int buildTime; + + /// The name of the vcs provider repository + final String providerRepositoryName; + + /// The name of the vcs provider repository owner + final String providerRepositoryOwner; + + /// The url of the vcs provider repository + final String providerRepositoryUrl; + + /// The branch of the vcs repository + final String providerBranch; + + /// The commit hash of the vcs commit + final String providerCommitHash; + + /// The url of vcs commit author + final String providerCommitAuthorUrl; + + /// The name of vcs commit author + final String providerCommitAuthor; + + /// The commit message + final String providerCommitMessage; + + /// The url of the vcs commit + final String providerCommitUrl; + + /// The branch of the vcs repository + final String providerBranchUrl; + + Deployment({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.type, + required this.resourceId, + required this.resourceType, + required this.entrypoint, + required this.size, + required this.buildSize, + required this.buildId, + required this.activate, + required this.status, + required this.buildLogs, + required this.buildTime, + required this.providerRepositoryName, + required this.providerRepositoryOwner, + required this.providerRepositoryUrl, + required this.providerBranch, + required this.providerCommitHash, + required this.providerCommitAuthorUrl, + required this.providerCommitAuthor, + required this.providerCommitMessage, + required this.providerCommitUrl, + required this.providerBranchUrl, + }); + + factory Deployment.fromMap(Map map) { + return Deployment( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + type: map['type'].toString(), + resourceId: map['resourceId'].toString(), + resourceType: map['resourceType'].toString(), + entrypoint: map['entrypoint'].toString(), + size: (map['size'] is String) + ? int.tryParse(map['size']) ?? 0 + : map['size'] ?? 0, + buildSize: (map['buildSize'] is String) + ? int.tryParse(map['buildSize']) ?? 0 + : map['buildSize'] ?? 0, + buildId: map['buildId'].toString(), + activate: map['activate'], + status: map['status'].toString(), + buildLogs: map['buildLogs'].toString(), + buildTime: (map['buildTime'] is String) + ? int.tryParse(map['buildTime']) ?? 0 + : map['buildTime'] ?? 0, + providerRepositoryName: map['providerRepositoryName'].toString(), + providerRepositoryOwner: map['providerRepositoryOwner'].toString(), + providerRepositoryUrl: map['providerRepositoryUrl'].toString(), + providerBranch: map['providerBranch'].toString(), + providerCommitHash: map['providerCommitHash'].toString(), + providerCommitAuthorUrl: map['providerCommitAuthorUrl'].toString(), + providerCommitAuthor: map['providerCommitAuthor'].toString(), + providerCommitMessage: map['providerCommitMessage'].toString(), + providerCommitUrl: map['providerCommitUrl'].toString(), + providerBranchUrl: map['providerBranchUrl'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "type": type, + "resourceId": resourceId, + "resourceType": resourceType, + "entrypoint": entrypoint, + "size": size, + "buildSize": buildSize, + "buildId": buildId, + "activate": activate, + "status": status, + "buildLogs": buildLogs, + "buildTime": buildTime, + "providerRepositoryName": providerRepositoryName, + "providerRepositoryOwner": providerRepositoryOwner, + "providerRepositoryUrl": providerRepositoryUrl, + "providerBranch": providerBranch, + "providerCommitHash": providerCommitHash, + "providerCommitAuthorUrl": providerCommitAuthorUrl, + "providerCommitAuthor": providerCommitAuthor, + "providerCommitMessage": providerCommitMessage, + "providerCommitUrl": providerCommitUrl, + "providerBranchUrl": providerBranchUrl, + }; + } } diff --git a/lib/src/models/deployment_list.dart b/lib/src/models/deployment_list.dart index ddc014f9..087d9766 100644 --- a/lib/src/models/deployment_list.dart +++ b/lib/src/models/deployment_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Deployments List class DeploymentList implements Model { - /// Total number of deployments documents that matched your query. - final int total; - /// List of deployments. - final List deployments; + /// Total number of deployments documents that matched your query. + final int total; - DeploymentList({ - required this.total, - required this.deployments, - }); + /// List of deployments. + final List deployments; - factory DeploymentList.fromMap(Map map) { - return DeploymentList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - deployments: List.from(map['deployments'].map((p) => Deployment.fromMap(p))), - ); - } + DeploymentList({ + required this.total, + required this.deployments, + }); - Map toMap() { - return { - "total": total, - "deployments": deployments.map((p) => p.toMap()).toList(), - }; - } + factory DeploymentList.fromMap(Map map) { + return DeploymentList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + deployments: List.from( + map['deployments'].map((p) => Deployment.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "deployments": deployments.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/document.dart b/lib/src/models/document.dart index d5b8c77e..6406f06a 100644 --- a/lib/src/models/document.dart +++ b/lib/src/models/document.dart @@ -2,53 +2,58 @@ part of '../../models.dart'; /// Document class Document implements Model { - /// Document ID. - final String $id; - /// Collection ID. - final String $collectionId; - /// Database ID. - final String $databaseId; - /// Document creation date in ISO 8601 format. - final String $createdAt; - /// Document update date in ISO 8601 format. - final String $updatedAt; - /// Document permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List $permissions; - final Map data; - - Document({ - required this.$id, - required this.$collectionId, - required this.$databaseId, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.data, - }); - - factory Document.fromMap(Map map) { - return Document( - $id: map['\$id'].toString(), - $collectionId: map['\$collectionId'].toString(), - $databaseId: map['\$databaseId'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - data: map, - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$collectionId": $collectionId, - "\$databaseId": $databaseId, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "data": data, - }; - } - - T convertTo(T Function(Map) fromJson) => fromJson(data); + /// Document ID. + final String $id; + + /// Collection ID. + final String $collectionId; + + /// Database ID. + final String $databaseId; + + /// Document creation date in ISO 8601 format. + final String $createdAt; + + /// Document update date in ISO 8601 format. + final String $updatedAt; + + /// Document permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List $permissions; + final Map data; + + Document({ + required this.$id, + required this.$collectionId, + required this.$databaseId, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.data, + }); + + factory Document.fromMap(Map map) { + return Document( + $id: map['\$id'].toString(), + $collectionId: map['\$collectionId'].toString(), + $databaseId: map['\$databaseId'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + data: map, + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$collectionId": $collectionId, + "\$databaseId": $databaseId, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "data": data, + }; + } + + T convertTo(T Function(Map) fromJson) => fromJson(data); } diff --git a/lib/src/models/document_list.dart b/lib/src/models/document_list.dart index c418b48e..1e25b09e 100644 --- a/lib/src/models/document_list.dart +++ b/lib/src/models/document_list.dart @@ -2,31 +2,34 @@ part of '../../models.dart'; /// Documents List class DocumentList implements Model { - /// Total number of documents documents that matched your query. - final int total; - /// List of documents. - final List documents; + /// Total number of documents documents that matched your query. + final int total; - DocumentList({ - required this.total, - required this.documents, - }); + /// List of documents. + final List documents; - factory DocumentList.fromMap(Map map) { - return DocumentList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - documents: List.from(map['documents'].map((p) => Document.fromMap(p))), - ); - } + DocumentList({ + required this.total, + required this.documents, + }); - Map toMap() { - return { - "total": total, - "documents": documents.map((p) => p.toMap()).toList(), - }; - } + factory DocumentList.fromMap(Map map) { + return DocumentList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + documents: + List.from(map['documents'].map((p) => Document.fromMap(p))), + ); + } - List convertTo(T Function(Map) fromJson) => - documents.map((d) => d.convertTo(fromJson)).toList(); + Map toMap() { + return { + "total": total, + "documents": documents.map((p) => p.toMap()).toList(), + }; + } + + List convertTo(T Function(Map) fromJson) => + documents.map((d) => d.convertTo(fromJson)).toList(); } diff --git a/lib/src/models/execution.dart b/lib/src/models/execution.dart index aff3e0b3..ad277e42 100644 --- a/lib/src/models/execution.dart +++ b/lib/src/models/execution.dart @@ -2,103 +2,122 @@ part of '../../models.dart'; /// Execution class Execution implements Model { - /// Execution ID. - final String $id; - /// Execution creation date in ISO 8601 format. - final String $createdAt; - /// Execution upate date in ISO 8601 format. - final String $updatedAt; - /// Execution roles. - final List $permissions; - /// Function ID. - final String functionId; - /// The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`. - final String trigger; - /// The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`. - final String status; - /// HTTP request method type. - final String requestMethod; - /// HTTP request path and query. - final String requestPath; - /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. - final List requestHeaders; - /// HTTP response status code. - final int responseStatusCode; - /// HTTP response body. This will return empty unless execution is created as synchronous. - final String responseBody; - /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. - final List responseHeaders; - /// Function logs. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. - final String logs; - /// Function errors. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. - final String errors; - /// Function execution duration in seconds. - final double duration; - /// The scheduled time for execution. If left empty, execution will be queued immediately. - final String? scheduledAt; - - Execution({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.functionId, - required this.trigger, - required this.status, - required this.requestMethod, - required this.requestPath, - required this.requestHeaders, - required this.responseStatusCode, - required this.responseBody, - required this.responseHeaders, - required this.logs, - required this.errors, - required this.duration, - this.scheduledAt, - }); - - factory Execution.fromMap(Map map) { - return Execution( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - functionId: map['functionId'].toString(), - trigger: map['trigger'].toString(), - status: map['status'].toString(), - requestMethod: map['requestMethod'].toString(), - requestPath: map['requestPath'].toString(), - requestHeaders: List.from(map['requestHeaders'].map((p) => Headers.fromMap(p))), - responseStatusCode: (map['responseStatusCode'] is String) ? - int.tryParse(map['responseStatusCode']) ?? 0:map['responseStatusCode'] ?? 0, - responseBody: map['responseBody'].toString(), - responseHeaders: List.from(map['responseHeaders'].map((p) => Headers.fromMap(p))), - logs: map['logs'].toString(), - errors: map['errors'].toString(), - duration: map['duration'].toDouble(), - scheduledAt: map['scheduledAt']?.toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "functionId": functionId, - "trigger": trigger, - "status": status, - "requestMethod": requestMethod, - "requestPath": requestPath, - "requestHeaders": requestHeaders.map((p) => p.toMap()).toList(), - "responseStatusCode": responseStatusCode, - "responseBody": responseBody, - "responseHeaders": responseHeaders.map((p) => p.toMap()).toList(), - "logs": logs, - "errors": errors, - "duration": duration, - "scheduledAt": scheduledAt, - }; - } + /// Execution ID. + final String $id; + + /// Execution creation date in ISO 8601 format. + final String $createdAt; + + /// Execution upate date in ISO 8601 format. + final String $updatedAt; + + /// Execution roles. + final List $permissions; + + /// Function ID. + final String functionId; + + /// The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`. + final String trigger; + + /// The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`. + final String status; + + /// HTTP request method type. + final String requestMethod; + + /// HTTP request path and query. + final String requestPath; + + /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. + final List requestHeaders; + + /// HTTP response status code. + final int responseStatusCode; + + /// HTTP response body. This will return empty unless execution is created as synchronous. + final String responseBody; + + /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. + final List responseHeaders; + + /// Function logs. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. + final String logs; + + /// Function errors. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. + final String errors; + + /// Function execution duration in seconds. + final double duration; + + /// The scheduled time for execution. If left empty, execution will be queued immediately. + final String? scheduledAt; + + Execution({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.functionId, + required this.trigger, + required this.status, + required this.requestMethod, + required this.requestPath, + required this.requestHeaders, + required this.responseStatusCode, + required this.responseBody, + required this.responseHeaders, + required this.logs, + required this.errors, + required this.duration, + this.scheduledAt, + }); + + factory Execution.fromMap(Map map) { + return Execution( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + functionId: map['functionId'].toString(), + trigger: map['trigger'].toString(), + status: map['status'].toString(), + requestMethod: map['requestMethod'].toString(), + requestPath: map['requestPath'].toString(), + requestHeaders: List.from( + map['requestHeaders'].map((p) => Headers.fromMap(p))), + responseStatusCode: (map['responseStatusCode'] is String) + ? int.tryParse(map['responseStatusCode']) ?? 0 + : map['responseStatusCode'] ?? 0, + responseBody: map['responseBody'].toString(), + responseHeaders: List.from( + map['responseHeaders'].map((p) => Headers.fromMap(p))), + logs: map['logs'].toString(), + errors: map['errors'].toString(), + duration: map['duration'].toDouble(), + scheduledAt: map['scheduledAt']?.toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "functionId": functionId, + "trigger": trigger, + "status": status, + "requestMethod": requestMethod, + "requestPath": requestPath, + "requestHeaders": requestHeaders.map((p) => p.toMap()).toList(), + "responseStatusCode": responseStatusCode, + "responseBody": responseBody, + "responseHeaders": responseHeaders.map((p) => p.toMap()).toList(), + "logs": logs, + "errors": errors, + "duration": duration, + "scheduledAt": scheduledAt, + }; + } } diff --git a/lib/src/models/execution_list.dart b/lib/src/models/execution_list.dart index ba66f150..0a54b2a8 100644 --- a/lib/src/models/execution_list.dart +++ b/lib/src/models/execution_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Executions List class ExecutionList implements Model { - /// Total number of executions documents that matched your query. - final int total; - /// List of executions. - final List executions; + /// Total number of executions documents that matched your query. + final int total; - ExecutionList({ - required this.total, - required this.executions, - }); + /// List of executions. + final List executions; - factory ExecutionList.fromMap(Map map) { - return ExecutionList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - executions: List.from(map['executions'].map((p) => Execution.fromMap(p))), - ); - } + ExecutionList({ + required this.total, + required this.executions, + }); - Map toMap() { - return { - "total": total, - "executions": executions.map((p) => p.toMap()).toList(), - }; - } + factory ExecutionList.fromMap(Map map) { + return ExecutionList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + executions: List.from( + map['executions'].map((p) => Execution.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "executions": executions.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/file.dart b/lib/src/models/file.dart index 34b9e6cf..db31bf49 100644 --- a/lib/src/models/file.dart +++ b/lib/src/models/file.dart @@ -2,75 +2,88 @@ part of '../../models.dart'; /// File class File implements Model { - /// File ID. - final String $id; - /// Bucket ID. - final String bucketId; - /// File creation date in ISO 8601 format. - final String $createdAt; - /// File update date in ISO 8601 format. - final String $updatedAt; - /// File permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List $permissions; - /// File name. - final String name; - /// File MD5 signature. - final String signature; - /// File mime type. - final String mimeType; - /// File original size in bytes. - final int sizeOriginal; - /// Total number of chunks available - final int chunksTotal; - /// Total number of chunks uploaded - final int chunksUploaded; + /// File ID. + final String $id; - File({ - required this.$id, - required this.bucketId, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.name, - required this.signature, - required this.mimeType, - required this.sizeOriginal, - required this.chunksTotal, - required this.chunksUploaded, - }); + /// Bucket ID. + final String bucketId; - factory File.fromMap(Map map) { - return File( - $id: map['\$id'].toString(), - bucketId: map['bucketId'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - name: map['name'].toString(), - signature: map['signature'].toString(), - mimeType: map['mimeType'].toString(), - sizeOriginal: (map['sizeOriginal'] is String) ? - int.tryParse(map['sizeOriginal']) ?? 0:map['sizeOriginal'] ?? 0, - chunksTotal: (map['chunksTotal'] is String) ? - int.tryParse(map['chunksTotal']) ?? 0:map['chunksTotal'] ?? 0, - chunksUploaded: (map['chunksUploaded'] is String) ? - int.tryParse(map['chunksUploaded']) ?? 0:map['chunksUploaded'] ?? 0, - ); - } + /// File creation date in ISO 8601 format. + final String $createdAt; - Map toMap() { - return { - "\$id": $id, - "bucketId": bucketId, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "name": name, - "signature": signature, - "mimeType": mimeType, - "sizeOriginal": sizeOriginal, - "chunksTotal": chunksTotal, - "chunksUploaded": chunksUploaded, - }; - } + /// File update date in ISO 8601 format. + final String $updatedAt; + + /// File permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List $permissions; + + /// File name. + final String name; + + /// File MD5 signature. + final String signature; + + /// File mime type. + final String mimeType; + + /// File original size in bytes. + final int sizeOriginal; + + /// Total number of chunks available + final int chunksTotal; + + /// Total number of chunks uploaded + final int chunksUploaded; + + File({ + required this.$id, + required this.bucketId, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.name, + required this.signature, + required this.mimeType, + required this.sizeOriginal, + required this.chunksTotal, + required this.chunksUploaded, + }); + + factory File.fromMap(Map map) { + return File( + $id: map['\$id'].toString(), + bucketId: map['bucketId'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + name: map['name'].toString(), + signature: map['signature'].toString(), + mimeType: map['mimeType'].toString(), + sizeOriginal: (map['sizeOriginal'] is String) + ? int.tryParse(map['sizeOriginal']) ?? 0 + : map['sizeOriginal'] ?? 0, + chunksTotal: (map['chunksTotal'] is String) + ? int.tryParse(map['chunksTotal']) ?? 0 + : map['chunksTotal'] ?? 0, + chunksUploaded: (map['chunksUploaded'] is String) + ? int.tryParse(map['chunksUploaded']) ?? 0 + : map['chunksUploaded'] ?? 0, + ); + } + + Map toMap() { + return { + "\$id": $id, + "bucketId": bucketId, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "name": name, + "signature": signature, + "mimeType": mimeType, + "sizeOriginal": sizeOriginal, + "chunksTotal": chunksTotal, + "chunksUploaded": chunksUploaded, + }; + } } diff --git a/lib/src/models/file_list.dart b/lib/src/models/file_list.dart index cf7a0ced..3d4451f6 100644 --- a/lib/src/models/file_list.dart +++ b/lib/src/models/file_list.dart @@ -2,28 +2,30 @@ part of '../../models.dart'; /// Files List class FileList implements Model { - /// Total number of files documents that matched your query. - final int total; - /// List of files. - final List files; + /// Total number of files documents that matched your query. + final int total; - FileList({ - required this.total, - required this.files, - }); + /// List of files. + final List files; - factory FileList.fromMap(Map map) { - return FileList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - files: List.from(map['files'].map((p) => File.fromMap(p))), - ); - } + FileList({ + required this.total, + required this.files, + }); - Map toMap() { - return { - "total": total, - "files": files.map((p) => p.toMap()).toList(), - }; - } + factory FileList.fromMap(Map map) { + return FileList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + files: List.from(map['files'].map((p) => File.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "files": files.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/function.dart b/lib/src/models/function.dart index 870bd5df..f509b009 100644 --- a/lib/src/models/function.dart +++ b/lib/src/models/function.dart @@ -2,138 +2,162 @@ part of '../../models.dart'; /// Function class Func implements Model { - /// Function ID. - final String $id; - /// Function creation date in ISO 8601 format. - final String $createdAt; - /// Function update date in ISO 8601 format. - final String $updatedAt; - /// Execution permissions. - final List execute; - /// Function name. - final String name; - /// Function enabled. - final bool enabled; - /// Is the function deployed with the latest configuration? This is set to false if you've changed an environment variables, entrypoint, commands, or other settings that needs redeploy to be applied. When the value is false, redeploy the function to update it with the latest configuration. - final bool live; - /// Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project. - final bool logging; - /// Function execution runtime. - final String runtime; - /// Function's active deployment ID. - final String deployment; - /// Allowed permission scopes. - final List scopes; - /// Function variables. - final List vars; - /// Function trigger events. - final List events; - /// Function execution schedult in CRON format. - final String schedule; - /// Function execution timeout in seconds. - final int timeout; - /// The entrypoint file used to execute the deployment. - final String entrypoint; - /// The build command used to build the deployment. - final String commands; - /// Version of Open Runtimes used for the function. - final String version; - /// Function VCS (Version Control System) installation id. - final String installationId; - /// VCS (Version Control System) Repository ID - final String providerRepositoryId; - /// VCS (Version Control System) branch name - final String providerBranch; - /// Path to function in VCS (Version Control System) repository - final String providerRootDirectory; - /// Is VCS (Version Control System) connection is in silent mode? When in silence mode, no comments will be posted on the repository pull or merge requests - final bool providerSilentMode; - /// Machine specification for builds and executions. - final String specification; - - Func({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.execute, - required this.name, - required this.enabled, - required this.live, - required this.logging, - required this.runtime, - required this.deployment, - required this.scopes, - required this.vars, - required this.events, - required this.schedule, - required this.timeout, - required this.entrypoint, - required this.commands, - required this.version, - required this.installationId, - required this.providerRepositoryId, - required this.providerBranch, - required this.providerRootDirectory, - required this.providerSilentMode, - required this.specification, - }); - - factory Func.fromMap(Map map) { - return Func( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - execute: map['execute'] ?? [], - name: map['name'].toString(), - enabled: map['enabled'], - live: map['live'], - logging: map['logging'], - runtime: map['runtime'].toString(), - deployment: map['deployment'].toString(), - scopes: map['scopes'] ?? [], - vars: List.from(map['vars'].map((p) => Variable.fromMap(p))), - events: map['events'] ?? [], - schedule: map['schedule'].toString(), - timeout: (map['timeout'] is String) ? - int.tryParse(map['timeout']) ?? 0:map['timeout'] ?? 0, - entrypoint: map['entrypoint'].toString(), - commands: map['commands'].toString(), - version: map['version'].toString(), - installationId: map['installationId'].toString(), - providerRepositoryId: map['providerRepositoryId'].toString(), - providerBranch: map['providerBranch'].toString(), - providerRootDirectory: map['providerRootDirectory'].toString(), - providerSilentMode: map['providerSilentMode'], - specification: map['specification'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "execute": execute, - "name": name, - "enabled": enabled, - "live": live, - "logging": logging, - "runtime": runtime, - "deployment": deployment, - "scopes": scopes, - "vars": vars.map((p) => p.toMap()).toList(), - "events": events, - "schedule": schedule, - "timeout": timeout, - "entrypoint": entrypoint, - "commands": commands, - "version": version, - "installationId": installationId, - "providerRepositoryId": providerRepositoryId, - "providerBranch": providerBranch, - "providerRootDirectory": providerRootDirectory, - "providerSilentMode": providerSilentMode, - "specification": specification, - }; - } + /// Function ID. + final String $id; + + /// Function creation date in ISO 8601 format. + final String $createdAt; + + /// Function update date in ISO 8601 format. + final String $updatedAt; + + /// Execution permissions. + final List execute; + + /// Function name. + final String name; + + /// Function enabled. + final bool enabled; + + /// Is the function deployed with the latest configuration? This is set to false if you've changed an environment variables, entrypoint, commands, or other settings that needs redeploy to be applied. When the value is false, redeploy the function to update it with the latest configuration. + final bool live; + + /// Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project. + final bool logging; + + /// Function execution runtime. + final String runtime; + + /// Function's active deployment ID. + final String deployment; + + /// Allowed permission scopes. + final List scopes; + + /// Function variables. + final List vars; + + /// Function trigger events. + final List events; + + /// Function execution schedult in CRON format. + final String schedule; + + /// Function execution timeout in seconds. + final int timeout; + + /// The entrypoint file used to execute the deployment. + final String entrypoint; + + /// The build command used to build the deployment. + final String commands; + + /// Version of Open Runtimes used for the function. + final String version; + + /// Function VCS (Version Control System) installation id. + final String installationId; + + /// VCS (Version Control System) Repository ID + final String providerRepositoryId; + + /// VCS (Version Control System) branch name + final String providerBranch; + + /// Path to function in VCS (Version Control System) repository + final String providerRootDirectory; + + /// Is VCS (Version Control System) connection is in silent mode? When in silence mode, no comments will be posted on the repository pull or merge requests + final bool providerSilentMode; + + /// Machine specification for builds and executions. + final String specification; + + Func({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.execute, + required this.name, + required this.enabled, + required this.live, + required this.logging, + required this.runtime, + required this.deployment, + required this.scopes, + required this.vars, + required this.events, + required this.schedule, + required this.timeout, + required this.entrypoint, + required this.commands, + required this.version, + required this.installationId, + required this.providerRepositoryId, + required this.providerBranch, + required this.providerRootDirectory, + required this.providerSilentMode, + required this.specification, + }); + + factory Func.fromMap(Map map) { + return Func( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + execute: map['execute'] ?? [], + name: map['name'].toString(), + enabled: map['enabled'], + live: map['live'], + logging: map['logging'], + runtime: map['runtime'].toString(), + deployment: map['deployment'].toString(), + scopes: map['scopes'] ?? [], + vars: List.from(map['vars'].map((p) => Variable.fromMap(p))), + events: map['events'] ?? [], + schedule: map['schedule'].toString(), + timeout: (map['timeout'] is String) + ? int.tryParse(map['timeout']) ?? 0 + : map['timeout'] ?? 0, + entrypoint: map['entrypoint'].toString(), + commands: map['commands'].toString(), + version: map['version'].toString(), + installationId: map['installationId'].toString(), + providerRepositoryId: map['providerRepositoryId'].toString(), + providerBranch: map['providerBranch'].toString(), + providerRootDirectory: map['providerRootDirectory'].toString(), + providerSilentMode: map['providerSilentMode'], + specification: map['specification'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "execute": execute, + "name": name, + "enabled": enabled, + "live": live, + "logging": logging, + "runtime": runtime, + "deployment": deployment, + "scopes": scopes, + "vars": vars.map((p) => p.toMap()).toList(), + "events": events, + "schedule": schedule, + "timeout": timeout, + "entrypoint": entrypoint, + "commands": commands, + "version": version, + "installationId": installationId, + "providerRepositoryId": providerRepositoryId, + "providerBranch": providerBranch, + "providerRootDirectory": providerRootDirectory, + "providerSilentMode": providerSilentMode, + "specification": specification, + }; + } } diff --git a/lib/src/models/function_list.dart b/lib/src/models/function_list.dart index 712e459e..989e4264 100644 --- a/lib/src/models/function_list.dart +++ b/lib/src/models/function_list.dart @@ -2,28 +2,30 @@ part of '../../models.dart'; /// Functions List class FunctionList implements Model { - /// Total number of functions documents that matched your query. - final int total; - /// List of functions. - final List functions; + /// Total number of functions documents that matched your query. + final int total; - FunctionList({ - required this.total, - required this.functions, - }); + /// List of functions. + final List functions; - factory FunctionList.fromMap(Map map) { - return FunctionList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - functions: List.from(map['functions'].map((p) => Func.fromMap(p))), - ); - } + FunctionList({ + required this.total, + required this.functions, + }); - Map toMap() { - return { - "total": total, - "functions": functions.map((p) => p.toMap()).toList(), - }; - } + factory FunctionList.fromMap(Map map) { + return FunctionList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + functions: List.from(map['functions'].map((p) => Func.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "functions": functions.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/headers.dart b/lib/src/models/headers.dart index f03c5ce4..22494998 100644 --- a/lib/src/models/headers.dart +++ b/lib/src/models/headers.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Headers class Headers implements Model { - /// Header name. - final String name; - /// Header value. - final String value; + /// Header name. + final String name; - Headers({ - required this.name, - required this.value, - }); + /// Header value. + final String value; - factory Headers.fromMap(Map map) { - return Headers( - name: map['name'].toString(), - value: map['value'].toString(), - ); - } + Headers({ + required this.name, + required this.value, + }); - Map toMap() { - return { - "name": name, - "value": value, - }; - } + factory Headers.fromMap(Map map) { + return Headers( + name: map['name'].toString(), + value: map['value'].toString(), + ); + } + + Map toMap() { + return { + "name": name, + "value": value, + }; + } } diff --git a/lib/src/models/health_antivirus.dart b/lib/src/models/health_antivirus.dart index 48b8ad32..aabc7d85 100644 --- a/lib/src/models/health_antivirus.dart +++ b/lib/src/models/health_antivirus.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Health Antivirus class HealthAntivirus implements Model { - /// Antivirus version. - final String version; - /// Antivirus status. Possible values can are: `disabled`, `offline`, `online` - final String status; + /// Antivirus version. + final String version; - HealthAntivirus({ - required this.version, - required this.status, - }); + /// Antivirus status. Possible values can are: `disabled`, `offline`, `online` + final String status; - factory HealthAntivirus.fromMap(Map map) { - return HealthAntivirus( - version: map['version'].toString(), - status: map['status'].toString(), - ); - } + HealthAntivirus({ + required this.version, + required this.status, + }); - Map toMap() { - return { - "version": version, - "status": status, - }; - } + factory HealthAntivirus.fromMap(Map map) { + return HealthAntivirus( + version: map['version'].toString(), + status: map['status'].toString(), + ); + } + + Map toMap() { + return { + "version": version, + "status": status, + }; + } } diff --git a/lib/src/models/health_certificate.dart b/lib/src/models/health_certificate.dart index 3409d8e7..d412eba9 100644 --- a/lib/src/models/health_certificate.dart +++ b/lib/src/models/health_certificate.dart @@ -2,47 +2,52 @@ part of '../../models.dart'; /// Health Certificate class HealthCertificate implements Model { - /// Certificate name - final String name; - /// Subject SN - final String subjectSN; - /// Issuer organisation - final String issuerOrganisation; - /// Valid from - final String validFrom; - /// Valid to - final String validTo; - /// Signature type SN - final String signatureTypeSN; - - HealthCertificate({ - required this.name, - required this.subjectSN, - required this.issuerOrganisation, - required this.validFrom, - required this.validTo, - required this.signatureTypeSN, - }); - - factory HealthCertificate.fromMap(Map map) { - return HealthCertificate( - name: map['name'].toString(), - subjectSN: map['subjectSN'].toString(), - issuerOrganisation: map['issuerOrganisation'].toString(), - validFrom: map['validFrom'].toString(), - validTo: map['validTo'].toString(), - signatureTypeSN: map['signatureTypeSN'].toString(), - ); - } - - Map toMap() { - return { - "name": name, - "subjectSN": subjectSN, - "issuerOrganisation": issuerOrganisation, - "validFrom": validFrom, - "validTo": validTo, - "signatureTypeSN": signatureTypeSN, - }; - } + /// Certificate name + final String name; + + /// Subject SN + final String subjectSN; + + /// Issuer organisation + final String issuerOrganisation; + + /// Valid from + final String validFrom; + + /// Valid to + final String validTo; + + /// Signature type SN + final String signatureTypeSN; + + HealthCertificate({ + required this.name, + required this.subjectSN, + required this.issuerOrganisation, + required this.validFrom, + required this.validTo, + required this.signatureTypeSN, + }); + + factory HealthCertificate.fromMap(Map map) { + return HealthCertificate( + name: map['name'].toString(), + subjectSN: map['subjectSN'].toString(), + issuerOrganisation: map['issuerOrganisation'].toString(), + validFrom: map['validFrom'].toString(), + validTo: map['validTo'].toString(), + signatureTypeSN: map['signatureTypeSN'].toString(), + ); + } + + Map toMap() { + return { + "name": name, + "subjectSN": subjectSN, + "issuerOrganisation": issuerOrganisation, + "validFrom": validFrom, + "validTo": validTo, + "signatureTypeSN": signatureTypeSN, + }; + } } diff --git a/lib/src/models/health_queue.dart b/lib/src/models/health_queue.dart index 8267e5bc..fdb1f433 100644 --- a/lib/src/models/health_queue.dart +++ b/lib/src/models/health_queue.dart @@ -2,23 +2,24 @@ part of '../../models.dart'; /// Health Queue class HealthQueue implements Model { - /// Amount of actions in the queue. - final int size; + /// Amount of actions in the queue. + final int size; - HealthQueue({ - required this.size, - }); + HealthQueue({ + required this.size, + }); - factory HealthQueue.fromMap(Map map) { - return HealthQueue( - size: (map['size'] is String) ? - int.tryParse(map['size']) ?? 0:map['size'] ?? 0, - ); - } + factory HealthQueue.fromMap(Map map) { + return HealthQueue( + size: (map['size'] is String) + ? int.tryParse(map['size']) ?? 0 + : map['size'] ?? 0, + ); + } - Map toMap() { - return { - "size": size, - }; - } + Map toMap() { + return { + "size": size, + }; + } } diff --git a/lib/src/models/health_status.dart b/lib/src/models/health_status.dart index dbbcfef8..9469eb40 100644 --- a/lib/src/models/health_status.dart +++ b/lib/src/models/health_status.dart @@ -2,33 +2,36 @@ part of '../../models.dart'; /// Health Status class HealthStatus implements Model { - /// Name of the service. - final String name; - /// Duration in milliseconds how long the health check took. - final int ping; - /// Service status. Possible values can are: `pass`, `fail` - final String status; + /// Name of the service. + final String name; - HealthStatus({ - required this.name, - required this.ping, - required this.status, - }); + /// Duration in milliseconds how long the health check took. + final int ping; - factory HealthStatus.fromMap(Map map) { - return HealthStatus( - name: map['name'].toString(), - ping: (map['ping'] is String) ? - int.tryParse(map['ping']) ?? 0:map['ping'] ?? 0, - status: map['status'].toString(), - ); - } + /// Service status. Possible values can are: `pass`, `fail` + final String status; - Map toMap() { - return { - "name": name, - "ping": ping, - "status": status, - }; - } + HealthStatus({ + required this.name, + required this.ping, + required this.status, + }); + + factory HealthStatus.fromMap(Map map) { + return HealthStatus( + name: map['name'].toString(), + ping: (map['ping'] is String) + ? int.tryParse(map['ping']) ?? 0 + : map['ping'] ?? 0, + status: map['status'].toString(), + ); + } + + Map toMap() { + return { + "name": name, + "ping": ping, + "status": status, + }; + } } diff --git a/lib/src/models/health_time.dart b/lib/src/models/health_time.dart index 49b00a9d..284ab848 100644 --- a/lib/src/models/health_time.dart +++ b/lib/src/models/health_time.dart @@ -2,35 +2,40 @@ part of '../../models.dart'; /// Health Time class HealthTime implements Model { - /// Current unix timestamp on trustful remote server. - final int remoteTime; - /// Current unix timestamp of local server where Appwrite runs. - final int localTime; - /// Difference of unix remote and local timestamps in milliseconds. - final int diff; + /// Current unix timestamp on trustful remote server. + final int remoteTime; - HealthTime({ - required this.remoteTime, - required this.localTime, - required this.diff, - }); + /// Current unix timestamp of local server where Appwrite runs. + final int localTime; - factory HealthTime.fromMap(Map map) { - return HealthTime( - remoteTime: (map['remoteTime'] is String) ? - int.tryParse(map['remoteTime']) ?? 0:map['remoteTime'] ?? 0, - localTime: (map['localTime'] is String) ? - int.tryParse(map['localTime']) ?? 0:map['localTime'] ?? 0, - diff: (map['diff'] is String) ? - int.tryParse(map['diff']) ?? 0:map['diff'] ?? 0, - ); - } + /// Difference of unix remote and local timestamps in milliseconds. + final int diff; - Map toMap() { - return { - "remoteTime": remoteTime, - "localTime": localTime, - "diff": diff, - }; - } + HealthTime({ + required this.remoteTime, + required this.localTime, + required this.diff, + }); + + factory HealthTime.fromMap(Map map) { + return HealthTime( + remoteTime: (map['remoteTime'] is String) + ? int.tryParse(map['remoteTime']) ?? 0 + : map['remoteTime'] ?? 0, + localTime: (map['localTime'] is String) + ? int.tryParse(map['localTime']) ?? 0 + : map['localTime'] ?? 0, + diff: (map['diff'] is String) + ? int.tryParse(map['diff']) ?? 0 + : map['diff'] ?? 0, + ); + } + + Map toMap() { + return { + "remoteTime": remoteTime, + "localTime": localTime, + "diff": diff, + }; + } } diff --git a/lib/src/models/identity.dart b/lib/src/models/identity.dart index 632dc3db..807bdfd0 100644 --- a/lib/src/models/identity.dart +++ b/lib/src/models/identity.dart @@ -2,67 +2,76 @@ part of '../../models.dart'; /// Identity class Identity implements Model { - /// Identity ID. - final String $id; - /// Identity creation date in ISO 8601 format. - final String $createdAt; - /// Identity update date in ISO 8601 format. - final String $updatedAt; - /// User ID. - final String userId; - /// Identity Provider. - final String provider; - /// ID of the User in the Identity Provider. - final String providerUid; - /// Email of the User in the Identity Provider. - final String providerEmail; - /// Identity Provider Access Token. - final String providerAccessToken; - /// The date of when the access token expires in ISO 8601 format. - final String providerAccessTokenExpiry; - /// Identity Provider Refresh Token. - final String providerRefreshToken; + /// Identity ID. + final String $id; - Identity({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.userId, - required this.provider, - required this.providerUid, - required this.providerEmail, - required this.providerAccessToken, - required this.providerAccessTokenExpiry, - required this.providerRefreshToken, - }); + /// Identity creation date in ISO 8601 format. + final String $createdAt; - factory Identity.fromMap(Map map) { - return Identity( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - userId: map['userId'].toString(), - provider: map['provider'].toString(), - providerUid: map['providerUid'].toString(), - providerEmail: map['providerEmail'].toString(), - providerAccessToken: map['providerAccessToken'].toString(), - providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), - providerRefreshToken: map['providerRefreshToken'].toString(), - ); - } + /// Identity update date in ISO 8601 format. + final String $updatedAt; - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "userId": userId, - "provider": provider, - "providerUid": providerUid, - "providerEmail": providerEmail, - "providerAccessToken": providerAccessToken, - "providerAccessTokenExpiry": providerAccessTokenExpiry, - "providerRefreshToken": providerRefreshToken, - }; - } + /// User ID. + final String userId; + + /// Identity Provider. + final String provider; + + /// ID of the User in the Identity Provider. + final String providerUid; + + /// Email of the User in the Identity Provider. + final String providerEmail; + + /// Identity Provider Access Token. + final String providerAccessToken; + + /// The date of when the access token expires in ISO 8601 format. + final String providerAccessTokenExpiry; + + /// Identity Provider Refresh Token. + final String providerRefreshToken; + + Identity({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.userId, + required this.provider, + required this.providerUid, + required this.providerEmail, + required this.providerAccessToken, + required this.providerAccessTokenExpiry, + required this.providerRefreshToken, + }); + + factory Identity.fromMap(Map map) { + return Identity( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + userId: map['userId'].toString(), + provider: map['provider'].toString(), + providerUid: map['providerUid'].toString(), + providerEmail: map['providerEmail'].toString(), + providerAccessToken: map['providerAccessToken'].toString(), + providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), + providerRefreshToken: map['providerRefreshToken'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "userId": userId, + "provider": provider, + "providerUid": providerUid, + "providerEmail": providerEmail, + "providerAccessToken": providerAccessToken, + "providerAccessTokenExpiry": providerAccessTokenExpiry, + "providerRefreshToken": providerRefreshToken, + }; + } } diff --git a/lib/src/models/identity_list.dart b/lib/src/models/identity_list.dart index 77b9d8c7..3d546f5e 100644 --- a/lib/src/models/identity_list.dart +++ b/lib/src/models/identity_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Identities List class IdentityList implements Model { - /// Total number of identities documents that matched your query. - final int total; - /// List of identities. - final List identities; + /// Total number of identities documents that matched your query. + final int total; - IdentityList({ - required this.total, - required this.identities, - }); + /// List of identities. + final List identities; - factory IdentityList.fromMap(Map map) { - return IdentityList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - identities: List.from(map['identities'].map((p) => Identity.fromMap(p))), - ); - } + IdentityList({ + required this.total, + required this.identities, + }); - Map toMap() { - return { - "total": total, - "identities": identities.map((p) => p.toMap()).toList(), - }; - } + factory IdentityList.fromMap(Map map) { + return IdentityList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + identities: List.from( + map['identities'].map((p) => Identity.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "identities": identities.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/index.dart b/lib/src/models/index.dart index 9a4a1f9f..deb2f92e 100644 --- a/lib/src/models/index.dart +++ b/lib/src/models/index.dart @@ -2,47 +2,52 @@ part of '../../models.dart'; /// Index class Index implements Model { - /// Index Key. - final String key; - /// Index type. - final String type; - /// Index status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an index. - final String error; - /// Index attributes. - final List attributes; - /// Index orders. - final List? orders; - - Index({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.attributes, - this.orders, - }); - - factory Index.fromMap(Map map) { - return Index( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - attributes: map['attributes'] ?? [], - orders: map['orders'], - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "attributes": attributes, - "orders": orders, - }; - } + /// Index Key. + final String key; + + /// Index type. + final String type; + + /// Index status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + + /// Error message. Displays error generated on failure of creating or deleting an index. + final String error; + + /// Index attributes. + final List attributes; + + /// Index orders. + final List? orders; + + Index({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.attributes, + this.orders, + }); + + factory Index.fromMap(Map map) { + return Index( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + attributes: map['attributes'] ?? [], + orders: map['orders'], + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "attributes": attributes, + "orders": orders, + }; + } } diff --git a/lib/src/models/index_list.dart b/lib/src/models/index_list.dart index dbf66137..9927e08d 100644 --- a/lib/src/models/index_list.dart +++ b/lib/src/models/index_list.dart @@ -2,28 +2,30 @@ part of '../../models.dart'; /// Indexes List class IndexList implements Model { - /// Total number of indexes documents that matched your query. - final int total; - /// List of indexes. - final List indexes; + /// Total number of indexes documents that matched your query. + final int total; - IndexList({ - required this.total, - required this.indexes, - }); + /// List of indexes. + final List indexes; - factory IndexList.fromMap(Map map) { - return IndexList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - indexes: List.from(map['indexes'].map((p) => Index.fromMap(p))), - ); - } + IndexList({ + required this.total, + required this.indexes, + }); - Map toMap() { - return { - "total": total, - "indexes": indexes.map((p) => p.toMap()).toList(), - }; - } + factory IndexList.fromMap(Map map) { + return IndexList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + indexes: List.from(map['indexes'].map((p) => Index.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "indexes": indexes.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/jwt.dart b/lib/src/models/jwt.dart index 1b4ff7de..e2e31bd2 100644 --- a/lib/src/models/jwt.dart +++ b/lib/src/models/jwt.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// JWT class Jwt implements Model { - /// JWT encoded string. - final String jwt; + /// JWT encoded string. + final String jwt; - Jwt({ - required this.jwt, - }); + Jwt({ + required this.jwt, + }); - factory Jwt.fromMap(Map map) { - return Jwt( - jwt: map['jwt'].toString(), - ); - } + factory Jwt.fromMap(Map map) { + return Jwt( + jwt: map['jwt'].toString(), + ); + } - Map toMap() { - return { - "jwt": jwt, - }; - } + Map toMap() { + return { + "jwt": jwt, + }; + } } diff --git a/lib/src/models/language.dart b/lib/src/models/language.dart index 6d26c461..b6ec6121 100644 --- a/lib/src/models/language.dart +++ b/lib/src/models/language.dart @@ -2,32 +2,34 @@ part of '../../models.dart'; /// Language class Language implements Model { - /// Language name. - final String name; - /// Language two-character ISO 639-1 codes. - final String code; - /// Language native name. - final String nativeName; + /// Language name. + final String name; - Language({ - required this.name, - required this.code, - required this.nativeName, - }); + /// Language two-character ISO 639-1 codes. + final String code; - factory Language.fromMap(Map map) { - return Language( - name: map['name'].toString(), - code: map['code'].toString(), - nativeName: map['nativeName'].toString(), - ); - } + /// Language native name. + final String nativeName; - Map toMap() { - return { - "name": name, - "code": code, - "nativeName": nativeName, - }; - } + Language({ + required this.name, + required this.code, + required this.nativeName, + }); + + factory Language.fromMap(Map map) { + return Language( + name: map['name'].toString(), + code: map['code'].toString(), + nativeName: map['nativeName'].toString(), + ); + } + + Map toMap() { + return { + "name": name, + "code": code, + "nativeName": nativeName, + }; + } } diff --git a/lib/src/models/language_list.dart b/lib/src/models/language_list.dart index fd4824fb..b0cfcc49 100644 --- a/lib/src/models/language_list.dart +++ b/lib/src/models/language_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Languages List class LanguageList implements Model { - /// Total number of languages documents that matched your query. - final int total; - /// List of languages. - final List languages; + /// Total number of languages documents that matched your query. + final int total; - LanguageList({ - required this.total, - required this.languages, - }); + /// List of languages. + final List languages; - factory LanguageList.fromMap(Map map) { - return LanguageList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - languages: List.from(map['languages'].map((p) => Language.fromMap(p))), - ); - } + LanguageList({ + required this.total, + required this.languages, + }); - Map toMap() { - return { - "total": total, - "languages": languages.map((p) => p.toMap()).toList(), - }; - } + factory LanguageList.fromMap(Map map) { + return LanguageList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + languages: + List.from(map['languages'].map((p) => Language.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "languages": languages.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/locale.dart b/lib/src/models/locale.dart index 0f0fd7f2..084475bf 100644 --- a/lib/src/models/locale.dart +++ b/lib/src/models/locale.dart @@ -2,52 +2,58 @@ part of '../../models.dart'; /// Locale class Locale implements Model { - /// User IP address. - final String ip; - /// Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format - final String countryCode; - /// Country name. This field support localization. - final String country; - /// Continent code. A two character continent code "AF" for Africa, "AN" for Antarctica, "AS" for Asia, "EU" for Europe, "NA" for North America, "OC" for Oceania, and "SA" for South America. - final String continentCode; - /// Continent name. This field support localization. - final String continent; - /// True if country is part of the European Union. - final bool eu; - /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format - final String currency; - - Locale({ - required this.ip, - required this.countryCode, - required this.country, - required this.continentCode, - required this.continent, - required this.eu, - required this.currency, - }); - - factory Locale.fromMap(Map map) { - return Locale( - ip: map['ip'].toString(), - countryCode: map['countryCode'].toString(), - country: map['country'].toString(), - continentCode: map['continentCode'].toString(), - continent: map['continent'].toString(), - eu: map['eu'], - currency: map['currency'].toString(), - ); - } - - Map toMap() { - return { - "ip": ip, - "countryCode": countryCode, - "country": country, - "continentCode": continentCode, - "continent": continent, - "eu": eu, - "currency": currency, - }; - } + /// User IP address. + final String ip; + + /// Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format + final String countryCode; + + /// Country name. This field support localization. + final String country; + + /// Continent code. A two character continent code "AF" for Africa, "AN" for Antarctica, "AS" for Asia, "EU" for Europe, "NA" for North America, "OC" for Oceania, and "SA" for South America. + final String continentCode; + + /// Continent name. This field support localization. + final String continent; + + /// True if country is part of the European Union. + final bool eu; + + /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format + final String currency; + + Locale({ + required this.ip, + required this.countryCode, + required this.country, + required this.continentCode, + required this.continent, + required this.eu, + required this.currency, + }); + + factory Locale.fromMap(Map map) { + return Locale( + ip: map['ip'].toString(), + countryCode: map['countryCode'].toString(), + country: map['country'].toString(), + continentCode: map['continentCode'].toString(), + continent: map['continent'].toString(), + eu: map['eu'], + currency: map['currency'].toString(), + ); + } + + Map toMap() { + return { + "ip": ip, + "countryCode": countryCode, + "country": country, + "continentCode": continentCode, + "continent": continent, + "eu": eu, + "currency": currency, + }; + } } diff --git a/lib/src/models/locale_code.dart b/lib/src/models/locale_code.dart index eebce199..678e40c4 100644 --- a/lib/src/models/locale_code.dart +++ b/lib/src/models/locale_code.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// LocaleCode class LocaleCode implements Model { - /// Locale codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) - final String code; - /// Locale name - final String name; + /// Locale codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) + final String code; - LocaleCode({ - required this.code, - required this.name, - }); + /// Locale name + final String name; - factory LocaleCode.fromMap(Map map) { - return LocaleCode( - code: map['code'].toString(), - name: map['name'].toString(), - ); - } + LocaleCode({ + required this.code, + required this.name, + }); - Map toMap() { - return { - "code": code, - "name": name, - }; - } + factory LocaleCode.fromMap(Map map) { + return LocaleCode( + code: map['code'].toString(), + name: map['name'].toString(), + ); + } + + Map toMap() { + return { + "code": code, + "name": name, + }; + } } diff --git a/lib/src/models/locale_code_list.dart b/lib/src/models/locale_code_list.dart index 9ed7f657..9bd97f78 100644 --- a/lib/src/models/locale_code_list.dart +++ b/lib/src/models/locale_code_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Locale codes list class LocaleCodeList implements Model { - /// Total number of localeCodes documents that matched your query. - final int total; - /// List of localeCodes. - final List localeCodes; + /// Total number of localeCodes documents that matched your query. + final int total; - LocaleCodeList({ - required this.total, - required this.localeCodes, - }); + /// List of localeCodes. + final List localeCodes; - factory LocaleCodeList.fromMap(Map map) { - return LocaleCodeList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - localeCodes: List.from(map['localeCodes'].map((p) => LocaleCode.fromMap(p))), - ); - } + LocaleCodeList({ + required this.total, + required this.localeCodes, + }); - Map toMap() { - return { - "total": total, - "localeCodes": localeCodes.map((p) => p.toMap()).toList(), - }; - } + factory LocaleCodeList.fromMap(Map map) { + return LocaleCodeList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + localeCodes: List.from( + map['localeCodes'].map((p) => LocaleCode.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "localeCodes": localeCodes.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/log.dart b/lib/src/models/log.dart index 41cda2ca..7fb3f364 100644 --- a/lib/src/models/log.dart +++ b/lib/src/models/log.dart @@ -2,122 +2,142 @@ part of '../../models.dart'; /// Log class Log implements Model { - /// Event name. - final String event; - /// User ID. - final String userId; - /// User Email. - final String userEmail; - /// User Name. - final String userName; - /// API mode when event triggered. - final String mode; - /// IP session in use when the session was created. - final String ip; - /// Log creation date in ISO 8601 format. - final String time; - /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). - final String osCode; - /// Operating system name. - final String osName; - /// Operating system version. - final String osVersion; - /// Client type. - final String clientType; - /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). - final String clientCode; - /// Client name. - final String clientName; - /// Client version. - final String clientVersion; - /// Client engine name. - final String clientEngine; - /// Client engine name. - final String clientEngineVersion; - /// Device name. - final String deviceName; - /// Device brand name. - final String deviceBrand; - /// Device model name. - final String deviceModel; - /// Country two-character ISO 3166-1 alpha code. - final String countryCode; - /// Country name. - final String countryName; - - Log({ - required this.event, - required this.userId, - required this.userEmail, - required this.userName, - required this.mode, - required this.ip, - required this.time, - required this.osCode, - required this.osName, - required this.osVersion, - required this.clientType, - required this.clientCode, - required this.clientName, - required this.clientVersion, - required this.clientEngine, - required this.clientEngineVersion, - required this.deviceName, - required this.deviceBrand, - required this.deviceModel, - required this.countryCode, - required this.countryName, - }); - - factory Log.fromMap(Map map) { - return Log( - event: map['event'].toString(), - userId: map['userId'].toString(), - userEmail: map['userEmail'].toString(), - userName: map['userName'].toString(), - mode: map['mode'].toString(), - ip: map['ip'].toString(), - time: map['time'].toString(), - osCode: map['osCode'].toString(), - osName: map['osName'].toString(), - osVersion: map['osVersion'].toString(), - clientType: map['clientType'].toString(), - clientCode: map['clientCode'].toString(), - clientName: map['clientName'].toString(), - clientVersion: map['clientVersion'].toString(), - clientEngine: map['clientEngine'].toString(), - clientEngineVersion: map['clientEngineVersion'].toString(), - deviceName: map['deviceName'].toString(), - deviceBrand: map['deviceBrand'].toString(), - deviceModel: map['deviceModel'].toString(), - countryCode: map['countryCode'].toString(), - countryName: map['countryName'].toString(), - ); - } - - Map toMap() { - return { - "event": event, - "userId": userId, - "userEmail": userEmail, - "userName": userName, - "mode": mode, - "ip": ip, - "time": time, - "osCode": osCode, - "osName": osName, - "osVersion": osVersion, - "clientType": clientType, - "clientCode": clientCode, - "clientName": clientName, - "clientVersion": clientVersion, - "clientEngine": clientEngine, - "clientEngineVersion": clientEngineVersion, - "deviceName": deviceName, - "deviceBrand": deviceBrand, - "deviceModel": deviceModel, - "countryCode": countryCode, - "countryName": countryName, - }; - } + /// Event name. + final String event; + + /// User ID. + final String userId; + + /// User Email. + final String userEmail; + + /// User Name. + final String userName; + + /// API mode when event triggered. + final String mode; + + /// IP session in use when the session was created. + final String ip; + + /// Log creation date in ISO 8601 format. + final String time; + + /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). + final String osCode; + + /// Operating system name. + final String osName; + + /// Operating system version. + final String osVersion; + + /// Client type. + final String clientType; + + /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). + final String clientCode; + + /// Client name. + final String clientName; + + /// Client version. + final String clientVersion; + + /// Client engine name. + final String clientEngine; + + /// Client engine name. + final String clientEngineVersion; + + /// Device name. + final String deviceName; + + /// Device brand name. + final String deviceBrand; + + /// Device model name. + final String deviceModel; + + /// Country two-character ISO 3166-1 alpha code. + final String countryCode; + + /// Country name. + final String countryName; + + Log({ + required this.event, + required this.userId, + required this.userEmail, + required this.userName, + required this.mode, + required this.ip, + required this.time, + required this.osCode, + required this.osName, + required this.osVersion, + required this.clientType, + required this.clientCode, + required this.clientName, + required this.clientVersion, + required this.clientEngine, + required this.clientEngineVersion, + required this.deviceName, + required this.deviceBrand, + required this.deviceModel, + required this.countryCode, + required this.countryName, + }); + + factory Log.fromMap(Map map) { + return Log( + event: map['event'].toString(), + userId: map['userId'].toString(), + userEmail: map['userEmail'].toString(), + userName: map['userName'].toString(), + mode: map['mode'].toString(), + ip: map['ip'].toString(), + time: map['time'].toString(), + osCode: map['osCode'].toString(), + osName: map['osName'].toString(), + osVersion: map['osVersion'].toString(), + clientType: map['clientType'].toString(), + clientCode: map['clientCode'].toString(), + clientName: map['clientName'].toString(), + clientVersion: map['clientVersion'].toString(), + clientEngine: map['clientEngine'].toString(), + clientEngineVersion: map['clientEngineVersion'].toString(), + deviceName: map['deviceName'].toString(), + deviceBrand: map['deviceBrand'].toString(), + deviceModel: map['deviceModel'].toString(), + countryCode: map['countryCode'].toString(), + countryName: map['countryName'].toString(), + ); + } + + Map toMap() { + return { + "event": event, + "userId": userId, + "userEmail": userEmail, + "userName": userName, + "mode": mode, + "ip": ip, + "time": time, + "osCode": osCode, + "osName": osName, + "osVersion": osVersion, + "clientType": clientType, + "clientCode": clientCode, + "clientName": clientName, + "clientVersion": clientVersion, + "clientEngine": clientEngine, + "clientEngineVersion": clientEngineVersion, + "deviceName": deviceName, + "deviceBrand": deviceBrand, + "deviceModel": deviceModel, + "countryCode": countryCode, + "countryName": countryName, + }; + } } diff --git a/lib/src/models/log_list.dart b/lib/src/models/log_list.dart index c7d6000c..2c06cc50 100644 --- a/lib/src/models/log_list.dart +++ b/lib/src/models/log_list.dart @@ -2,28 +2,30 @@ part of '../../models.dart'; /// Logs List class LogList implements Model { - /// Total number of logs documents that matched your query. - final int total; - /// List of logs. - final List logs; + /// Total number of logs documents that matched your query. + final int total; - LogList({ - required this.total, - required this.logs, - }); + /// List of logs. + final List logs; - factory LogList.fromMap(Map map) { - return LogList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - logs: List.from(map['logs'].map((p) => Log.fromMap(p))), - ); - } + LogList({ + required this.total, + required this.logs, + }); - Map toMap() { - return { - "total": total, - "logs": logs.map((p) => p.toMap()).toList(), - }; - } + factory LogList.fromMap(Map map) { + return LogList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + logs: List.from(map['logs'].map((p) => Log.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "logs": logs.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/membership.dart b/lib/src/models/membership.dart index 283f4ee5..fb3fb523 100644 --- a/lib/src/models/membership.dart +++ b/lib/src/models/membership.dart @@ -2,82 +2,94 @@ part of '../../models.dart'; /// Membership class Membership implements Model { - /// Membership ID. - final String $id; - /// Membership creation date in ISO 8601 format. - final String $createdAt; - /// Membership update date in ISO 8601 format. - final String $updatedAt; - /// User ID. - final String userId; - /// User name. - final String userName; - /// User email address. - final String userEmail; - /// Team ID. - final String teamId; - /// Team name. - final String teamName; - /// Date, the user has been invited to join the team in ISO 8601 format. - final String invited; - /// Date, the user has accepted the invitation to join the team in ISO 8601 format. - final String joined; - /// User confirmation status, true if the user has joined the team or false otherwise. - final bool confirm; - /// Multi factor authentication status, true if the user has MFA enabled or false otherwise. - final bool mfa; - /// User list of roles - final List roles; - - Membership({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.userId, - required this.userName, - required this.userEmail, - required this.teamId, - required this.teamName, - required this.invited, - required this.joined, - required this.confirm, - required this.mfa, - required this.roles, - }); - - factory Membership.fromMap(Map map) { - return Membership( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - userId: map['userId'].toString(), - userName: map['userName'].toString(), - userEmail: map['userEmail'].toString(), - teamId: map['teamId'].toString(), - teamName: map['teamName'].toString(), - invited: map['invited'].toString(), - joined: map['joined'].toString(), - confirm: map['confirm'], - mfa: map['mfa'], - roles: map['roles'] ?? [], - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "userId": userId, - "userName": userName, - "userEmail": userEmail, - "teamId": teamId, - "teamName": teamName, - "invited": invited, - "joined": joined, - "confirm": confirm, - "mfa": mfa, - "roles": roles, - }; - } + /// Membership ID. + final String $id; + + /// Membership creation date in ISO 8601 format. + final String $createdAt; + + /// Membership update date in ISO 8601 format. + final String $updatedAt; + + /// User ID. + final String userId; + + /// User name. + final String userName; + + /// User email address. + final String userEmail; + + /// Team ID. + final String teamId; + + /// Team name. + final String teamName; + + /// Date, the user has been invited to join the team in ISO 8601 format. + final String invited; + + /// Date, the user has accepted the invitation to join the team in ISO 8601 format. + final String joined; + + /// User confirmation status, true if the user has joined the team or false otherwise. + final bool confirm; + + /// Multi factor authentication status, true if the user has MFA enabled or false otherwise. + final bool mfa; + + /// User list of roles + final List roles; + + Membership({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.userId, + required this.userName, + required this.userEmail, + required this.teamId, + required this.teamName, + required this.invited, + required this.joined, + required this.confirm, + required this.mfa, + required this.roles, + }); + + factory Membership.fromMap(Map map) { + return Membership( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + userId: map['userId'].toString(), + userName: map['userName'].toString(), + userEmail: map['userEmail'].toString(), + teamId: map['teamId'].toString(), + teamName: map['teamName'].toString(), + invited: map['invited'].toString(), + joined: map['joined'].toString(), + confirm: map['confirm'], + mfa: map['mfa'], + roles: map['roles'] ?? [], + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "userId": userId, + "userName": userName, + "userEmail": userEmail, + "teamId": teamId, + "teamName": teamName, + "invited": invited, + "joined": joined, + "confirm": confirm, + "mfa": mfa, + "roles": roles, + }; + } } diff --git a/lib/src/models/membership_list.dart b/lib/src/models/membership_list.dart index f5302cbf..880c1d20 100644 --- a/lib/src/models/membership_list.dart +++ b/lib/src/models/membership_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Memberships List class MembershipList implements Model { - /// Total number of memberships documents that matched your query. - final int total; - /// List of memberships. - final List memberships; + /// Total number of memberships documents that matched your query. + final int total; - MembershipList({ - required this.total, - required this.memberships, - }); + /// List of memberships. + final List memberships; - factory MembershipList.fromMap(Map map) { - return MembershipList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - memberships: List.from(map['memberships'].map((p) => Membership.fromMap(p))), - ); - } + MembershipList({ + required this.total, + required this.memberships, + }); - Map toMap() { - return { - "total": total, - "memberships": memberships.map((p) => p.toMap()).toList(), - }; - } + factory MembershipList.fromMap(Map map) { + return MembershipList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + memberships: List.from( + map['memberships'].map((p) => Membership.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "memberships": memberships.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/message.dart b/lib/src/models/message.dart index 381ab216..fe2a53ab 100644 --- a/lib/src/models/message.dart +++ b/lib/src/models/message.dart @@ -2,83 +2,96 @@ part of '../../models.dart'; /// Message class Message implements Model { - /// Message ID. - final String $id; - /// Message creation time in ISO 8601 format. - final String $createdAt; - /// Message update date in ISO 8601 format. - final String $updatedAt; - /// Message provider type. - final String providerType; - /// Topic IDs set as recipients. - final List topics; - /// User IDs set as recipients. - final List users; - /// Target IDs set as recipients. - final List targets; - /// The scheduled time for message. - final String? scheduledAt; - /// The time when the message was delivered. - final String? deliveredAt; - /// Delivery errors if any. - final List? deliveryErrors; - /// Number of recipients the message was delivered to. - final int deliveredTotal; - /// Data of the message. - final Map data; - /// Status of delivery. - final String status; - - Message({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.providerType, - required this.topics, - required this.users, - required this.targets, - this.scheduledAt, - this.deliveredAt, - this.deliveryErrors, - required this.deliveredTotal, - required this.data, - required this.status, - }); - - factory Message.fromMap(Map map) { - return Message( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - providerType: map['providerType'].toString(), - topics: map['topics'] ?? [], - users: map['users'] ?? [], - targets: map['targets'] ?? [], - scheduledAt: map['scheduledAt']?.toString(), - deliveredAt: map['deliveredAt']?.toString(), - deliveryErrors: map['deliveryErrors'], - deliveredTotal: (map['deliveredTotal'] is String) ? - int.tryParse(map['deliveredTotal']) ?? 0:map['deliveredTotal'] ?? 0, - data: map['data'], - status: map['status'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "providerType": providerType, - "topics": topics, - "users": users, - "targets": targets, - "scheduledAt": scheduledAt, - "deliveredAt": deliveredAt, - "deliveryErrors": deliveryErrors, - "deliveredTotal": deliveredTotal, - "data": data, - "status": status, - }; - } + /// Message ID. + final String $id; + + /// Message creation time in ISO 8601 format. + final String $createdAt; + + /// Message update date in ISO 8601 format. + final String $updatedAt; + + /// Message provider type. + final String providerType; + + /// Topic IDs set as recipients. + final List topics; + + /// User IDs set as recipients. + final List users; + + /// Target IDs set as recipients. + final List targets; + + /// The scheduled time for message. + final String? scheduledAt; + + /// The time when the message was delivered. + final String? deliveredAt; + + /// Delivery errors if any. + final List? deliveryErrors; + + /// Number of recipients the message was delivered to. + final int deliveredTotal; + + /// Data of the message. + final Map data; + + /// Status of delivery. + final String status; + + Message({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.providerType, + required this.topics, + required this.users, + required this.targets, + this.scheduledAt, + this.deliveredAt, + this.deliveryErrors, + required this.deliveredTotal, + required this.data, + required this.status, + }); + + factory Message.fromMap(Map map) { + return Message( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + providerType: map['providerType'].toString(), + topics: map['topics'] ?? [], + users: map['users'] ?? [], + targets: map['targets'] ?? [], + scheduledAt: map['scheduledAt']?.toString(), + deliveredAt: map['deliveredAt']?.toString(), + deliveryErrors: map['deliveryErrors'], + deliveredTotal: (map['deliveredTotal'] is String) + ? int.tryParse(map['deliveredTotal']) ?? 0 + : map['deliveredTotal'] ?? 0, + data: map['data'], + status: map['status'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "providerType": providerType, + "topics": topics, + "users": users, + "targets": targets, + "scheduledAt": scheduledAt, + "deliveredAt": deliveredAt, + "deliveryErrors": deliveryErrors, + "deliveredTotal": deliveredTotal, + "data": data, + "status": status, + }; + } } diff --git a/lib/src/models/message_list.dart b/lib/src/models/message_list.dart index 220d3c52..1c128731 100644 --- a/lib/src/models/message_list.dart +++ b/lib/src/models/message_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Message list class MessageList implements Model { - /// Total number of messages documents that matched your query. - final int total; - /// List of messages. - final List messages; + /// Total number of messages documents that matched your query. + final int total; - MessageList({ - required this.total, - required this.messages, - }); + /// List of messages. + final List messages; - factory MessageList.fromMap(Map map) { - return MessageList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - messages: List.from(map['messages'].map((p) => Message.fromMap(p))), - ); - } + MessageList({ + required this.total, + required this.messages, + }); - Map toMap() { - return { - "total": total, - "messages": messages.map((p) => p.toMap()).toList(), - }; - } + factory MessageList.fromMap(Map map) { + return MessageList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + messages: + List.from(map['messages'].map((p) => Message.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "messages": messages.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/mfa_challenge.dart b/lib/src/models/mfa_challenge.dart index 043ff286..96bf3c65 100644 --- a/lib/src/models/mfa_challenge.dart +++ b/lib/src/models/mfa_challenge.dart @@ -2,37 +2,40 @@ part of '../../models.dart'; /// MFA Challenge class MfaChallenge implements Model { - /// Token ID. - final String $id; - /// Token creation date in ISO 8601 format. - final String $createdAt; - /// User ID. - final String userId; - /// Token expiration date in ISO 8601 format. - final String expire; + /// Token ID. + final String $id; - MfaChallenge({ - required this.$id, - required this.$createdAt, - required this.userId, - required this.expire, - }); + /// Token creation date in ISO 8601 format. + final String $createdAt; - factory MfaChallenge.fromMap(Map map) { - return MfaChallenge( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - userId: map['userId'].toString(), - expire: map['expire'].toString(), - ); - } + /// User ID. + final String userId; - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "userId": userId, - "expire": expire, - }; - } + /// Token expiration date in ISO 8601 format. + final String expire; + + MfaChallenge({ + required this.$id, + required this.$createdAt, + required this.userId, + required this.expire, + }); + + factory MfaChallenge.fromMap(Map map) { + return MfaChallenge( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + userId: map['userId'].toString(), + expire: map['expire'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "userId": userId, + "expire": expire, + }; + } } diff --git a/lib/src/models/mfa_factors.dart b/lib/src/models/mfa_factors.dart index f453e870..c930a23e 100644 --- a/lib/src/models/mfa_factors.dart +++ b/lib/src/models/mfa_factors.dart @@ -2,37 +2,40 @@ part of '../../models.dart'; /// MFAFactors class MfaFactors implements Model { - /// Can TOTP be used for MFA challenge for this account. - final bool totp; - /// Can phone (SMS) be used for MFA challenge for this account. - final bool phone; - /// Can email be used for MFA challenge for this account. - final bool email; - /// Can recovery code be used for MFA challenge for this account. - final bool recoveryCode; + /// Can TOTP be used for MFA challenge for this account. + final bool totp; - MfaFactors({ - required this.totp, - required this.phone, - required this.email, - required this.recoveryCode, - }); + /// Can phone (SMS) be used for MFA challenge for this account. + final bool phone; - factory MfaFactors.fromMap(Map map) { - return MfaFactors( - totp: map['totp'], - phone: map['phone'], - email: map['email'], - recoveryCode: map['recoveryCode'], - ); - } + /// Can email be used for MFA challenge for this account. + final bool email; - Map toMap() { - return { - "totp": totp, - "phone": phone, - "email": email, - "recoveryCode": recoveryCode, - }; - } + /// Can recovery code be used for MFA challenge for this account. + final bool recoveryCode; + + MfaFactors({ + required this.totp, + required this.phone, + required this.email, + required this.recoveryCode, + }); + + factory MfaFactors.fromMap(Map map) { + return MfaFactors( + totp: map['totp'], + phone: map['phone'], + email: map['email'], + recoveryCode: map['recoveryCode'], + ); + } + + Map toMap() { + return { + "totp": totp, + "phone": phone, + "email": email, + "recoveryCode": recoveryCode, + }; + } } diff --git a/lib/src/models/mfa_recovery_codes.dart b/lib/src/models/mfa_recovery_codes.dart index 68402443..83483901 100644 --- a/lib/src/models/mfa_recovery_codes.dart +++ b/lib/src/models/mfa_recovery_codes.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// MFA Recovery Codes class MfaRecoveryCodes implements Model { - /// Recovery codes. - final List recoveryCodes; + /// Recovery codes. + final List recoveryCodes; - MfaRecoveryCodes({ - required this.recoveryCodes, - }); + MfaRecoveryCodes({ + required this.recoveryCodes, + }); - factory MfaRecoveryCodes.fromMap(Map map) { - return MfaRecoveryCodes( - recoveryCodes: map['recoveryCodes'] ?? [], - ); - } + factory MfaRecoveryCodes.fromMap(Map map) { + return MfaRecoveryCodes( + recoveryCodes: map['recoveryCodes'] ?? [], + ); + } - Map toMap() { - return { - "recoveryCodes": recoveryCodes, - }; - } + Map toMap() { + return { + "recoveryCodes": recoveryCodes, + }; + } } diff --git a/lib/src/models/mfa_type.dart b/lib/src/models/mfa_type.dart index 87064007..0573166e 100644 --- a/lib/src/models/mfa_type.dart +++ b/lib/src/models/mfa_type.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// MFAType class MfaType implements Model { - /// Secret token used for TOTP factor. - final String secret; - /// URI for authenticator apps. - final String uri; + /// Secret token used for TOTP factor. + final String secret; - MfaType({ - required this.secret, - required this.uri, - }); + /// URI for authenticator apps. + final String uri; - factory MfaType.fromMap(Map map) { - return MfaType( - secret: map['secret'].toString(), - uri: map['uri'].toString(), - ); - } + MfaType({ + required this.secret, + required this.uri, + }); - Map toMap() { - return { - "secret": secret, - "uri": uri, - }; - } + factory MfaType.fromMap(Map map) { + return MfaType( + secret: map['secret'].toString(), + uri: map['uri'].toString(), + ); + } + + Map toMap() { + return { + "secret": secret, + "uri": uri, + }; + } } diff --git a/lib/src/models/model.dart b/lib/src/models/model.dart index 48e5b84a..f810a35b 100644 --- a/lib/src/models/model.dart +++ b/lib/src/models/model.dart @@ -2,4 +2,4 @@ part of '../../models.dart'; abstract class Model { Map toMap(); -} \ No newline at end of file +} diff --git a/lib/src/models/phone.dart b/lib/src/models/phone.dart index 24f7260d..40f7bcd2 100644 --- a/lib/src/models/phone.dart +++ b/lib/src/models/phone.dart @@ -2,32 +2,34 @@ part of '../../models.dart'; /// Phone class Phone implements Model { - /// Phone code. - final String code; - /// Country two-character ISO 3166-1 alpha code. - final String countryCode; - /// Country name. - final String countryName; + /// Phone code. + final String code; - Phone({ - required this.code, - required this.countryCode, - required this.countryName, - }); + /// Country two-character ISO 3166-1 alpha code. + final String countryCode; - factory Phone.fromMap(Map map) { - return Phone( - code: map['code'].toString(), - countryCode: map['countryCode'].toString(), - countryName: map['countryName'].toString(), - ); - } + /// Country name. + final String countryName; - Map toMap() { - return { - "code": code, - "countryCode": countryCode, - "countryName": countryName, - }; - } + Phone({ + required this.code, + required this.countryCode, + required this.countryName, + }); + + factory Phone.fromMap(Map map) { + return Phone( + code: map['code'].toString(), + countryCode: map['countryCode'].toString(), + countryName: map['countryName'].toString(), + ); + } + + Map toMap() { + return { + "code": code, + "countryCode": countryCode, + "countryName": countryName, + }; + } } diff --git a/lib/src/models/phone_list.dart b/lib/src/models/phone_list.dart index f00a91d3..f2cb989b 100644 --- a/lib/src/models/phone_list.dart +++ b/lib/src/models/phone_list.dart @@ -2,28 +2,30 @@ part of '../../models.dart'; /// Phones List class PhoneList implements Model { - /// Total number of phones documents that matched your query. - final int total; - /// List of phones. - final List phones; + /// Total number of phones documents that matched your query. + final int total; - PhoneList({ - required this.total, - required this.phones, - }); + /// List of phones. + final List phones; - factory PhoneList.fromMap(Map map) { - return PhoneList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - phones: List.from(map['phones'].map((p) => Phone.fromMap(p))), - ); - } + PhoneList({ + required this.total, + required this.phones, + }); - Map toMap() { - return { - "total": total, - "phones": phones.map((p) => p.toMap()).toList(), - }; - } + factory PhoneList.fromMap(Map map) { + return PhoneList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + phones: List.from(map['phones'].map((p) => Phone.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "phones": phones.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/preferences.dart b/lib/src/models/preferences.dart index 3c62f86d..3549cff0 100644 --- a/lib/src/models/preferences.dart +++ b/lib/src/models/preferences.dart @@ -2,23 +2,23 @@ part of '../../models.dart'; /// Preferences class Preferences implements Model { - final Map data; + final Map data; - Preferences({ - required this.data, - }); + Preferences({ + required this.data, + }); - factory Preferences.fromMap(Map map) { - return Preferences( - data: map, - ); - } + factory Preferences.fromMap(Map map) { + return Preferences( + data: map, + ); + } - Map toMap() { - return { - "data": data, - }; - } + Map toMap() { + return { + "data": data, + }; + } - T convertTo(T Function(Map) fromJson) => fromJson(data); + T convertTo(T Function(Map) fromJson) => fromJson(data); } diff --git a/lib/src/models/provider.dart b/lib/src/models/provider.dart index ba0855de..1a762f85 100644 --- a/lib/src/models/provider.dart +++ b/lib/src/models/provider.dart @@ -2,62 +2,70 @@ part of '../../models.dart'; /// Provider class Provider implements Model { - /// Provider ID. - final String $id; - /// Provider creation time in ISO 8601 format. - final String $createdAt; - /// Provider update date in ISO 8601 format. - final String $updatedAt; - /// The name for the provider instance. - final String name; - /// The name of the provider service. - final String provider; - /// Is provider enabled? - final bool enabled; - /// Type of provider. - final String type; - /// Provider credentials. - final Map credentials; - /// Provider options. - final Map? options; - - Provider({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.provider, - required this.enabled, - required this.type, - required this.credentials, - this.options, - }); - - factory Provider.fromMap(Map map) { - return Provider( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - provider: map['provider'].toString(), - enabled: map['enabled'], - type: map['type'].toString(), - credentials: map['credentials'], - options: map['options'], - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "provider": provider, - "enabled": enabled, - "type": type, - "credentials": credentials, - "options": options, - }; - } + /// Provider ID. + final String $id; + + /// Provider creation time in ISO 8601 format. + final String $createdAt; + + /// Provider update date in ISO 8601 format. + final String $updatedAt; + + /// The name for the provider instance. + final String name; + + /// The name of the provider service. + final String provider; + + /// Is provider enabled? + final bool enabled; + + /// Type of provider. + final String type; + + /// Provider credentials. + final Map credentials; + + /// Provider options. + final Map? options; + + Provider({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.provider, + required this.enabled, + required this.type, + required this.credentials, + this.options, + }); + + factory Provider.fromMap(Map map) { + return Provider( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + provider: map['provider'].toString(), + enabled: map['enabled'], + type: map['type'].toString(), + credentials: map['credentials'], + options: map['options'], + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "provider": provider, + "enabled": enabled, + "type": type, + "credentials": credentials, + "options": options, + }; + } } diff --git a/lib/src/models/provider_list.dart b/lib/src/models/provider_list.dart index fe6d41d0..415f0d9b 100644 --- a/lib/src/models/provider_list.dart +++ b/lib/src/models/provider_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Provider list class ProviderList implements Model { - /// Total number of providers documents that matched your query. - final int total; - /// List of providers. - final List providers; + /// Total number of providers documents that matched your query. + final int total; - ProviderList({ - required this.total, - required this.providers, - }); + /// List of providers. + final List providers; - factory ProviderList.fromMap(Map map) { - return ProviderList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - providers: List.from(map['providers'].map((p) => Provider.fromMap(p))), - ); - } + ProviderList({ + required this.total, + required this.providers, + }); - Map toMap() { - return { - "total": total, - "providers": providers.map((p) => p.toMap()).toList(), - }; - } + factory ProviderList.fromMap(Map map) { + return ProviderList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + providers: + List.from(map['providers'].map((p) => Provider.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "providers": providers.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/runtime.dart b/lib/src/models/runtime.dart index acda5a4f..c99f3541 100644 --- a/lib/src/models/runtime.dart +++ b/lib/src/models/runtime.dart @@ -2,57 +2,64 @@ part of '../../models.dart'; /// Runtime class Runtime implements Model { - /// Runtime ID. - final String $id; - /// Parent runtime key. - final String key; - /// Runtime Name. - final String name; - /// Runtime version. - final String version; - /// Base Docker image used to build the runtime. - final String base; - /// Image name of Docker Hub. - final String image; - /// Name of the logo image. - final String logo; - /// List of supported architectures. - final List supports; - - Runtime({ - required this.$id, - required this.key, - required this.name, - required this.version, - required this.base, - required this.image, - required this.logo, - required this.supports, - }); - - factory Runtime.fromMap(Map map) { - return Runtime( - $id: map['\$id'].toString(), - key: map['key'].toString(), - name: map['name'].toString(), - version: map['version'].toString(), - base: map['base'].toString(), - image: map['image'].toString(), - logo: map['logo'].toString(), - supports: map['supports'] ?? [], - ); - } - - Map toMap() { - return { - "\$id": $id, - "key": key, - "name": name, - "version": version, - "base": base, - "image": image, - "logo": logo, - "supports": supports, - }; - } + /// Runtime ID. + final String $id; + + /// Parent runtime key. + final String key; + + /// Runtime Name. + final String name; + + /// Runtime version. + final String version; + + /// Base Docker image used to build the runtime. + final String base; + + /// Image name of Docker Hub. + final String image; + + /// Name of the logo image. + final String logo; + + /// List of supported architectures. + final List supports; + + Runtime({ + required this.$id, + required this.key, + required this.name, + required this.version, + required this.base, + required this.image, + required this.logo, + required this.supports, + }); + + factory Runtime.fromMap(Map map) { + return Runtime( + $id: map['\$id'].toString(), + key: map['key'].toString(), + name: map['name'].toString(), + version: map['version'].toString(), + base: map['base'].toString(), + image: map['image'].toString(), + logo: map['logo'].toString(), + supports: map['supports'] ?? [], + ); + } + + Map toMap() { + return { + "\$id": $id, + "key": key, + "name": name, + "version": version, + "base": base, + "image": image, + "logo": logo, + "supports": supports, + }; + } } diff --git a/lib/src/models/runtime_list.dart b/lib/src/models/runtime_list.dart index 8ee86986..386ef56f 100644 --- a/lib/src/models/runtime_list.dart +++ b/lib/src/models/runtime_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Runtimes List class RuntimeList implements Model { - /// Total number of runtimes documents that matched your query. - final int total; - /// List of runtimes. - final List runtimes; + /// Total number of runtimes documents that matched your query. + final int total; - RuntimeList({ - required this.total, - required this.runtimes, - }); + /// List of runtimes. + final List runtimes; - factory RuntimeList.fromMap(Map map) { - return RuntimeList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - runtimes: List.from(map['runtimes'].map((p) => Runtime.fromMap(p))), - ); - } + RuntimeList({ + required this.total, + required this.runtimes, + }); - Map toMap() { - return { - "total": total, - "runtimes": runtimes.map((p) => p.toMap()).toList(), - }; - } + factory RuntimeList.fromMap(Map map) { + return RuntimeList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + runtimes: + List.from(map['runtimes'].map((p) => Runtime.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "runtimes": runtimes.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/session.dart b/lib/src/models/session.dart index 10566f44..1f55d400 100644 --- a/lib/src/models/session.dart +++ b/lib/src/models/session.dart @@ -2,162 +2,190 @@ part of '../../models.dart'; /// Session class Session implements Model { - /// Session ID. - final String $id; - /// Session creation date in ISO 8601 format. - final String $createdAt; - /// Session update date in ISO 8601 format. - final String $updatedAt; - /// User ID. - final String userId; - /// Session expiration date in ISO 8601 format. - final String expire; - /// Session Provider. - final String provider; - /// Session Provider User ID. - final String providerUid; - /// Session Provider Access Token. - final String providerAccessToken; - /// The date of when the access token expires in ISO 8601 format. - final String providerAccessTokenExpiry; - /// Session Provider Refresh Token. - final String providerRefreshToken; - /// IP in use when the session was created. - final String ip; - /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). - final String osCode; - /// Operating system name. - final String osName; - /// Operating system version. - final String osVersion; - /// Client type. - final String clientType; - /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). - final String clientCode; - /// Client name. - final String clientName; - /// Client version. - final String clientVersion; - /// Client engine name. - final String clientEngine; - /// Client engine name. - final String clientEngineVersion; - /// Device name. - final String deviceName; - /// Device brand name. - final String deviceBrand; - /// Device model name. - final String deviceModel; - /// Country two-character ISO 3166-1 alpha code. - final String countryCode; - /// Country name. - final String countryName; - /// Returns true if this the current user session. - final bool current; - /// Returns a list of active session factors. - final List factors; - /// Secret used to authenticate the user. Only included if the request was made with an API key - final String secret; - /// Most recent date in ISO 8601 format when the session successfully passed MFA challenge. - final String mfaUpdatedAt; - - Session({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.userId, - required this.expire, - required this.provider, - required this.providerUid, - required this.providerAccessToken, - required this.providerAccessTokenExpiry, - required this.providerRefreshToken, - required this.ip, - required this.osCode, - required this.osName, - required this.osVersion, - required this.clientType, - required this.clientCode, - required this.clientName, - required this.clientVersion, - required this.clientEngine, - required this.clientEngineVersion, - required this.deviceName, - required this.deviceBrand, - required this.deviceModel, - required this.countryCode, - required this.countryName, - required this.current, - required this.factors, - required this.secret, - required this.mfaUpdatedAt, - }); - - factory Session.fromMap(Map map) { - return Session( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - userId: map['userId'].toString(), - expire: map['expire'].toString(), - provider: map['provider'].toString(), - providerUid: map['providerUid'].toString(), - providerAccessToken: map['providerAccessToken'].toString(), - providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), - providerRefreshToken: map['providerRefreshToken'].toString(), - ip: map['ip'].toString(), - osCode: map['osCode'].toString(), - osName: map['osName'].toString(), - osVersion: map['osVersion'].toString(), - clientType: map['clientType'].toString(), - clientCode: map['clientCode'].toString(), - clientName: map['clientName'].toString(), - clientVersion: map['clientVersion'].toString(), - clientEngine: map['clientEngine'].toString(), - clientEngineVersion: map['clientEngineVersion'].toString(), - deviceName: map['deviceName'].toString(), - deviceBrand: map['deviceBrand'].toString(), - deviceModel: map['deviceModel'].toString(), - countryCode: map['countryCode'].toString(), - countryName: map['countryName'].toString(), - current: map['current'], - factors: map['factors'] ?? [], - secret: map['secret'].toString(), - mfaUpdatedAt: map['mfaUpdatedAt'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "userId": userId, - "expire": expire, - "provider": provider, - "providerUid": providerUid, - "providerAccessToken": providerAccessToken, - "providerAccessTokenExpiry": providerAccessTokenExpiry, - "providerRefreshToken": providerRefreshToken, - "ip": ip, - "osCode": osCode, - "osName": osName, - "osVersion": osVersion, - "clientType": clientType, - "clientCode": clientCode, - "clientName": clientName, - "clientVersion": clientVersion, - "clientEngine": clientEngine, - "clientEngineVersion": clientEngineVersion, - "deviceName": deviceName, - "deviceBrand": deviceBrand, - "deviceModel": deviceModel, - "countryCode": countryCode, - "countryName": countryName, - "current": current, - "factors": factors, - "secret": secret, - "mfaUpdatedAt": mfaUpdatedAt, - }; - } + /// Session ID. + final String $id; + + /// Session creation date in ISO 8601 format. + final String $createdAt; + + /// Session update date in ISO 8601 format. + final String $updatedAt; + + /// User ID. + final String userId; + + /// Session expiration date in ISO 8601 format. + final String expire; + + /// Session Provider. + final String provider; + + /// Session Provider User ID. + final String providerUid; + + /// Session Provider Access Token. + final String providerAccessToken; + + /// The date of when the access token expires in ISO 8601 format. + final String providerAccessTokenExpiry; + + /// Session Provider Refresh Token. + final String providerRefreshToken; + + /// IP in use when the session was created. + final String ip; + + /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). + final String osCode; + + /// Operating system name. + final String osName; + + /// Operating system version. + final String osVersion; + + /// Client type. + final String clientType; + + /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). + final String clientCode; + + /// Client name. + final String clientName; + + /// Client version. + final String clientVersion; + + /// Client engine name. + final String clientEngine; + + /// Client engine name. + final String clientEngineVersion; + + /// Device name. + final String deviceName; + + /// Device brand name. + final String deviceBrand; + + /// Device model name. + final String deviceModel; + + /// Country two-character ISO 3166-1 alpha code. + final String countryCode; + + /// Country name. + final String countryName; + + /// Returns true if this the current user session. + final bool current; + + /// Returns a list of active session factors. + final List factors; + + /// Secret used to authenticate the user. Only included if the request was made with an API key + final String secret; + + /// Most recent date in ISO 8601 format when the session successfully passed MFA challenge. + final String mfaUpdatedAt; + + Session({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.userId, + required this.expire, + required this.provider, + required this.providerUid, + required this.providerAccessToken, + required this.providerAccessTokenExpiry, + required this.providerRefreshToken, + required this.ip, + required this.osCode, + required this.osName, + required this.osVersion, + required this.clientType, + required this.clientCode, + required this.clientName, + required this.clientVersion, + required this.clientEngine, + required this.clientEngineVersion, + required this.deviceName, + required this.deviceBrand, + required this.deviceModel, + required this.countryCode, + required this.countryName, + required this.current, + required this.factors, + required this.secret, + required this.mfaUpdatedAt, + }); + + factory Session.fromMap(Map map) { + return Session( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + userId: map['userId'].toString(), + expire: map['expire'].toString(), + provider: map['provider'].toString(), + providerUid: map['providerUid'].toString(), + providerAccessToken: map['providerAccessToken'].toString(), + providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), + providerRefreshToken: map['providerRefreshToken'].toString(), + ip: map['ip'].toString(), + osCode: map['osCode'].toString(), + osName: map['osName'].toString(), + osVersion: map['osVersion'].toString(), + clientType: map['clientType'].toString(), + clientCode: map['clientCode'].toString(), + clientName: map['clientName'].toString(), + clientVersion: map['clientVersion'].toString(), + clientEngine: map['clientEngine'].toString(), + clientEngineVersion: map['clientEngineVersion'].toString(), + deviceName: map['deviceName'].toString(), + deviceBrand: map['deviceBrand'].toString(), + deviceModel: map['deviceModel'].toString(), + countryCode: map['countryCode'].toString(), + countryName: map['countryName'].toString(), + current: map['current'], + factors: map['factors'] ?? [], + secret: map['secret'].toString(), + mfaUpdatedAt: map['mfaUpdatedAt'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "userId": userId, + "expire": expire, + "provider": provider, + "providerUid": providerUid, + "providerAccessToken": providerAccessToken, + "providerAccessTokenExpiry": providerAccessTokenExpiry, + "providerRefreshToken": providerRefreshToken, + "ip": ip, + "osCode": osCode, + "osName": osName, + "osVersion": osVersion, + "clientType": clientType, + "clientCode": clientCode, + "clientName": clientName, + "clientVersion": clientVersion, + "clientEngine": clientEngine, + "clientEngineVersion": clientEngineVersion, + "deviceName": deviceName, + "deviceBrand": deviceBrand, + "deviceModel": deviceModel, + "countryCode": countryCode, + "countryName": countryName, + "current": current, + "factors": factors, + "secret": secret, + "mfaUpdatedAt": mfaUpdatedAt, + }; + } } diff --git a/lib/src/models/session_list.dart b/lib/src/models/session_list.dart index f17b963d..cc1ed114 100644 --- a/lib/src/models/session_list.dart +++ b/lib/src/models/session_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Sessions List class SessionList implements Model { - /// Total number of sessions documents that matched your query. - final int total; - /// List of sessions. - final List sessions; + /// Total number of sessions documents that matched your query. + final int total; - SessionList({ - required this.total, - required this.sessions, - }); + /// List of sessions. + final List sessions; - factory SessionList.fromMap(Map map) { - return SessionList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - sessions: List.from(map['sessions'].map((p) => Session.fromMap(p))), - ); - } + SessionList({ + required this.total, + required this.sessions, + }); - Map toMap() { - return { - "total": total, - "sessions": sessions.map((p) => p.toMap()).toList(), - }; - } + factory SessionList.fromMap(Map map) { + return SessionList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + sessions: + List.from(map['sessions'].map((p) => Session.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "sessions": sessions.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/specification.dart b/lib/src/models/specification.dart index 97b359f2..97e030ee 100644 --- a/lib/src/models/specification.dart +++ b/lib/src/models/specification.dart @@ -2,38 +2,42 @@ part of '../../models.dart'; /// Specification class Specification implements Model { - /// Memory size in MB. - final int memory; - /// Number of CPUs. - final double cpus; - /// Is size enabled. - final bool enabled; - /// Size slug. - final String slug; + /// Memory size in MB. + final int memory; - Specification({ - required this.memory, - required this.cpus, - required this.enabled, - required this.slug, - }); + /// Number of CPUs. + final double cpus; - factory Specification.fromMap(Map map) { - return Specification( - memory: (map['memory'] is String) ? - int.tryParse(map['memory']) ?? 0:map['memory'] ?? 0, - cpus: map['cpus'].toDouble(), - enabled: map['enabled'], - slug: map['slug'].toString(), - ); - } + /// Is size enabled. + final bool enabled; - Map toMap() { - return { - "memory": memory, - "cpus": cpus, - "enabled": enabled, - "slug": slug, - }; - } + /// Size slug. + final String slug; + + Specification({ + required this.memory, + required this.cpus, + required this.enabled, + required this.slug, + }); + + factory Specification.fromMap(Map map) { + return Specification( + memory: (map['memory'] is String) + ? int.tryParse(map['memory']) ?? 0 + : map['memory'] ?? 0, + cpus: map['cpus'].toDouble(), + enabled: map['enabled'], + slug: map['slug'].toString(), + ); + } + + Map toMap() { + return { + "memory": memory, + "cpus": cpus, + "enabled": enabled, + "slug": slug, + }; + } } diff --git a/lib/src/models/specification_list.dart b/lib/src/models/specification_list.dart index 1b7d3a69..9413334e 100644 --- a/lib/src/models/specification_list.dart +++ b/lib/src/models/specification_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Specifications List class SpecificationList implements Model { - /// Total number of specifications documents that matched your query. - final int total; - /// List of specifications. - final List specifications; + /// Total number of specifications documents that matched your query. + final int total; - SpecificationList({ - required this.total, - required this.specifications, - }); + /// List of specifications. + final List specifications; - factory SpecificationList.fromMap(Map map) { - return SpecificationList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - specifications: List.from(map['specifications'].map((p) => Specification.fromMap(p))), - ); - } + SpecificationList({ + required this.total, + required this.specifications, + }); - Map toMap() { - return { - "total": total, - "specifications": specifications.map((p) => p.toMap()).toList(), - }; - } + factory SpecificationList.fromMap(Map map) { + return SpecificationList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + specifications: List.from( + map['specifications'].map((p) => Specification.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "specifications": specifications.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/subscriber.dart b/lib/src/models/subscriber.dart index 97bdb018..0c926297 100644 --- a/lib/src/models/subscriber.dart +++ b/lib/src/models/subscriber.dart @@ -2,62 +2,70 @@ part of '../../models.dart'; /// Subscriber class Subscriber implements Model { - /// Subscriber ID. - final String $id; - /// Subscriber creation time in ISO 8601 format. - final String $createdAt; - /// Subscriber update date in ISO 8601 format. - final String $updatedAt; - /// Target ID. - final String targetId; - /// Target. - final Target target; - /// Topic ID. - final String userId; - /// User Name. - final String userName; - /// Topic ID. - final String topicId; - /// The target provider type. Can be one of the following: `email`, `sms` or `push`. - final String providerType; - - Subscriber({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.targetId, - required this.target, - required this.userId, - required this.userName, - required this.topicId, - required this.providerType, - }); - - factory Subscriber.fromMap(Map map) { - return Subscriber( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - targetId: map['targetId'].toString(), - target: Target.fromMap(map['target']), - userId: map['userId'].toString(), - userName: map['userName'].toString(), - topicId: map['topicId'].toString(), - providerType: map['providerType'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "targetId": targetId, - "target": target.toMap(), - "userId": userId, - "userName": userName, - "topicId": topicId, - "providerType": providerType, - }; - } + /// Subscriber ID. + final String $id; + + /// Subscriber creation time in ISO 8601 format. + final String $createdAt; + + /// Subscriber update date in ISO 8601 format. + final String $updatedAt; + + /// Target ID. + final String targetId; + + /// Target. + final Target target; + + /// Topic ID. + final String userId; + + /// User Name. + final String userName; + + /// Topic ID. + final String topicId; + + /// The target provider type. Can be one of the following: `email`, `sms` or `push`. + final String providerType; + + Subscriber({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.targetId, + required this.target, + required this.userId, + required this.userName, + required this.topicId, + required this.providerType, + }); + + factory Subscriber.fromMap(Map map) { + return Subscriber( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + targetId: map['targetId'].toString(), + target: Target.fromMap(map['target']), + userId: map['userId'].toString(), + userName: map['userName'].toString(), + topicId: map['topicId'].toString(), + providerType: map['providerType'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "targetId": targetId, + "target": target.toMap(), + "userId": userId, + "userName": userName, + "topicId": topicId, + "providerType": providerType, + }; + } } diff --git a/lib/src/models/subscriber_list.dart b/lib/src/models/subscriber_list.dart index dc6724cf..eaed257c 100644 --- a/lib/src/models/subscriber_list.dart +++ b/lib/src/models/subscriber_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Subscriber list class SubscriberList implements Model { - /// Total number of subscribers documents that matched your query. - final int total; - /// List of subscribers. - final List subscribers; + /// Total number of subscribers documents that matched your query. + final int total; - SubscriberList({ - required this.total, - required this.subscribers, - }); + /// List of subscribers. + final List subscribers; - factory SubscriberList.fromMap(Map map) { - return SubscriberList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - subscribers: List.from(map['subscribers'].map((p) => Subscriber.fromMap(p))), - ); - } + SubscriberList({ + required this.total, + required this.subscribers, + }); - Map toMap() { - return { - "total": total, - "subscribers": subscribers.map((p) => p.toMap()).toList(), - }; - } + factory SubscriberList.fromMap(Map map) { + return SubscriberList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + subscribers: List.from( + map['subscribers'].map((p) => Subscriber.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "subscribers": subscribers.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/target.dart b/lib/src/models/target.dart index 50134304..68460126 100644 --- a/lib/src/models/target.dart +++ b/lib/src/models/target.dart @@ -2,57 +2,64 @@ part of '../../models.dart'; /// Target class Target implements Model { - /// Target ID. - final String $id; - /// Target creation time in ISO 8601 format. - final String $createdAt; - /// Target update date in ISO 8601 format. - final String $updatedAt; - /// Target Name. - final String name; - /// User ID. - final String userId; - /// Provider ID. - final String? providerId; - /// The target provider type. Can be one of the following: `email`, `sms` or `push`. - final String providerType; - /// The target identifier. - final String identifier; - - Target({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.userId, - this.providerId, - required this.providerType, - required this.identifier, - }); - - factory Target.fromMap(Map map) { - return Target( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - userId: map['userId'].toString(), - providerId: map['providerId']?.toString(), - providerType: map['providerType'].toString(), - identifier: map['identifier'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "userId": userId, - "providerId": providerId, - "providerType": providerType, - "identifier": identifier, - }; - } + /// Target ID. + final String $id; + + /// Target creation time in ISO 8601 format. + final String $createdAt; + + /// Target update date in ISO 8601 format. + final String $updatedAt; + + /// Target Name. + final String name; + + /// User ID. + final String userId; + + /// Provider ID. + final String? providerId; + + /// The target provider type. Can be one of the following: `email`, `sms` or `push`. + final String providerType; + + /// The target identifier. + final String identifier; + + Target({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.userId, + this.providerId, + required this.providerType, + required this.identifier, + }); + + factory Target.fromMap(Map map) { + return Target( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + userId: map['userId'].toString(), + providerId: map['providerId']?.toString(), + providerType: map['providerType'].toString(), + identifier: map['identifier'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "userId": userId, + "providerId": providerId, + "providerType": providerType, + "identifier": identifier, + }; + } } diff --git a/lib/src/models/target_list.dart b/lib/src/models/target_list.dart index bc859bee..4cdcf666 100644 --- a/lib/src/models/target_list.dart +++ b/lib/src/models/target_list.dart @@ -2,28 +2,30 @@ part of '../../models.dart'; /// Target list class TargetList implements Model { - /// Total number of targets documents that matched your query. - final int total; - /// List of targets. - final List targets; + /// Total number of targets documents that matched your query. + final int total; - TargetList({ - required this.total, - required this.targets, - }); + /// List of targets. + final List targets; - factory TargetList.fromMap(Map map) { - return TargetList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - targets: List.from(map['targets'].map((p) => Target.fromMap(p))), - ); - } + TargetList({ + required this.total, + required this.targets, + }); - Map toMap() { - return { - "total": total, - "targets": targets.map((p) => p.toMap()).toList(), - }; - } + factory TargetList.fromMap(Map map) { + return TargetList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + targets: List.from(map['targets'].map((p) => Target.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "targets": targets.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/team.dart b/lib/src/models/team.dart index 118be8dd..8f9bece6 100644 --- a/lib/src/models/team.dart +++ b/lib/src/models/team.dart @@ -2,48 +2,54 @@ part of '../../models.dart'; /// Team class Team implements Model { - /// Team ID. - final String $id; - /// Team creation date in ISO 8601 format. - final String $createdAt; - /// Team update date in ISO 8601 format. - final String $updatedAt; - /// Team name. - final String name; - /// Total number of team members. - final int total; - /// Team preferences as a key-value object - final Preferences prefs; - - Team({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.total, - required this.prefs, - }); - - factory Team.fromMap(Map map) { - return Team( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - prefs: Preferences.fromMap(map['prefs']), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "total": total, - "prefs": prefs.toMap(), - }; - } + /// Team ID. + final String $id; + + /// Team creation date in ISO 8601 format. + final String $createdAt; + + /// Team update date in ISO 8601 format. + final String $updatedAt; + + /// Team name. + final String name; + + /// Total number of team members. + final int total; + + /// Team preferences as a key-value object + final Preferences prefs; + + Team({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.total, + required this.prefs, + }); + + factory Team.fromMap(Map map) { + return Team( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + prefs: Preferences.fromMap(map['prefs']), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "total": total, + "prefs": prefs.toMap(), + }; + } } diff --git a/lib/src/models/team_list.dart b/lib/src/models/team_list.dart index f011ce95..a4dfe204 100644 --- a/lib/src/models/team_list.dart +++ b/lib/src/models/team_list.dart @@ -2,28 +2,30 @@ part of '../../models.dart'; /// Teams List class TeamList implements Model { - /// Total number of teams documents that matched your query. - final int total; - /// List of teams. - final List teams; + /// Total number of teams documents that matched your query. + final int total; - TeamList({ - required this.total, - required this.teams, - }); + /// List of teams. + final List teams; - factory TeamList.fromMap(Map map) { - return TeamList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - teams: List.from(map['teams'].map((p) => Team.fromMap(p))), - ); - } + TeamList({ + required this.total, + required this.teams, + }); - Map toMap() { - return { - "total": total, - "teams": teams.map((p) => p.toMap()).toList(), - }; - } + factory TeamList.fromMap(Map map) { + return TeamList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + teams: List.from(map['teams'].map((p) => Team.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "teams": teams.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/token.dart b/lib/src/models/token.dart index 217006c0..35115467 100644 --- a/lib/src/models/token.dart +++ b/lib/src/models/token.dart @@ -2,47 +2,52 @@ part of '../../models.dart'; /// Token class Token implements Model { - /// Token ID. - final String $id; - /// Token creation date in ISO 8601 format. - final String $createdAt; - /// User ID. - final String userId; - /// Token secret key. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. - final String secret; - /// Token expiration date in ISO 8601 format. - final String expire; - /// Security phrase of a token. Empty if security phrase was not requested when creating a token. It includes randomly generated phrase which is also sent in the external resource such as email. - final String phrase; - - Token({ - required this.$id, - required this.$createdAt, - required this.userId, - required this.secret, - required this.expire, - required this.phrase, - }); - - factory Token.fromMap(Map map) { - return Token( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - userId: map['userId'].toString(), - secret: map['secret'].toString(), - expire: map['expire'].toString(), - phrase: map['phrase'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "userId": userId, - "secret": secret, - "expire": expire, - "phrase": phrase, - }; - } + /// Token ID. + final String $id; + + /// Token creation date in ISO 8601 format. + final String $createdAt; + + /// User ID. + final String userId; + + /// Token secret key. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. + final String secret; + + /// Token expiration date in ISO 8601 format. + final String expire; + + /// Security phrase of a token. Empty if security phrase was not requested when creating a token. It includes randomly generated phrase which is also sent in the external resource such as email. + final String phrase; + + Token({ + required this.$id, + required this.$createdAt, + required this.userId, + required this.secret, + required this.expire, + required this.phrase, + }); + + factory Token.fromMap(Map map) { + return Token( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + userId: map['userId'].toString(), + secret: map['secret'].toString(), + expire: map['expire'].toString(), + phrase: map['phrase'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "userId": userId, + "secret": secret, + "expire": expire, + "phrase": phrase, + }; + } } diff --git a/lib/src/models/topic.dart b/lib/src/models/topic.dart index bb9ddc3f..8410de02 100644 --- a/lib/src/models/topic.dart +++ b/lib/src/models/topic.dart @@ -2,60 +2,70 @@ part of '../../models.dart'; /// Topic class Topic implements Model { - /// Topic ID. - final String $id; - /// Topic creation time in ISO 8601 format. - final String $createdAt; - /// Topic update date in ISO 8601 format. - final String $updatedAt; - /// The name of the topic. - final String name; - /// Total count of email subscribers subscribed to the topic. - final int emailTotal; - /// Total count of SMS subscribers subscribed to the topic. - final int smsTotal; - /// Total count of push subscribers subscribed to the topic. - final int pushTotal; - /// Subscribe permissions. - final List subscribe; - - Topic({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.emailTotal, - required this.smsTotal, - required this.pushTotal, - required this.subscribe, - }); - - factory Topic.fromMap(Map map) { - return Topic( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - emailTotal: (map['emailTotal'] is String) ? - int.tryParse(map['emailTotal']) ?? 0:map['emailTotal'] ?? 0, - smsTotal: (map['smsTotal'] is String) ? - int.tryParse(map['smsTotal']) ?? 0:map['smsTotal'] ?? 0, - pushTotal: (map['pushTotal'] is String) ? - int.tryParse(map['pushTotal']) ?? 0:map['pushTotal'] ?? 0, - subscribe: map['subscribe'] ?? [], - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "emailTotal": emailTotal, - "smsTotal": smsTotal, - "pushTotal": pushTotal, - "subscribe": subscribe, - }; - } + /// Topic ID. + final String $id; + + /// Topic creation time in ISO 8601 format. + final String $createdAt; + + /// Topic update date in ISO 8601 format. + final String $updatedAt; + + /// The name of the topic. + final String name; + + /// Total count of email subscribers subscribed to the topic. + final int emailTotal; + + /// Total count of SMS subscribers subscribed to the topic. + final int smsTotal; + + /// Total count of push subscribers subscribed to the topic. + final int pushTotal; + + /// Subscribe permissions. + final List subscribe; + + Topic({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.emailTotal, + required this.smsTotal, + required this.pushTotal, + required this.subscribe, + }); + + factory Topic.fromMap(Map map) { + return Topic( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + emailTotal: (map['emailTotal'] is String) + ? int.tryParse(map['emailTotal']) ?? 0 + : map['emailTotal'] ?? 0, + smsTotal: (map['smsTotal'] is String) + ? int.tryParse(map['smsTotal']) ?? 0 + : map['smsTotal'] ?? 0, + pushTotal: (map['pushTotal'] is String) + ? int.tryParse(map['pushTotal']) ?? 0 + : map['pushTotal'] ?? 0, + subscribe: map['subscribe'] ?? [], + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "emailTotal": emailTotal, + "smsTotal": smsTotal, + "pushTotal": pushTotal, + "subscribe": subscribe, + }; + } } diff --git a/lib/src/models/topic_list.dart b/lib/src/models/topic_list.dart index 64e6598f..bc474b61 100644 --- a/lib/src/models/topic_list.dart +++ b/lib/src/models/topic_list.dart @@ -2,28 +2,30 @@ part of '../../models.dart'; /// Topic list class TopicList implements Model { - /// Total number of topics documents that matched your query. - final int total; - /// List of topics. - final List topics; + /// Total number of topics documents that matched your query. + final int total; - TopicList({ - required this.total, - required this.topics, - }); + /// List of topics. + final List topics; - factory TopicList.fromMap(Map map) { - return TopicList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - topics: List.from(map['topics'].map((p) => Topic.fromMap(p))), - ); - } + TopicList({ + required this.total, + required this.topics, + }); - Map toMap() { - return { - "total": total, - "topics": topics.map((p) => p.toMap()).toList(), - }; - } + factory TopicList.fromMap(Map map) { + return TopicList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + topics: List.from(map['topics'].map((p) => Topic.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "topics": topics.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/user.dart b/lib/src/models/user.dart index 5937ff55..889005cf 100644 --- a/lib/src/models/user.dart +++ b/lib/src/models/user.dart @@ -2,112 +2,130 @@ part of '../../models.dart'; /// User class User implements Model { - /// User ID. - final String $id; - /// User creation date in ISO 8601 format. - final String $createdAt; - /// User update date in ISO 8601 format. - final String $updatedAt; - /// User name. - final String name; - /// Hashed user password. - final String? password; - /// Password hashing algorithm. - final String? hash; - /// Password hashing algorithm configuration. - final Map? hashOptions; - /// User registration date in ISO 8601 format. - final String registration; - /// User status. Pass `true` for enabled and `false` for disabled. - final bool status; - /// Labels for the user. - final List labels; - /// Password update time in ISO 8601 format. - final String passwordUpdate; - /// User email address. - final String email; - /// User phone number in E.164 format. - final String phone; - /// Email verification status. - final bool emailVerification; - /// Phone verification status. - final bool phoneVerification; - /// Multi factor authentication status. - final bool mfa; - /// User preferences as a key-value object - final Preferences prefs; - /// A user-owned message receiver. A single user may have multiple e.g. emails, phones, and a browser. Each target is registered with a single provider. - final List targets; - /// Most recent access date in ISO 8601 format. This attribute is only updated again after 24 hours. - final String accessedAt; - - User({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - this.password, - this.hash, - this.hashOptions, - required this.registration, - required this.status, - required this.labels, - required this.passwordUpdate, - required this.email, - required this.phone, - required this.emailVerification, - required this.phoneVerification, - required this.mfa, - required this.prefs, - required this.targets, - required this.accessedAt, - }); - - factory User.fromMap(Map map) { - return User( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - password: map['password']?.toString(), - hash: map['hash']?.toString(), - hashOptions: map['hashOptions'], - registration: map['registration'].toString(), - status: map['status'], - labels: map['labels'] ?? [], - passwordUpdate: map['passwordUpdate'].toString(), - email: map['email'].toString(), - phone: map['phone'].toString(), - emailVerification: map['emailVerification'], - phoneVerification: map['phoneVerification'], - mfa: map['mfa'], - prefs: Preferences.fromMap(map['prefs']), - targets: List.from(map['targets'].map((p) => Target.fromMap(p))), - accessedAt: map['accessedAt'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "password": password, - "hash": hash, - "hashOptions": hashOptions, - "registration": registration, - "status": status, - "labels": labels, - "passwordUpdate": passwordUpdate, - "email": email, - "phone": phone, - "emailVerification": emailVerification, - "phoneVerification": phoneVerification, - "mfa": mfa, - "prefs": prefs.toMap(), - "targets": targets.map((p) => p.toMap()).toList(), - "accessedAt": accessedAt, - }; - } + /// User ID. + final String $id; + + /// User creation date in ISO 8601 format. + final String $createdAt; + + /// User update date in ISO 8601 format. + final String $updatedAt; + + /// User name. + final String name; + + /// Hashed user password. + final String? password; + + /// Password hashing algorithm. + final String? hash; + + /// Password hashing algorithm configuration. + final Map? hashOptions; + + /// User registration date in ISO 8601 format. + final String registration; + + /// User status. Pass `true` for enabled and `false` for disabled. + final bool status; + + /// Labels for the user. + final List labels; + + /// Password update time in ISO 8601 format. + final String passwordUpdate; + + /// User email address. + final String email; + + /// User phone number in E.164 format. + final String phone; + + /// Email verification status. + final bool emailVerification; + + /// Phone verification status. + final bool phoneVerification; + + /// Multi factor authentication status. + final bool mfa; + + /// User preferences as a key-value object + final Preferences prefs; + + /// A user-owned message receiver. A single user may have multiple e.g. emails, phones, and a browser. Each target is registered with a single provider. + final List targets; + + /// Most recent access date in ISO 8601 format. This attribute is only updated again after 24 hours. + final String accessedAt; + + User({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + this.password, + this.hash, + this.hashOptions, + required this.registration, + required this.status, + required this.labels, + required this.passwordUpdate, + required this.email, + required this.phone, + required this.emailVerification, + required this.phoneVerification, + required this.mfa, + required this.prefs, + required this.targets, + required this.accessedAt, + }); + + factory User.fromMap(Map map) { + return User( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + password: map['password']?.toString(), + hash: map['hash']?.toString(), + hashOptions: map['hashOptions'], + registration: map['registration'].toString(), + status: map['status'], + labels: map['labels'] ?? [], + passwordUpdate: map['passwordUpdate'].toString(), + email: map['email'].toString(), + phone: map['phone'].toString(), + emailVerification: map['emailVerification'], + phoneVerification: map['phoneVerification'], + mfa: map['mfa'], + prefs: Preferences.fromMap(map['prefs']), + targets: List.from(map['targets'].map((p) => Target.fromMap(p))), + accessedAt: map['accessedAt'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "password": password, + "hash": hash, + "hashOptions": hashOptions, + "registration": registration, + "status": status, + "labels": labels, + "passwordUpdate": passwordUpdate, + "email": email, + "phone": phone, + "emailVerification": emailVerification, + "phoneVerification": phoneVerification, + "mfa": mfa, + "prefs": prefs.toMap(), + "targets": targets.map((p) => p.toMap()).toList(), + "accessedAt": accessedAt, + }; + } } diff --git a/lib/src/models/user_list.dart b/lib/src/models/user_list.dart index 92d926b0..c6d26cfe 100644 --- a/lib/src/models/user_list.dart +++ b/lib/src/models/user_list.dart @@ -2,28 +2,30 @@ part of '../../models.dart'; /// Users List class UserList implements Model { - /// Total number of users documents that matched your query. - final int total; - /// List of users. - final List users; + /// Total number of users documents that matched your query. + final int total; - UserList({ - required this.total, - required this.users, - }); + /// List of users. + final List users; - factory UserList.fromMap(Map map) { - return UserList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - users: List.from(map['users'].map((p) => User.fromMap(p))), - ); - } + UserList({ + required this.total, + required this.users, + }); - Map toMap() { - return { - "total": total, - "users": users.map((p) => p.toMap()).toList(), - }; - } + factory UserList.fromMap(Map map) { + return UserList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + users: List.from(map['users'].map((p) => User.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "users": users.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/variable.dart b/lib/src/models/variable.dart index 83526877..a233010a 100644 --- a/lib/src/models/variable.dart +++ b/lib/src/models/variable.dart @@ -2,52 +2,58 @@ part of '../../models.dart'; /// Variable class Variable implements Model { - /// Variable ID. - final String $id; - /// Variable creation date in ISO 8601 format. - final String $createdAt; - /// Variable creation date in ISO 8601 format. - final String $updatedAt; - /// Variable key. - final String key; - /// Variable value. - final String value; - /// Service to which the variable belongs. Possible values are "project", "function" - final String resourceType; - /// ID of resource to which the variable belongs. If resourceType is "project", it is empty. If resourceType is "function", it is ID of the function. - final String resourceId; - - Variable({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.key, - required this.value, - required this.resourceType, - required this.resourceId, - }); - - factory Variable.fromMap(Map map) { - return Variable( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - key: map['key'].toString(), - value: map['value'].toString(), - resourceType: map['resourceType'].toString(), - resourceId: map['resourceId'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "key": key, - "value": value, - "resourceType": resourceType, - "resourceId": resourceId, - }; - } + /// Variable ID. + final String $id; + + /// Variable creation date in ISO 8601 format. + final String $createdAt; + + /// Variable creation date in ISO 8601 format. + final String $updatedAt; + + /// Variable key. + final String key; + + /// Variable value. + final String value; + + /// Service to which the variable belongs. Possible values are "project", "function" + final String resourceType; + + /// ID of resource to which the variable belongs. If resourceType is "project", it is empty. If resourceType is "function", it is ID of the function. + final String resourceId; + + Variable({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.key, + required this.value, + required this.resourceType, + required this.resourceId, + }); + + factory Variable.fromMap(Map map) { + return Variable( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + key: map['key'].toString(), + value: map['value'].toString(), + resourceType: map['resourceType'].toString(), + resourceId: map['resourceId'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "key": key, + "value": value, + "resourceType": resourceType, + "resourceId": resourceId, + }; + } } diff --git a/lib/src/models/variable_list.dart b/lib/src/models/variable_list.dart index 6883a928..07f2b2c4 100644 --- a/lib/src/models/variable_list.dart +++ b/lib/src/models/variable_list.dart @@ -2,28 +2,31 @@ part of '../../models.dart'; /// Variables List class VariableList implements Model { - /// Total number of variables documents that matched your query. - final int total; - /// List of variables. - final List variables; + /// Total number of variables documents that matched your query. + final int total; - VariableList({ - required this.total, - required this.variables, - }); + /// List of variables. + final List variables; - factory VariableList.fromMap(Map map) { - return VariableList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, - variables: List.from(map['variables'].map((p) => Variable.fromMap(p))), - ); - } + VariableList({ + required this.total, + required this.variables, + }); - Map toMap() { - return { - "total": total, - "variables": variables.map((p) => p.toMap()).toList(), - }; - } + factory VariableList.fromMap(Map map) { + return VariableList( + total: (map['total'] is String) + ? int.tryParse(map['total']) ?? 0 + : map['total'] ?? 0, + variables: + List.from(map['variables'].map((p) => Variable.fromMap(p))), + ); + } + + Map toMap() { + return { + "total": total, + "variables": variables.map((p) => p.toMap()).toList(), + }; + } } From 9d595674acc890cd0d2e5478d60ec0ae5692d4c4 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 1 Oct 2024 21:29:14 +0100 Subject: [PATCH 3/7] fix: multipart testing --- README.md | 2 +- lib/client_browser.dart | 2 +- lib/client_io.dart | 2 +- lib/dart_appwrite.dart | 2 +- lib/id.dart | 3 +- lib/payload.dart | 16 +- lib/query.dart | 45 +- lib/role.dart | 106 +- lib/services/account.dart | 2243 +++++++++-------- lib/services/avatars.dart | 404 ++- lib/services/databases.dart | 2367 ++++++++---------- lib/services/functions.dart | 1263 +++++----- lib/services/graphql.dart | 94 +- lib/services/health.dart | 929 +++---- lib/services/locale.dart | 270 +- lib/services/messaging.dart | 2619 ++++++++++---------- lib/services/storage.dart | 732 +++--- lib/services/teams.dart | 684 ++--- lib/services/users.dart | 2072 ++++++++-------- lib/src/client.dart | 7 +- lib/src/client_base.dart | 6 +- lib/src/client_browser.dart | 103 +- lib/src/client_io.dart | 103 +- lib/src/client_mixin.dart | 49 +- lib/src/enums/authentication_factor.dart | 18 +- lib/src/enums/authenticator_type.dart | 12 +- lib/src/enums/browser.dart | 38 +- lib/src/enums/compression.dart | 16 +- lib/src/enums/credit_card.dart | 42 +- lib/src/enums/execution_method.dart | 22 +- lib/src/enums/flag.dart | 400 +-- lib/src/enums/image_format.dart | 20 +- lib/src/enums/image_gravity.dart | 28 +- lib/src/enums/index_type.dart | 16 +- lib/src/enums/messaging_provider_type.dart | 16 +- lib/src/enums/name.dart | 34 +- lib/src/enums/o_auth_provider.dart | 88 +- lib/src/enums/password_hash.dart | 32 +- lib/src/enums/relation_mutate.dart | 16 +- lib/src/enums/relationship_type.dart | 18 +- lib/src/enums/runtime.dart | 108 +- lib/src/enums/smtp_encryption.dart | 16 +- lib/src/exception.dart | 2 +- lib/src/models/algo_argon2.dart | 72 +- lib/src/models/algo_bcrypt.dart | 30 +- lib/src/models/algo_md5.dart | 30 +- lib/src/models/algo_phpass.dart | 30 +- lib/src/models/algo_scrypt.dart | 92 +- lib/src/models/algo_scrypt_modified.dart | 63 +- lib/src/models/algo_sha.dart | 30 +- lib/src/models/attribute_boolean.dart | 102 +- lib/src/models/attribute_datetime.dart | 113 +- lib/src/models/attribute_email.dart | 113 +- lib/src/models/attribute_enum.dart | 124 +- lib/src/models/attribute_float.dart | 124 +- lib/src/models/attribute_integer.dart | 123 +- lib/src/models/attribute_ip.dart | 113 +- lib/src/models/attribute_list.dart | 44 +- lib/src/models/attribute_relationship.dart | 151 +- lib/src/models/attribute_string.dart | 116 +- lib/src/models/attribute_url.dart | 113 +- lib/src/models/bucket.dart | 154 +- lib/src/models/bucket_list.dart | 44 +- lib/src/models/build.dart | 124 +- lib/src/models/collection.dart | 129 +- lib/src/models/collection_list.dart | 45 +- lib/src/models/continent.dart | 41 +- lib/src/models/continent_list.dart | 45 +- lib/src/models/country.dart | 41 +- lib/src/models/country_list.dart | 45 +- lib/src/models/currency.dart | 105 +- lib/src/models/currency_list.dart | 45 +- lib/src/models/database.dart | 80 +- lib/src/models/database_list.dart | 45 +- lib/src/models/deployment.dart | 298 +-- lib/src/models/deployment_list.dart | 45 +- lib/src/models/document.dart | 103 +- lib/src/models/document_list.dart | 49 +- lib/src/models/execution.dart | 217 +- lib/src/models/execution_list.dart | 45 +- lib/src/models/file.dart | 149 +- lib/src/models/file_list.dart | 44 +- lib/src/models/function.dart | 292 +-- lib/src/models/function_list.dart | 44 +- lib/src/models/headers.dart | 41 +- lib/src/models/health_antivirus.dart | 41 +- lib/src/models/health_certificate.dart | 91 +- lib/src/models/health_queue.dart | 33 +- lib/src/models/health_status.dart | 55 +- lib/src/models/health_time.dart | 61 +- lib/src/models/identity.dart | 129 +- lib/src/models/identity_list.dart | 45 +- lib/src/models/index.dart | 91 +- lib/src/models/index_list.dart | 44 +- lib/src/models/jwt.dart | 30 +- lib/src/models/language.dart | 52 +- lib/src/models/language_list.dart | 45 +- lib/src/models/locale.dart | 102 +- lib/src/models/locale_code.dart | 41 +- lib/src/models/locale_code_list.dart | 45 +- lib/src/models/log.dart | 256 +- lib/src/models/log_list.dart | 44 +- lib/src/models/membership.dart | 168 +- lib/src/models/membership_list.dart | 45 +- lib/src/models/message.dart | 171 +- lib/src/models/message_list.dart | 45 +- lib/src/models/mfa_challenge.dart | 63 +- lib/src/models/mfa_factors.dart | 63 +- lib/src/models/mfa_recovery_codes.dart | 30 +- lib/src/models/mfa_type.dart | 41 +- lib/src/models/model.dart | 2 +- lib/src/models/phone.dart | 52 +- lib/src/models/phone_list.dart | 44 +- lib/src/models/preferences.dart | 30 +- lib/src/models/provider.dart | 124 +- lib/src/models/provider_list.dart | 45 +- lib/src/models/runtime.dart | 113 +- lib/src/models/runtime_list.dart | 45 +- lib/src/models/session.dart | 344 ++- lib/src/models/session_list.dart | 45 +- lib/src/models/specification.dart | 66 +- lib/src/models/specification_list.dart | 45 +- lib/src/models/subscriber.dart | 124 +- lib/src/models/subscriber_list.dart | 45 +- lib/src/models/target.dart | 113 +- lib/src/models/target_list.dart | 44 +- lib/src/models/team.dart | 94 +- lib/src/models/team_list.dart | 44 +- lib/src/models/token.dart | 91 +- lib/src/models/topic.dart | 122 +- lib/src/models/topic_list.dart | 44 +- lib/src/models/user.dart | 234 +- lib/src/models/user_list.dart | 44 +- lib/src/models/variable.dart | 102 +- lib/src/models/variable_list.dart | 45 +- pubspec.yaml | 2 +- test/services/functions_test.dart | 4 +- test/src/models/execution_test.dart | 4 +- 138 files changed, 11127 insertions(+), 11733 deletions(-) diff --git a/README.md b/README.md index 770c67fa..c1ab7d9f 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Add this to your package's `pubspec.yaml` file: ```yml dependencies: - dart_appwrite: ^13.0.0-rc1 + dart_appwrite: ^13.0.0 ``` You can install packages from the command line: diff --git a/lib/client_browser.dart b/lib/client_browser.dart index b9805a3a..09f110ea 100644 --- a/lib/client_browser.dart +++ b/lib/client_browser.dart @@ -1 +1 @@ -export 'src/client_browser.dart'; +export 'src/client_browser.dart'; \ No newline at end of file diff --git a/lib/client_io.dart b/lib/client_io.dart index 42a0c0b6..4d85cbfa 100644 --- a/lib/client_io.dart +++ b/lib/client_io.dart @@ -1 +1 @@ -export 'src/client_io.dart'; +export 'src/client_io.dart'; \ No newline at end of file diff --git a/lib/dart_appwrite.dart b/lib/dart_appwrite.dart index 6e1a5f10..659eb962 100644 --- a/lib/dart_appwrite.dart +++ b/lib/dart_appwrite.dart @@ -1,6 +1,6 @@ /// Appwrite Dart SDK /// -/// This SDK is compatible with Appwrite server version 1.6.x. +/// This SDK is compatible with Appwrite server version 1.6.x. /// For older versions, please check /// [previous releases](https://github.com/appwrite/sdk-for-dart/releases). library dart_appwrite; diff --git a/lib/id.dart b/lib/id.dart index 28ff15e8..72e26a23 100644 --- a/lib/id.dart +++ b/lib/id.dart @@ -10,7 +10,8 @@ class ID { final now = DateTime.now(); final sec = (now.millisecondsSinceEpoch / 1000).floor(); final usec = now.microsecondsSinceEpoch - (sec * 1000000); - return sec.toRadixString(16) + usec.toRadixString(16).padLeft(5, '0'); + return sec.toRadixString(16) + + usec.toRadixString(16).padLeft(5, '0'); } // Generate a unique ID with padding to have a longer ID diff --git a/lib/payload.dart b/lib/payload.dart index fec52b0d..7afcd2a8 100644 --- a/lib/payload.dart +++ b/lib/payload.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'src/exception.dart'; +import 'dart:io'; class Payload { late final String? path; @@ -14,10 +15,10 @@ class Payload { /// Convert to binary, with optional offset and length List toBinary({int offset = 0, int? length}) { - if (data == null) { + if(data == null) { throw AppwriteException('`data` is not defined.'); } - if (offset == 0 && length == null) { + if(offset == 0 && length == null) { return data!; } else if (length == null) { return data!.sublist(offset); @@ -29,7 +30,7 @@ class Payload { /// Convert binary data to string (utf8) @override String toString() { - if (data == null) { + if(data == null) { return ''; } return utf8.decode(data!); @@ -44,6 +45,15 @@ class Payload { } } + /// Create a file from the payload + void toFile(String path) { + if(data == null) { + throw AppwriteException('`data` is not defined.'); + } + final file = File(path); + file.writeAsBytesSync(data!); + } + /// Create a Payload from binary data factory Payload.fromBinary({ required List data, diff --git a/lib/query.dart b/lib/query.dart index 6b8ed94f..46882207 100644 --- a/lib/query.dart +++ b/lib/query.dart @@ -1,5 +1,6 @@ part of 'dart_appwrite.dart'; + /// Helper class to generate query strings. class Query { final String method; @@ -13,11 +14,11 @@ class Query { 'method': method, }; - if (attribute != null) { + if(attribute != null) { map['attribute'] = attribute; } - - if (values != null) { + + if(values != null) { map['values'] = values is List ? values : [values]; } @@ -28,7 +29,7 @@ class Query { String toString() => jsonEncode(toJson()); /// Filter resources where [attribute] is equal to [value]. - /// + /// /// [value] can be a single value or a list. If a list is used /// the query will return resources where [attribute] is equal /// to any of the values in the list. @@ -60,12 +61,10 @@ class Query { Query._('search', attribute, value).toString(); /// Filter resources where [attribute] is null. - static String isNull(String attribute) => - Query._('isNull', attribute).toString(); + static String isNull(String attribute) => Query._('isNull', attribute).toString(); /// Filter resources where [attribute] is not null. - static String isNotNull(String attribute) => - Query._('isNotNull', attribute).toString(); + static String isNotNull(String attribute) => Query._('isNotNull', attribute).toString(); /// Filter resources where [attribute] is between [start] and [end] (inclusive). static String between(String attribute, dynamic start, dynamic end) => @@ -85,46 +84,40 @@ class Query { Query._('contains', attribute, value).toString(); static String or(List queries) => - Query._('or', null, queries.map((query) => jsonDecode(query)).toList()) - .toString(); + Query._('or', null, queries.map((query) => jsonDecode(query)).toList()).toString(); static String and(List queries) => - Query._('and', null, queries.map((query) => jsonDecode(query)).toList()) - .toString(); + Query._('and', null, queries.map((query) => jsonDecode(query)).toList()).toString(); /// Specify which attributes should be returned by the API call. static String select(List attributes) => Query._('select', null, attributes).toString(); /// Sort results by [attribute] ascending. - static String orderAsc(String attribute) => - Query._('orderAsc', attribute).toString(); + static String orderAsc(String attribute) => Query._('orderAsc', attribute).toString(); /// Sort results by [attribute] descending. - static String orderDesc(String attribute) => - Query._('orderDesc', attribute).toString(); + static String orderDesc(String attribute) => Query._('orderDesc', attribute).toString(); /// Return results before [id]. - /// + /// /// Refer to the [Cursor Based Pagination](https://appwrite.io/docs/pagination#cursor-pagination) /// docs for more information. - static String cursorBefore(String id) => - Query._('cursorBefore', null, id).toString(); + static String cursorBefore(String id) => Query._('cursorBefore', null, id).toString(); /// Return results after [id]. - /// + /// /// Refer to the [Cursor Based Pagination](https://appwrite.io/docs/pagination#cursor-pagination) /// docs for more information. - static String cursorAfter(String id) => - Query._('cursorAfter', null, id).toString(); + static String cursorAfter(String id) => Query._('cursorAfter', null, id).toString(); /// Return only [limit] results. static String limit(int limit) => Query._('limit', null, limit).toString(); /// Return results from [offset]. - /// + /// /// Refer to the [Offset Pagination](https://appwrite.io/docs/pagination#offset-pagination) /// docs for more information. - static String offset(int offset) => - Query._('offset', null, offset).toString(); -} + static String offset(int offset) => Query._('offset', null, offset).toString(); + +} \ No newline at end of file diff --git a/lib/role.dart b/lib/role.dart index dafeb78d..6552df47 100644 --- a/lib/role.dart +++ b/lib/role.dart @@ -2,65 +2,65 @@ part of 'dart_appwrite.dart'; /// Helper class to generate role strings for [Permission]. class Role { - Role._(); - - /// Grants access to anyone. - /// - /// This includes authenticated and unauthenticated users. - static String any() { - return 'any'; - } + Role._(); + + /// Grants access to anyone. + /// + /// This includes authenticated and unauthenticated users. + static String any() { + return 'any'; + } - /// Grants access to a specific user by user ID. - /// - /// You can optionally pass verified or unverified for - /// [status] to target specific types of users. - static String user(String id, [String status = '']) { - if (status.isEmpty) { - return 'user:$id'; + /// Grants access to a specific user by user ID. + /// + /// You can optionally pass verified or unverified for + /// [status] to target specific types of users. + static String user(String id, [String status = '']) { + if(status.isEmpty) { + return 'user:$id'; + } + return 'user:$id/$status'; } - return 'user:$id/$status'; - } - /// Grants access to any authenticated or anonymous user. - /// - /// You can optionally pass verified or unverified for - /// [status] to target specific types of users. - static String users([String status = '']) { - if (status.isEmpty) { - return 'users'; + /// Grants access to any authenticated or anonymous user. + /// + /// You can optionally pass verified or unverified for + /// [status] to target specific types of users. + static String users([String status = '']) { + if(status.isEmpty) { + return 'users'; + } + return 'users/$status'; } - return 'users/$status'; - } - /// Grants access to any guest user without a session. - /// - /// Authenticated users don't have access to this role. - static String guests() { - return 'guests'; - } + /// Grants access to any guest user without a session. + /// + /// Authenticated users don't have access to this role. + static String guests() { + return 'guests'; + } - /// Grants access to a team by team ID. - /// - /// You can optionally pass a role for [role] to target - /// team members with the specified role. - static String team(String id, [String role = '']) { - if (role.isEmpty) { - return 'team:$id'; + /// Grants access to a team by team ID. + /// + /// You can optionally pass a role for [role] to target + /// team members with the specified role. + static String team(String id, [String role = '']) { + if(role.isEmpty) { + return 'team:$id'; + } + return 'team:$id/$role'; } - return 'team:$id/$role'; - } - /// Grants access to a specific member of a team. - /// - /// When the member is removed from the team, they will - /// no longer have access. - static String member(String id) { - return 'member:$id'; - } + /// Grants access to a specific member of a team. + /// + /// When the member is removed from the team, they will + /// no longer have access. + static String member(String id) { + return 'member:$id'; + } - /// Grants access to a user with the specified label. - static String label(String name) { - return 'label:$name'; - } -} + /// Grants access to a user with the specified label. + static String label(String name) { + return 'label:$name'; + } +} \ No newline at end of file diff --git a/lib/services/account.dart b/lib/services/account.dart index 6e4936cd..a6e5d6a6 100644 --- a/lib/services/account.dart +++ b/lib/services/account.dart @@ -2,1072 +2,1177 @@ part of '../dart_appwrite.dart'; /// The Account service allows you to authenticate and manage a user account. class Account extends Service { - Account(super.client); - - /// Get account - /// - /// Get the currently logged in user. - Future get() async { - final String apiPath = '/account'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.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](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession). - Future create( - {required String userId, - required String email, - required String password, - String? name}) async { - final String apiPath = '/account'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update 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 { - final String apiPath = '/account/email'; - - final Map apiParams = { - 'email': email, - 'password': password, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// List Identities - /// - /// Get the list of identities for the currently logged in user. - Future listIdentities({List? queries}) async { - final String apiPath = '/account/identities'; - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.IdentityList.fromMap(res.data); - } - - /// Delete identity - /// - /// Delete an identity by its unique ID. - Future deleteIdentity({required String identityId}) async { - final String apiPath = '/account/identities/{identityId}' - .replaceAll('{identityId}', identityId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Create 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 { - final String apiPath = '/account/jwts'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Jwt.fromMap(res.data); - } - - /// List logs - /// - /// Get the list of latest security activity logs for the currently logged in - /// user. Each log returns user IP address, location and date and time of log. - Future listLogs({List? queries}) async { - final String apiPath = '/account/logs'; - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// Update MFA - /// - /// Enable or disable MFA on an account. - Future updateMFA({required bool mfa}) async { - final String apiPath = '/account/mfa'; - - final Map apiParams = { - 'mfa': mfa, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create Authenticator - /// - /// Add an authenticator app to be used as an MFA factor. Verify the - /// authenticator using the [verify - /// authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) - /// method. - Future createMfaAuthenticator( - {required enums.AuthenticatorType type}) async { - final String apiPath = - '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaType.fromMap(res.data); - } - - /// Verify Authenticator - /// - /// Verify an authenticator app after adding it using the [add - /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) - /// method. - Future updateMfaAuthenticator( - {required enums.AuthenticatorType type, required String otp}) async { - final String apiPath = - '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); - - final Map apiParams = { - 'otp': otp, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Delete Authenticator - /// - /// Delete an authenticator for a user by ID. - Future deleteMfaAuthenticator({required enums.AuthenticatorType type}) async { - final String apiPath = - '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Create MFA Challenge - /// - /// Begin the process of MFA verification after sign-in. Finish the flow with - /// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) - /// method. - Future createMfaChallenge( - {required enums.AuthenticationFactor factor}) async { - final String apiPath = '/account/mfa/challenge'; - - final Map apiParams = { - 'factor': factor.value, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaChallenge.fromMap(res.data); - } - - /// Create MFA Challenge (confirmation) - /// - /// Complete the MFA challenge by providing the one-time password. Finish the - /// process of MFA verification by providing the one-time password. To begin - /// the flow, use - /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) - /// method. - Future updateMfaChallenge( - {required String challengeId, required String otp}) async { - final String apiPath = '/account/mfa/challenge'; - - final Map apiParams = { - 'challengeId': challengeId, - 'otp': otp, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List Factors - /// - /// List the factors available on the account to be used as a MFA challange. - Future listMfaFactors() async { - final String apiPath = '/account/mfa/factors'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaFactors.fromMap(res.data); - } - - /// Get MFA Recovery Codes - /// - /// Get recovery codes that can be used as backup for MFA flow. Before getting - /// codes, they must be generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. An OTP challenge is required to read recovery codes. - Future getMfaRecoveryCodes() async { - final String apiPath = '/account/mfa/recovery-codes'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Create MFA Recovery Codes - /// - /// Generate recovery codes as backup for MFA flow. It's recommended to - /// generate and show then immediately after user successfully adds their - /// authehticator. Recovery codes can be used as a MFA verification type in - /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) - /// method. - Future createMfaRecoveryCodes() async { - final String apiPath = '/account/mfa/recovery-codes'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Regenerate MFA Recovery Codes - /// - /// Regenerate recovery codes that can be used as backup for MFA flow. Before - /// regenerating codes, they must be first generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. An OTP challenge is required to regenreate recovery codes. - Future updateMfaRecoveryCodes() async { - final String apiPath = '/account/mfa/recovery-codes'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Update name - /// - /// Update currently logged in user account name. - Future updateName({required String name}) async { - final String apiPath = '/account/name'; - - final Map apiParams = { - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update 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 { - final String apiPath = '/account/password'; - - final Map apiParams = { - 'password': password, - 'oldPassword': oldPassword, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update 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](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification) - /// endpoint to send a confirmation SMS. - Future updatePhone( - {required String phone, required String password}) async { - final String apiPath = '/account/phone'; - - final Map apiParams = { - 'phone': phone, - 'password': password, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Get account preferences - /// - /// Get the preferences as a key-value object for the currently logged in user. - Future getPrefs() async { - final String apiPath = '/account/prefs'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - } - - /// Update 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 { - final String apiPath = '/account/prefs'; - - final Map apiParams = { - 'prefs': prefs, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery) - /// 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 { - final String apiPath = '/account/recovery'; - - final Map apiParams = { - 'email': email, - 'url': url, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Create 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](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery) - /// 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}) async { - final String apiPath = '/account/recovery'; - - final Map apiParams = { - 'userId': userId, - 'secret': secret, - 'password': password, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// List sessions - /// - /// Get the list of active sessions across different devices for the currently - /// logged in user. - Future listSessions() async { - final String apiPath = '/account/sessions'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SessionList.fromMap(res.data); - } - - /// Delete sessions - /// - /// Delete all sessions from the user account and remove any sessions cookies - /// from the end client. - Future deleteSessions() async { - final String apiPath = '/account/sessions'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Create 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](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail) - /// or create an [OAuth2 - /// session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session). - Future createAnonymousSession() async { - final String apiPath = '/account/sessions/anonymous'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Create email password session - /// - /// Allow the user to login into their account by providing a valid email and - /// password combination. This route will create a new session for the user. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future createEmailPasswordSession( - {required String email, required String password}) async { - final String apiPath = '/account/sessions/email'; - - final Map apiParams = { - 'email': email, - 'password': password, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Update magic URL session - /// - /// Use this endpoint to create a session from token. Provide the **userId** - /// and **secret** parameters from the successful response of authentication - /// flows initiated by token creation. For example, magic URL and phone login. - Future updateMagicURLSession( - {required String userId, required String secret}) async { - final String apiPath = '/account/sessions/magic-url'; - - final Map apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Update phone session - /// - /// Use this endpoint to create a session from token. Provide the **userId** - /// and **secret** parameters from the successful response of authentication - /// flows initiated by token creation. For example, magic URL and phone login. - Future updatePhoneSession( - {required String userId, required String secret}) async { - final String apiPath = '/account/sessions/phone'; - - final Map apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Create session - /// - /// Use this endpoint to create a session from token. Provide the **userId** - /// and **secret** parameters from the successful response of authentication - /// flows initiated by token creation. For example, magic URL and phone login. - Future createSession( - {required String userId, required String secret}) async { - final String apiPath = '/account/sessions/token'; - - final Map apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Get session - /// - /// 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 apiPath = - '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Update session - /// - /// Use this endpoint to extend a session's length. Extending a session is - /// useful when session expiry is short. If the session was created using an - /// OAuth provider, this endpoint refreshes the access token from the provider. - Future updateSession({required String sessionId}) async { - final String apiPath = - '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Delete session - /// - /// Logout the user. Use 'current' as the session ID to logout on this device, - /// use a session ID to logout on another device. If you're looking to logout - /// the user on all devices, use [Delete - /// Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions) - /// instead. - Future deleteSession({required String sessionId}) async { - final String apiPath = - '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Update 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 { - final String apiPath = '/account/status'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create email token (OTP) - /// - /// Sends the user an email with a secret key for creating a session. If the - /// provided user ID has not be registered, a new user will be created. Use the - /// returned user ID and secret and submit a request to the [POST - /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. The secret sent to the user's email - /// is valid for 15 minutes. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future createEmailToken( - {required String userId, required String email, bool? phrase}) async { - final String apiPath = '/account/tokens/email'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'phrase': phrase, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Create magic URL token - /// - /// Sends the user an email with a secret key for creating a session. If the - /// provided user ID has not been registered, a new user will be created. When - /// the user clicks the link in the email, the user is redirected back to the - /// URL you provided with the secret key and userId values attached to the URL - /// query string. Use the query string parameters to submit a request to the - /// [POST - /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. The link sent to the user's email - /// address is valid for 1 hour. If you are on a mobile device you can leave - /// the URL parameter empty, so that the login completion will be handled by - /// your Appwrite instance by default. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - /// - Future createMagicURLToken( - {required String userId, - required String email, - String? url, - bool? phrase}) async { - final String apiPath = '/account/tokens/magic-url'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'url': url, - 'phrase': phrase, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Create OAuth2 token - /// - /// Allow the user to login to their account using the OAuth2 provider of their - /// choice. Each OAuth2 provider should be enabled from the Appwrite console - /// first. Use the success and failure arguments to provide a redirect URL's - /// back to your app when login is completed. - /// - /// If authentication succeeds, `userId` and `secret` of a token will be - /// appended to the success URL as query parameters. These can be used to - /// create a new session using the [Create - /// session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future createOAuth2Token( - {required enums.OAuthProvider provider, - String? success, - String? failure, - List? scopes}) async { - final String apiPath = '/account/tokens/oauth2/{provider}' - .replaceAll('{provider}', provider.value); - - final Map params = { - 'success': success, - 'failure': failure, - 'scopes': scopes, - 'project': client.config['project'], - }; - - final List query = []; - - params.forEach((key, value) { - if (value is List) { - for (var item in value) { - query.add(Uri.encodeComponent(key + '[]') + - '=' + - Uri.encodeComponent(item)); - } - } else if (value != null) { - query.add(Uri.encodeComponent(key) + '=' + Uri.encodeComponent(value)); - } - }); - - Uri endpoint = Uri.parse(client.endPoint); - Uri url = Uri( - scheme: endpoint.scheme, - host: endpoint.host, - port: endpoint.port, - path: endpoint.path + apiPath, - query: query.join('&')); - - return client.webAuth(url); - } - - /// Create phone token - /// - /// Sends the user an SMS with a secret key for creating a session. If the - /// provided user ID has not be registered, a new user will be created. Use the - /// returned user ID and secret and submit a request to the [POST - /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. The secret sent to the user's phone - /// is valid for 15 minutes. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future createPhoneToken( - {required String userId, required String phone}) async { - final String apiPath = '/account/tokens/phone'; - - final Map apiParams = { - 'userId': userId, - 'phone': phone, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Create email verification - /// - /// Use this endpoint to send a verification message to your user email address - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). - /// 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 { - final String apiPath = '/account/verification'; - - final Map apiParams = { - 'url': url, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Create 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 { - final String apiPath = '/account/verification'; - - final Map apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone) - /// endpoint. Learn more about how to [complete the verification - /// process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification). - /// The verification code sent to the user's phone number is valid for 15 - /// minutes. - Future createPhoneVerification() async { - final String apiPath = '/account/verification/phone'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Update 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 { - final String apiPath = '/account/verification/phone'; - - final Map apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } -} + Account(super.client); + + /// Get account + /// + /// Get the currently logged in user. + Future get() async { + final String apiPath = '/account'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.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](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession). + Future create({required String userId, required String email, required String password, String? name}) async { + final String apiPath = '/account'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update 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 { + final String apiPath = '/account/email'; + + final Map apiParams = { + + 'email': email, +'password': password, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// List identities + /// + /// Get the list of identities for the currently logged in user. + Future listIdentities({List? queries}) async { + final String apiPath = '/account/identities'; + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.IdentityList.fromMap(res.data); + + } + + /// Delete identity + /// + /// Delete an identity by its unique ID. + Future deleteIdentity({required String identityId}) async { + final String apiPath = '/account/identities/{identityId}'.replaceAll('{identityId}', identityId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Create 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 { + final String apiPath = '/account/jwts'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Jwt.fromMap(res.data); + + } + + /// List logs + /// + /// Get the list of latest security activity logs for the currently logged in + /// user. Each log returns user IP address, location and date and time of log. + Future listLogs({List? queries}) async { + final String apiPath = '/account/logs'; + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// Update MFA + /// + /// Enable or disable MFA on an account. + Future updateMFA({required bool mfa}) async { + final String apiPath = '/account/mfa'; + + final Map apiParams = { + + 'mfa': mfa, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create authenticator + /// + /// Add an authenticator app to be used as an MFA factor. Verify the + /// authenticator using the [verify + /// authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) + /// method. + Future createMfaAuthenticator({required enums.AuthenticatorType type}) async { + final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaType.fromMap(res.data); + + } + + /// Verify authenticator + /// + /// Verify an authenticator app after adding it using the [add + /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) + /// method. + Future updateMfaAuthenticator({required enums.AuthenticatorType type, required String otp}) async { + final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map apiParams = { + + 'otp': otp, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Delete authenticator + /// + /// Delete an authenticator for a user by ID. + Future deleteMfaAuthenticator({required enums.AuthenticatorType type}) async { + final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Create MFA challenge + /// + /// Begin the process of MFA verification after sign-in. Finish the flow with + /// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) + /// method. + Future createMfaChallenge({required enums.AuthenticationFactor factor}) async { + final String apiPath = '/account/mfa/challenge'; + + final Map apiParams = { + + 'factor': factor.value, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaChallenge.fromMap(res.data); + + } + + /// Create MFA challenge (confirmation) + /// + /// Complete the MFA challenge by providing the one-time password. Finish the + /// process of MFA verification by providing the one-time password. To begin + /// the flow, use + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method. + Future updateMfaChallenge({required String challengeId, required String otp}) async { + final String apiPath = '/account/mfa/challenge'; + + final Map apiParams = { + + 'challengeId': challengeId, +'otp': otp, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List factors + /// + /// List the factors available on the account to be used as a MFA challange. + Future listMfaFactors() async { + final String apiPath = '/account/mfa/factors'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaFactors.fromMap(res.data); + + } + + /// Get MFA recovery codes + /// + /// Get recovery codes that can be used as backup for MFA flow. Before getting + /// codes, they must be generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. An OTP challenge is required to read recovery codes. + Future getMfaRecoveryCodes() async { + final String apiPath = '/account/mfa/recovery-codes'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Create MFA recovery codes + /// + /// Generate recovery codes as backup for MFA flow. It's recommended to + /// generate and show then immediately after user successfully adds their + /// authehticator. Recovery codes can be used as a MFA verification type in + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method. + Future createMfaRecoveryCodes() async { + final String apiPath = '/account/mfa/recovery-codes'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Regenerate MFA recovery codes + /// + /// Regenerate recovery codes that can be used as backup for MFA flow. Before + /// regenerating codes, they must be first generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. An OTP challenge is required to regenreate recovery codes. + Future updateMfaRecoveryCodes() async { + final String apiPath = '/account/mfa/recovery-codes'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Update name + /// + /// Update currently logged in user account name. + Future updateName({required String name}) async { + final String apiPath = '/account/name'; + + final Map apiParams = { + + 'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update 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 { + final String apiPath = '/account/password'; + + final Map apiParams = { + + 'password': password, +'oldPassword': oldPassword, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update 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](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification) + /// endpoint to send a confirmation SMS. + Future updatePhone({required String phone, required String password}) async { + final String apiPath = '/account/phone'; + + final Map apiParams = { + + 'phone': phone, +'password': password, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Get account preferences + /// + /// Get the preferences as a key-value object for the currently logged in user. + Future getPrefs() async { + final String apiPath = '/account/prefs'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + + } + + /// Update 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 { + final String apiPath = '/account/prefs'; + + final Map apiParams = { + + 'prefs': prefs, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery) + /// 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 { + final String apiPath = '/account/recovery'; + + final Map apiParams = { + + 'email': email, +'url': url, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Create 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](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery) + /// 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}) async { + final String apiPath = '/account/recovery'; + + final Map apiParams = { + + 'userId': userId, +'secret': secret, +'password': password, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// List sessions + /// + /// Get the list of active sessions across different devices for the currently + /// logged in user. + Future listSessions() async { + final String apiPath = '/account/sessions'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SessionList.fromMap(res.data); + + } + + /// Delete sessions + /// + /// Delete all sessions from the user account and remove any sessions cookies + /// from the end client. + Future deleteSessions() async { + final String apiPath = '/account/sessions'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Create 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](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail) + /// or create an [OAuth2 + /// session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session). + Future createAnonymousSession() async { + final String apiPath = '/account/sessions/anonymous'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Create email password session + /// + /// Allow the user to login into their account by providing a valid email and + /// password combination. This route will create a new session for the user. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future createEmailPasswordSession({required String email, required String password}) async { + final String apiPath = '/account/sessions/email'; + + final Map apiParams = { + + 'email': email, +'password': password, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Update magic URL session + /// + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. + Future updateMagicURLSession({required String userId, required String secret}) async { + final String apiPath = '/account/sessions/magic-url'; + + final Map apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Update phone session + /// + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. + Future updatePhoneSession({required String userId, required String secret}) async { + final String apiPath = '/account/sessions/phone'; + + final Map apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Create session + /// + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. + Future createSession({required String userId, required String secret}) async { + final String apiPath = '/account/sessions/token'; + + final Map apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Get session + /// + /// 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 apiPath = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Update session + /// + /// Use this endpoint to extend a session's length. Extending a session is + /// useful when session expiry is short. If the session was created using an + /// OAuth provider, this endpoint refreshes the access token from the provider. + Future updateSession({required String sessionId}) async { + final String apiPath = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Delete session + /// + /// Logout the user. Use 'current' as the session ID to logout on this device, + /// use a session ID to logout on another device. If you're looking to logout + /// the user on all devices, use [Delete + /// Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions) + /// instead. + Future deleteSession({required String sessionId}) async { + final String apiPath = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Update 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 { + final String apiPath = '/account/status'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create email token (OTP) + /// + /// Sends the user an email with a secret key for creating a session. If the + /// provided user ID has not be registered, a new user will be created. Use the + /// returned user ID and secret and submit a request to the [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The secret sent to the user's email + /// is valid for 15 minutes. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future createEmailToken({required String userId, required String email, bool? phrase}) async { + final String apiPath = '/account/tokens/email'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'phrase': phrase, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Create magic URL token + /// + /// Sends the user an email with a secret key for creating a session. If the + /// provided user ID has not been registered, a new user will be created. When + /// the user clicks the link in the email, the user is redirected back to the + /// URL you provided with the secret key and userId values attached to the URL + /// query string. Use the query string parameters to submit a request to the + /// [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The link sent to the user's email + /// address is valid for 1 hour. If you are on a mobile device you can leave + /// the URL parameter empty, so that the login completion will be handled by + /// your Appwrite instance by default. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + /// + Future createMagicURLToken({required String userId, required String email, String? url, bool? phrase}) async { + final String apiPath = '/account/tokens/magic-url'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'url': url, +'phrase': phrase, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Create OAuth2 token + /// + /// Allow the user to login to their account using the OAuth2 provider of their + /// choice. Each OAuth2 provider should be enabled from the Appwrite console + /// first. Use the success and failure arguments to provide a redirect URL's + /// back to your app when login is completed. + /// + /// If authentication succeeds, `userId` and `secret` of a token will be + /// appended to the success URL as query parameters. These can be used to + /// create a new session using the [Create + /// session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future createOAuth2Token({required enums.OAuthProvider provider, String? success, String? failure, List? scopes}) async { + final String apiPath = '/account/tokens/oauth2/{provider}'.replaceAll('{provider}', provider.value); + + final Map params = { + 'success': success, +'failure': failure, +'scopes': scopes, + + + 'project': client.config['project'], + }; + + final List query = []; + + params.forEach((key, value) { + if (value is List) { + for (var item in value) { + query.add(Uri.encodeComponent(key + '[]') + '=' + Uri.encodeComponent(item)); + } + } else if(value != null) { + query.add(Uri.encodeComponent(key) + '=' + Uri.encodeComponent(value)); + } + }); + + Uri endpoint = Uri.parse(client.endPoint); + Uri url = Uri(scheme: endpoint.scheme, + host: endpoint.host, + port: endpoint.port, + path: endpoint.path + apiPath, + query: query.join('&') + ); + + return client.webAuth(url); + } + + /// Create phone token + /// + /// Sends the user an SMS with a secret key for creating a session. If the + /// provided user ID has not be registered, a new user will be created. Use the + /// returned user ID and secret and submit a request to the [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The secret sent to the user's phone + /// is valid for 15 minutes. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future createPhoneToken({required String userId, required String phone}) async { + final String apiPath = '/account/tokens/phone'; + + final Map apiParams = { + + 'userId': userId, +'phone': phone, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Create email verification + /// + /// Use this endpoint to send a verification message to your user email address + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). + /// 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 { + final String apiPath = '/account/verification'; + + final Map apiParams = { + + 'url': url, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Create 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 { + final String apiPath = '/account/verification'; + + final Map apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone) + /// endpoint. Learn more about how to [complete the verification + /// process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification). + /// The verification code sent to the user's phone number is valid for 15 + /// minutes. + Future createPhoneVerification() async { + final String apiPath = '/account/verification/phone'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Update 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 { + final String apiPath = '/account/verification/phone'; + + final Map apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 9c77eda6..4609b00b 100644 --- a/lib/services/avatars.dart +++ b/lib/services/avatars.dart @@ -3,209 +3,201 @@ part of '../dart_appwrite.dart'; /// The Avatars service aims to help you complete everyday tasks related to /// your app image, icons, and avatars. class Avatars extends Service { - Avatars(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](https://appwrite.io/docs/references/cloud/client-web/account#getSessions) - /// 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 enums.Browser code, - int? width, - int? height, - int? quality}) async { - final String apiPath = - '/avatars/browsers/{code}'.replaceAll('{code}', code.value); - - final Map params = { - 'width': width, - 'height': height, - 'quality': quality, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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 enums.CreditCard code, - int? width, - int? height, - int? quality}) async { - final String apiPath = - '/avatars/credit-cards/{code}'.replaceAll('{code}', code.value); - - final Map params = { - 'width': width, - 'height': height, - 'quality': quality, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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. - /// - /// This endpoint does not follow HTTP redirects. - Future getFavicon({required String url}) async { - final String apiPath = '/avatars/favicon'; - - final Map params = { - 'url': url, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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. Country codes - /// follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard. - /// - /// 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 enums.Flag code, int? width, int? height, int? quality}) async { - final String apiPath = - '/avatars/flags/{code}'.replaceAll('{code}', code.value); - - final Map params = { - 'width': width, - 'height': height, - 'quality': quality, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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. - /// - /// This endpoint does not follow HTTP redirects. - Future getImage( - {required String url, int? width, int? height}) async { - final String apiPath = '/avatars/image'; - - final Map params = { - 'url': url, - 'width': width, - 'height': height, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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? background}) async { - final String apiPath = '/avatars/initials'; - - final Map params = { - 'name': name, - 'width': width, - 'height': height, - 'background': background, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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 { - final String apiPath = '/avatars/qr'; - - final Map params = { - 'text': text, - 'size': size, - 'margin': margin, - 'download': download, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: params, responseType: ResponseType.bytes); - return res.data; - } -} + Avatars(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](https://appwrite.io/docs/references/cloud/client-web/account#getSessions) + /// 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 enums.Browser code, int? width, int? height, int? quality}) async { + final String apiPath = '/avatars/browsers/{code}'.replaceAll('{code}', code.value); + + final Map params = { + 'width': width, +'height': height, +'quality': quality, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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 enums.CreditCard code, int? width, int? height, int? quality}) async { + final String apiPath = '/avatars/credit-cards/{code}'.replaceAll('{code}', code.value); + + final Map params = { + 'width': width, +'height': height, +'quality': quality, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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. + /// + /// This endpoint does not follow HTTP redirects. + Future getFavicon({required String url}) async { + final String apiPath = '/avatars/favicon'; + + final Map params = { + 'url': url, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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. Country codes + /// follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard. + /// + /// 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 enums.Flag code, int? width, int? height, int? quality}) async { + final String apiPath = '/avatars/flags/{code}'.replaceAll('{code}', code.value); + + final Map params = { + 'width': width, +'height': height, +'quality': quality, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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. + /// + /// This endpoint does not follow HTTP redirects. + Future getImage({required String url, int? width, int? height}) async { + final String apiPath = '/avatars/image'; + + final Map params = { + 'url': url, +'width': width, +'height': height, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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? background}) async { + final String apiPath = '/avatars/initials'; + + final Map params = { + 'name': name, +'width': width, +'height': height, +'background': background, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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 { + final String apiPath = '/avatars/qr'; + + final Map params = { + 'text': text, +'size': size, +'margin': margin, +'download': download, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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 5d3a8c86..6d74eb4b 100644 --- a/lib/services/databases.dart +++ b/lib/services/databases.dart @@ -3,1280 +3,1093 @@ part of '../dart_appwrite.dart'; /// The Databases service allows you to create structured collections of /// documents, query and filter lists of documents class Databases extends Service { - Databases(super.client); - - /// List databases - /// - /// Get a list of all databases from the current Appwrite project. You can use - /// the search parameter to filter your results. - Future list( - {List? queries, String? search}) async { - final String apiPath = '/databases'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.DatabaseList.fromMap(res.data); - } - - /// Create database - /// - /// Create a new Database. - /// - Future create( - {required String databaseId, required String name, bool? enabled}) async { - final String apiPath = '/databases'; - - final Map apiParams = { - 'databaseId': databaseId, - 'name': name, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Database.fromMap(res.data); - } - - /// Get database - /// - /// Get a database by its unique ID. This endpoint response returns a JSON - /// object with the database metadata. - Future get({required String databaseId}) async { - final String apiPath = - '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Database.fromMap(res.data); - } - - /// Update database - /// - /// Update a database by its unique ID. - Future update( - {required String databaseId, required String name, bool? enabled}) async { - final String apiPath = - '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Database.fromMap(res.data); - } - - /// Delete database - /// - /// Delete a database by its unique ID. Only API keys with with databases.write - /// scope can delete a database. - Future delete({required String databaseId}) async { - final String apiPath = - '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List collections - /// - /// Get a list of all collections that belong to the provided databaseId. You - /// can use the search parameter to filter your results. - Future listCollections( - {required String databaseId, - List? queries, - String? search}) async { - final String apiPath = '/databases/{databaseId}/collections' - .replaceAll('{databaseId}', databaseId); - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.CollectionList.fromMap(res.data); - } - - /// Create collection - /// - /// Create a new Collection. Before using this route, you should create a new - /// database resource using either a [server - /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) - /// API or directly from your database console. - Future createCollection( - {required String databaseId, - required String collectionId, - required String name, - List? permissions, - bool? documentSecurity, - bool? enabled}) async { - final String apiPath = '/databases/{databaseId}/collections' - .replaceAll('{databaseId}', databaseId); - - final Map apiParams = { - 'collectionId': collectionId, - 'name': name, - 'permissions': permissions, - 'documentSecurity': documentSecurity, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Collection.fromMap(res.data); - } - - /// Get collection - /// - /// Get a collection by its unique ID. This endpoint response returns a JSON - /// object with the collection metadata. - Future getCollection( - {required String databaseId, required String collectionId}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Collection.fromMap(res.data); - } - - /// Update collection - /// - /// Update a collection by its unique ID. - Future updateCollection( - {required String databaseId, - required String collectionId, - required String name, - List? permissions, - bool? documentSecurity, - bool? enabled}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'name': name, - 'permissions': permissions, - 'documentSecurity': documentSecurity, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Collection.fromMap(res.data); - } - - /// Delete collection - /// - /// Delete a collection by its unique ID. Only users with write permissions - /// have access to delete this resource. - Future deleteCollection( - {required String databaseId, required String collectionId}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List attributes - /// - /// List attributes in the collection. - Future listAttributes( - {required String databaseId, - required String collectionId, - List? queries}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeList.fromMap(res.data); - } - - /// Create boolean attribute - /// - /// Create a boolean attribute. - /// - Future createBooleanAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - bool? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/boolean' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeBoolean.fromMap(res.data); - } - - /// Update boolean attribute - /// - /// Update a boolean attribute. Changing the `default` value will not update - /// already existing documents. - Future updateBooleanAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required bool? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/boolean/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeBoolean.fromMap(res.data); - } - - /// Create datetime attribute - /// - /// Create a date time attribute according to the ISO 8601 standard. - Future createDatetimeAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - String? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/datetime' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeDatetime.fromMap(res.data); - } - - /// Update dateTime attribute - /// - /// Update a date time attribute. Changing the `default` value will not update - /// already existing documents. - Future updateDatetimeAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required String? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/datetime/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeDatetime.fromMap(res.data); - } - - /// Create email attribute - /// - /// Create an email attribute. - /// - Future createEmailAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - String? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/email' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEmail.fromMap(res.data); - } - - /// Update email attribute - /// - /// Update an email attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateEmailAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required String? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/email/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEmail.fromMap(res.data); - } - - /// Create enum attribute - /// - /// Create an enumeration attribute. The `elements` param acts as a white-list - /// of accepted values for this attribute. - /// - Future createEnumAttribute( - {required String databaseId, - required String collectionId, - required String key, - required List elements, - required bool xrequired, - String? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/enum' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'elements': elements, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEnum.fromMap(res.data); - } - - /// Update enum attribute - /// - /// Update an enum attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateEnumAttribute( - {required String databaseId, - required String collectionId, - required String key, - required List elements, - required bool xrequired, - required String? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/enum/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'elements': elements, - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEnum.fromMap(res.data); - } - - /// Create float attribute - /// - /// Create a float attribute. Optionally, minimum and maximum values can be - /// provided. - /// - Future createFloatAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - double? min, - double? max, - double? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/float' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, - 'array': array, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeFloat.fromMap(res.data); - } - - /// Update float attribute - /// - /// Update a float attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateFloatAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required double min, - required double max, - required double? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/float/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeFloat.fromMap(res.data); - } - - /// Create integer attribute - /// - /// Create an integer attribute. Optionally, minimum and maximum values can be - /// provided. - /// - Future createIntegerAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - int? min, - int? max, - int? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/integer' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, - 'array': array, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeInteger.fromMap(res.data); - } - - /// Update integer attribute - /// - /// Update an integer attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateIntegerAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required int min, - required int max, - required int? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/integer/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeInteger.fromMap(res.data); - } - - /// Create IP address attribute - /// - /// Create IP address attribute. - /// - Future createIpAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - String? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/ip' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeIp.fromMap(res.data); - } - - /// Update IP address attribute - /// - /// Update an ip attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateIpAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required String? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/ip/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeIp.fromMap(res.data); - } - - /// Create relationship attribute - /// - /// Create relationship attribute. [Learn more about relationship - /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). - /// - Future createRelationshipAttribute( - {required String databaseId, - required String collectionId, - required String relatedCollectionId, - required enums.RelationshipType type, - bool? twoWay, - String? key, - String? twoWayKey, - enums.RelationMutate? onDelete}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/relationship' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'relatedCollectionId': relatedCollectionId, - 'type': type.value, - 'twoWay': twoWay, - 'key': key, - 'twoWayKey': twoWayKey, - 'onDelete': onDelete?.value, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeRelationship.fromMap(res.data); - } - - /// Create string attribute - /// - /// Create a string attribute. - /// - Future createStringAttribute( - {required String databaseId, - required String collectionId, - required String key, - required int size, - required bool xrequired, - String? xdefault, - bool? array, - bool? encrypt}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/string' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'size': size, - 'required': xrequired, - 'default': xdefault, - 'array': array, - 'encrypt': encrypt, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeString.fromMap(res.data); - } - - /// Update string attribute - /// - /// Update a string attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateStringAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required String? xdefault, - int? size, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/string/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'required': xrequired, - 'default': xdefault, - 'size': size, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeString.fromMap(res.data); - } - - /// Create URL attribute - /// - /// Create a URL attribute. - /// - Future createUrlAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - String? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/url' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeUrl.fromMap(res.data); - } - - /// Update URL attribute - /// - /// Update an url attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future updateUrlAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required String? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/url/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeUrl.fromMap(res.data); - } - - /// Get attribute - /// - /// Get attribute by ID. - Future getAttribute( - {required String databaseId, - required String collectionId, - required String key}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Delete attribute - /// - /// Deletes an attribute. - Future deleteAttribute( - {required String databaseId, - required String collectionId, - required String key}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Update relationship attribute - /// - /// Update relationship attribute. [Learn more about relationship - /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). - /// - Future updateRelationshipAttribute( - {required String databaseId, - required String collectionId, - required String key, - enums.RelationMutate? onDelete, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/{key}/relationship' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = { - 'onDelete': onDelete?.value, - 'newKey': newKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeRelationship.fromMap(res.data); - } - - /// List documents - /// - /// Get a list of all the user's documents in a given collection. You can use - /// the query params to filter your results. - Future listDocuments( - {required String databaseId, - required String collectionId, - List? queries}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/documents' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.DocumentList.fromMap(res.data); - } - - /// Create document - /// - /// Create a new Document. Before using this route, you should create a new - /// collection resource using either a [server - /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) - /// API or directly from your database console. - Future createDocument( - {required String databaseId, - required String collectionId, - required String documentId, - required Map data, - List? permissions}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/documents' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'documentId': documentId, - 'data': data, - 'permissions': permissions, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Document.fromMap(res.data); - } - - /// Get document - /// - /// Get a document by its unique ID. This endpoint response returns a JSON - /// object with the document data. - Future getDocument( - {required String databaseId, - required String collectionId, - required String documentId, - List? queries}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{documentId}', documentId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Document.fromMap(res.data); - } - - /// Update document - /// - /// Update a document by its unique ID. Using the patch method you can pass - /// only specific fields that will get updated. - Future updateDocument( - {required String databaseId, - required String collectionId, - required String documentId, - Map? data, - List? permissions}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{documentId}', documentId); - - final Map apiParams = { - 'data': data, - 'permissions': permissions, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Document.fromMap(res.data); - } - - /// Delete document - /// - /// Delete a document by its unique ID. - Future deleteDocument( - {required String databaseId, - required String collectionId, - required String documentId}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{documentId}', documentId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List indexes - /// - /// List indexes in the collection. - Future listIndexes( - {required String databaseId, - required String collectionId, - List? queries}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/indexes' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.IndexList.fromMap(res.data); - } - - /// Create index - /// - /// Creates an index on the attributes listed. Your index should include all - /// the attributes you will query in a single request. - /// Attributes can be `key`, `fulltext`, and `unique`. - Future createIndex( - {required String databaseId, - required String collectionId, - required String key, - required enums.IndexType type, - required List attributes, - List? orders}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/indexes' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map apiParams = { - 'key': key, - 'type': type.value, - 'attributes': attributes, - 'orders': orders, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Index.fromMap(res.data); - } - - /// Get index - /// - /// Get index by ID. - Future getIndex( - {required String databaseId, - required String collectionId, - required String key}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/indexes/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Index.fromMap(res.data); - } - - /// Delete index - /// - /// Delete an index. - Future deleteIndex( - {required String databaseId, - required String collectionId, - required String key}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/indexes/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } -} + Databases(super.client); + + /// List databases + /// + /// Get a list of all databases from the current Appwrite project. You can use + /// the search parameter to filter your results. + Future list({List? queries, String? search}) async { + final String apiPath = '/databases'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DatabaseList.fromMap(res.data); + + } + + /// Create database + /// + /// Create a new Database. + /// + Future create({required String databaseId, required String name, bool? enabled}) async { + final String apiPath = '/databases'; + + final Map apiParams = { + + 'databaseId': databaseId, +'name': name, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Database.fromMap(res.data); + + } + + /// Get database + /// + /// Get a database by its unique ID. This endpoint response returns a JSON + /// object with the database metadata. + Future get({required String databaseId}) async { + final String apiPath = '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Database.fromMap(res.data); + + } + + /// Update database + /// + /// Update a database by its unique ID. + Future update({required String databaseId, required String name, bool? enabled}) async { + final String apiPath = '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Database.fromMap(res.data); + + } + + /// Delete database + /// + /// Delete a database by its unique ID. Only API keys with with databases.write + /// scope can delete a database. + Future delete({required String databaseId}) async { + final String apiPath = '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List collections + /// + /// Get a list of all collections that belong to the provided databaseId. You + /// can use the search parameter to filter your results. + Future listCollections({required String databaseId, List? queries, String? search}) async { + final String apiPath = '/databases/{databaseId}/collections'.replaceAll('{databaseId}', databaseId); + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.CollectionList.fromMap(res.data); + + } + + /// Create collection + /// + /// Create a new Collection. Before using this route, you should create a new + /// database resource using either a [server + /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) + /// API or directly from your database console. + Future createCollection({required String databaseId, required String collectionId, required String name, List? permissions, bool? documentSecurity, bool? enabled}) async { + final String apiPath = '/databases/{databaseId}/collections'.replaceAll('{databaseId}', databaseId); + + final Map apiParams = { + + 'collectionId': collectionId, +'name': name, +'permissions': permissions, +'documentSecurity': documentSecurity, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Collection.fromMap(res.data); + + } + + /// Get collection + /// + /// Get a collection by its unique ID. This endpoint response returns a JSON + /// object with the collection metadata. + Future getCollection({required String databaseId, required String collectionId}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Collection.fromMap(res.data); + + } + + /// Update collection + /// + /// Update a collection by its unique ID. + Future updateCollection({required String databaseId, required String collectionId, required String name, List? permissions, bool? documentSecurity, bool? enabled}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'name': name, +'permissions': permissions, +'documentSecurity': documentSecurity, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Collection.fromMap(res.data); + + } + + /// Delete collection + /// + /// Delete a collection by its unique ID. Only users with write permissions + /// have access to delete this resource. + Future deleteCollection({required String databaseId, required String collectionId}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List attributes + /// + /// List attributes in the collection. + Future listAttributes({required String databaseId, required String collectionId, List? queries}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeList.fromMap(res.data); + + } + + /// Create boolean attribute + /// + /// Create a boolean attribute. + /// + Future createBooleanAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, bool? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/boolean'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeBoolean.fromMap(res.data); + + } + + /// Update boolean attribute + /// + /// Update a boolean attribute. Changing the `default` value will not update + /// already existing documents. + Future updateBooleanAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required bool? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/boolean/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeBoolean.fromMap(res.data); + + } + + /// Create datetime attribute + /// + /// Create a date time attribute according to the ISO 8601 standard. + Future createDatetimeAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/datetime'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeDatetime.fromMap(res.data); + + } + + /// Update dateTime attribute + /// + /// Update a date time attribute. Changing the `default` value will not update + /// already existing documents. + Future updateDatetimeAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/datetime/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeDatetime.fromMap(res.data); + + } + + /// Create email attribute + /// + /// Create an email attribute. + /// + Future createEmailAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/email'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEmail.fromMap(res.data); + + } + + /// Update email attribute + /// + /// Update an email attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateEmailAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/email/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEmail.fromMap(res.data); + + } + + /// Create enum attribute + /// + /// Create an enumeration attribute. The `elements` param acts as a white-list + /// of accepted values for this attribute. + /// + Future createEnumAttribute({required String databaseId, required String collectionId, required String key, required List elements, required bool xrequired, String? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/enum'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'elements': elements, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEnum.fromMap(res.data); + + } + + /// Update enum attribute + /// + /// Update an enum attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateEnumAttribute({required String databaseId, required String collectionId, required String key, required List elements, required bool xrequired, required String? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/enum/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'elements': elements, +'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEnum.fromMap(res.data); + + } + + /// Create float attribute + /// + /// Create a float attribute. Optionally, minimum and maximum values can be + /// provided. + /// + Future createFloatAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, double? min, double? max, double? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/float'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'required': xrequired, +'min': min, +'max': max, +'default': xdefault, +'array': array, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeFloat.fromMap(res.data); + + } + + /// Update float attribute + /// + /// Update a float attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateFloatAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required double min, required double max, required double? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/float/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'required': xrequired, +'min': min, +'max': max, +'default': xdefault, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeFloat.fromMap(res.data); + + } + + /// Create integer attribute + /// + /// Create an integer attribute. Optionally, minimum and maximum values can be + /// provided. + /// + Future createIntegerAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, int? min, int? max, int? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/integer'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'required': xrequired, +'min': min, +'max': max, +'default': xdefault, +'array': array, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeInteger.fromMap(res.data); + + } + + /// Update integer attribute + /// + /// Update an integer attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateIntegerAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required int min, required int max, required int? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/integer/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'required': xrequired, +'min': min, +'max': max, +'default': xdefault, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeInteger.fromMap(res.data); + + } + + /// Create IP address attribute + /// + /// Create IP address attribute. + /// + Future createIpAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/ip'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeIp.fromMap(res.data); + + } + + /// Update IP address attribute + /// + /// Update an ip attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateIpAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/ip/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeIp.fromMap(res.data); + + } + + /// Create relationship attribute + /// + /// Create relationship attribute. [Learn more about relationship + /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). + /// + Future createRelationshipAttribute({required String databaseId, required String collectionId, required String relatedCollectionId, required enums.RelationshipType type, bool? twoWay, String? key, String? twoWayKey, enums.RelationMutate? onDelete}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/relationship'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'relatedCollectionId': relatedCollectionId, +'type': type.value, +'twoWay': twoWay, +'key': key, +'twoWayKey': twoWayKey, +'onDelete': onDelete?.value, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeRelationship.fromMap(res.data); + + } + + /// Create string attribute + /// + /// Create a string attribute. + /// + Future createStringAttribute({required String databaseId, required String collectionId, required String key, required int size, required bool xrequired, String? xdefault, bool? array, bool? encrypt}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/string'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'size': size, +'required': xrequired, +'default': xdefault, +'array': array, +'encrypt': encrypt, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeString.fromMap(res.data); + + } + + /// Update string attribute + /// + /// Update a string attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateStringAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, int? size, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/string/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'required': xrequired, +'default': xdefault, +'size': size, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeString.fromMap(res.data); + + } + + /// Create URL attribute + /// + /// Create a URL attribute. + /// + Future createUrlAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/url'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeUrl.fromMap(res.data); + + } + + /// Update URL attribute + /// + /// Update an url attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future updateUrlAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/url/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeUrl.fromMap(res.data); + + } + + /// Get attribute + /// + /// Get attribute by ID. + Future getAttribute({required String databaseId, required String collectionId, required String key}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Delete attribute + /// + /// Deletes an attribute. + Future deleteAttribute({required String databaseId, required String collectionId, required String key}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Update relationship attribute + /// + /// Update relationship attribute. [Learn more about relationship + /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). + /// + Future updateRelationshipAttribute({required String databaseId, required String collectionId, required String key, enums.RelationMutate? onDelete, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}/relationship'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + 'onDelete': onDelete?.value, +'newKey': newKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeRelationship.fromMap(res.data); + + } + + /// List documents + /// + /// Get a list of all the user's documents in a given collection. You can use + /// the query params to filter your results. + Future listDocuments({required String databaseId, required String collectionId, List? queries}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DocumentList.fromMap(res.data); + + } + + /// Create document + /// + /// Create a new Document. Before using this route, you should create a new + /// collection resource using either a [server + /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) + /// API or directly from your database console. + Future createDocument({required String databaseId, required String collectionId, required String documentId, required Map data, List? permissions}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'documentId': documentId, +'data': data, +'permissions': permissions, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Document.fromMap(res.data); + + } + + /// Get document + /// + /// Get a document by its unique ID. This endpoint response returns a JSON + /// object with the document data. + Future getDocument({required String databaseId, required String collectionId, required String documentId, List? queries}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Document.fromMap(res.data); + + } + + /// Update document + /// + /// Update a document by its unique ID. Using the patch method you can pass + /// only specific fields that will get updated. + Future updateDocument({required String databaseId, required String collectionId, required String documentId, Map? data, List? permissions}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); + + final Map apiParams = { + + 'data': data, +'permissions': permissions, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Document.fromMap(res.data); + + } + + /// Delete document + /// + /// Delete a document by its unique ID. + Future deleteDocument({required String databaseId, required String collectionId, required String documentId}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List indexes + /// + /// List indexes in the collection. + Future listIndexes({required String databaseId, required String collectionId, List? queries}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.IndexList.fromMap(res.data); + + } + + /// Create index + /// + /// Creates an index on the attributes listed. Your index should include all + /// the attributes you will query in a single request. + /// Attributes can be `key`, `fulltext`, and `unique`. + Future createIndex({required String databaseId, required String collectionId, required String key, required enums.IndexType type, required List attributes, List? orders}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map apiParams = { + + 'key': key, +'type': type.value, +'attributes': attributes, +'orders': orders, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Index.fromMap(res.data); + + } + + /// Get index + /// + /// Get index by ID. + Future getIndex({required String databaseId, required String collectionId, required String key}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Index.fromMap(res.data); + + } + + /// Delete index + /// + /// Delete an index. + Future deleteIndex({required String databaseId, required String collectionId, required String key}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } +} \ No newline at end of file diff --git a/lib/services/functions.dart b/lib/services/functions.dart index 5852b341..2bc323e9 100644 --- a/lib/services/functions.dart +++ b/lib/services/functions.dart @@ -3,650 +3,619 @@ part of '../dart_appwrite.dart'; /// The Functions Service allows you view, create and manage your Cloud /// Functions. class Functions extends Service { - Functions(super.client); - - /// List functions - /// - /// Get a list of all the project's functions. You can use the query params to - /// filter your results. - Future list( - {List? queries, String? search}) async { - final String apiPath = '/functions'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.FunctionList.fromMap(res.data); - } - - /// Create function - /// - /// Create a new function. You can pass a list of - /// [permissions](https://appwrite.io/docs/permissions) to allow different - /// project users or team with access to execute the function using the client - /// API. - Future create( - {required String functionId, - required String name, - required enums.Runtime runtime, - List? execute, - List? events, - String? schedule, - int? timeout, - bool? enabled, - bool? logging, - String? entrypoint, - String? commands, - List? scopes, - String? installationId, - String? providerRepositoryId, - String? providerBranch, - bool? providerSilentMode, - String? providerRootDirectory, - String? templateRepository, - String? templateOwner, - String? templateRootDirectory, - String? templateVersion, - String? specification}) async { - final String apiPath = '/functions'; - - final Map apiParams = { - 'functionId': functionId, - 'name': name, - 'runtime': runtime.value, - 'execute': execute, - 'events': events, - 'schedule': schedule, - 'timeout': timeout, - 'enabled': enabled, - 'logging': logging, - 'entrypoint': entrypoint, - 'commands': commands, - 'scopes': scopes, - 'installationId': installationId, - 'providerRepositoryId': providerRepositoryId, - 'providerBranch': providerBranch, - 'providerSilentMode': providerSilentMode, - 'providerRootDirectory': providerRootDirectory, - 'templateRepository': templateRepository, - 'templateOwner': templateOwner, - 'templateRootDirectory': templateRootDirectory, - 'templateVersion': templateVersion, - 'specification': specification, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - } - - /// List runtimes - /// - /// Get a list of all runtimes that are currently active on your instance. - Future listRuntimes() async { - final String apiPath = '/functions/runtimes'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.RuntimeList.fromMap(res.data); - } - - /// List available function runtime specifications - /// - /// List allowed function specifications for this instance. - /// - Future listSpecifications() async { - final String apiPath = '/functions/specifications'; - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SpecificationList.fromMap(res.data); - } - - /// Get function - /// - /// Get a function by its unique ID. - Future get({required String functionId}) async { - final String apiPath = - '/functions/{functionId}'.replaceAll('{functionId}', functionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - } - - /// Update function - /// - /// Update function by its unique ID. - Future update( - {required String functionId, - required String name, - enums.Runtime? runtime, - List? execute, - List? events, - String? schedule, - int? timeout, - bool? enabled, - bool? logging, - String? entrypoint, - String? commands, - List? scopes, - String? installationId, - String? providerRepositoryId, - String? providerBranch, - bool? providerSilentMode, - String? providerRootDirectory, - String? specification}) async { - final String apiPath = - '/functions/{functionId}'.replaceAll('{functionId}', functionId); - - final Map apiParams = { - 'name': name, - 'runtime': runtime?.value, - 'execute': execute, - 'events': events, - 'schedule': schedule, - 'timeout': timeout, - 'enabled': enabled, - 'logging': logging, - 'entrypoint': entrypoint, - 'commands': commands, - 'scopes': scopes, - 'installationId': installationId, - 'providerRepositoryId': providerRepositoryId, - 'providerBranch': providerBranch, - 'providerSilentMode': providerSilentMode, - 'providerRootDirectory': providerRootDirectory, - 'specification': specification, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - } - - /// Delete function - /// - /// Delete a function by its unique ID. - Future delete({required String functionId}) async { - final String apiPath = - '/functions/{functionId}'.replaceAll('{functionId}', functionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List deployments - /// - /// Get a list of all the project's code deployments. You can use the query - /// params to filter your results. - Future listDeployments( - {required String functionId, - List? queries, - String? search}) async { - final String apiPath = '/functions/{functionId}/deployments' - .replaceAll('{functionId}', functionId); - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.DeploymentList.fromMap(res.data); - } - - /// Create deployment - /// - /// Create a new function code deployment. Use this endpoint to upload a new - /// version of your code function. To execute your newly uploaded code, you'll - /// need to update the function's deployment to use your new deployment UID. - /// - /// This endpoint accepts a tar.gz file compressed with your code. Make sure to - /// include any dependencies your code has within the compressed file. You can - /// learn more about code packaging in the [Appwrite Cloud Functions - /// tutorial](https://appwrite.io/docs/functions). - /// - /// Use the "command" param to set the entrypoint used to execute your code. - Future createDeployment( - {required String functionId, - required Payload code, - required bool activate, - String? entrypoint, - String? commands, - Function(UploadProgress)? onProgress}) async { - final String apiPath = '/functions/{functionId}/deployments' - .replaceAll('{functionId}', functionId); - - final Map apiParams = { - 'entrypoint': entrypoint, - 'commands': commands, - 'code': code, - 'activate': activate, - }; - - final Map apiHeaders = { - 'content-type': 'multipart/form-data', - }; - - String idParamName = ''; - final paramName = 'code'; - final res = await client.chunkedUpload( - path: apiPath, - params: apiParams, - paramName: paramName, - idParamName: idParamName, - headers: apiHeaders, - onProgress: onProgress, - ); - - return models.Deployment.fromMap(res.data); - } - - /// Get deployment - /// - /// Get a code deployment by its unique ID. - Future getDeployment( - {required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Deployment.fromMap(res.data); - } - - /// Update deployment - /// - /// Update the function code deployment ID using the unique function ID. Use - /// this endpoint to switch the code deployment that should be executed by the - /// execution endpoint. - Future updateDeployment( - {required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - } - - /// Delete deployment - /// - /// Delete a code deployment by its unique ID. - Future deleteDeployment( - {required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Rebuild deployment - /// - Future createBuild( - {required String functionId, - required String deploymentId, - String? buildId}) async { - final String apiPath = - '/functions/{functionId}/deployments/{deploymentId}/build' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map apiParams = { - 'buildId': buildId, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Cancel deployment - /// - Future updateDeploymentBuild( - {required String functionId, required String deploymentId}) async { - final String apiPath = - '/functions/{functionId}/deployments/{deploymentId}/build' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Build.fromMap(res.data); - } - - /// Download deployment - /// - /// Get a Deployment's contents by its unique ID. This endpoint supports range - /// requests for partial or streaming file download. - Future getDeploymentDownload( - {required String functionId, required String deploymentId}) async { - final String apiPath = - '/functions/{functionId}/deployments/{deploymentId}/download' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map params = { - 'project': client.config['project'], - 'key': client.config['key'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: params, responseType: ResponseType.bytes); - 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. - Future listExecutions( - {required String functionId, - List? queries, - String? search}) async { - final String apiPath = '/functions/{functionId}/executions' - .replaceAll('{functionId}', functionId); - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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, - Payload? body, - bool? xasync, - String? path, - enums.ExecutionMethod? method, - Map? headers, - String? scheduledAt, - Function(UploadProgress)? onProgress}) async { - final String apiPath = '/functions/{functionId}/executions' - .replaceAll('{functionId}', functionId); - - final Map apiParams = { - 'body': body, - 'async': xasync, - 'path': path, - 'method': method?.value, - 'headers': headers, - 'scheduledAt': scheduledAt, - }; - - final Map apiHeaders = { - 'content-type': 'multipart/form-data', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/functions/{functionId}/executions/{executionId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{executionId}', executionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Execution.fromMap(res.data); - } - - /// Delete execution - /// - /// Delete a function execution by its unique ID. - /// - Future deleteExecution( - {required String functionId, required String executionId}) async { - final String apiPath = '/functions/{functionId}/executions/{executionId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{executionId}', executionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List variables - /// - /// Get a list of all variables of a specific function. - Future listVariables( - {required String functionId}) async { - final String apiPath = '/functions/{functionId}/variables' - .replaceAll('{functionId}', functionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.VariableList.fromMap(res.data); - } - - /// Create variable - /// - /// Create a new function environment variable. These variables can be accessed - /// in the function at runtime as environment variables. - Future createVariable( - {required String functionId, - required String key, - required String value}) async { - final String apiPath = '/functions/{functionId}/variables' - .replaceAll('{functionId}', functionId); - - final Map apiParams = { - 'key': key, - 'value': value, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Variable.fromMap(res.data); - } - - /// Get variable - /// - /// Get a variable by its unique ID. - Future getVariable( - {required String functionId, required String variableId}) async { - final String apiPath = '/functions/{functionId}/variables/{variableId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{variableId}', variableId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Variable.fromMap(res.data); - } - - /// Update variable - /// - /// Update variable by its unique ID. - Future updateVariable( - {required String functionId, - required String variableId, - required String key, - String? value}) async { - final String apiPath = '/functions/{functionId}/variables/{variableId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{variableId}', variableId); - - final Map apiParams = { - 'key': key, - 'value': value, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Variable.fromMap(res.data); - } - - /// Delete variable - /// - /// Delete a variable by its unique ID. - Future deleteVariable( - {required String functionId, required String variableId}) async { - final String apiPath = '/functions/{functionId}/variables/{variableId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{variableId}', variableId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } -} + Functions(super.client); + + /// List functions + /// + /// Get a list of all the project's functions. You can use the query params to + /// filter your results. + Future list({List? queries, String? search}) async { + final String apiPath = '/functions'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.FunctionList.fromMap(res.data); + + } + + /// Create function + /// + /// Create a new function. You can pass a list of + /// [permissions](https://appwrite.io/docs/permissions) to allow different + /// project users or team with access to execute the function using the client + /// API. + Future create({required String functionId, required String name, required enums.Runtime runtime, List? execute, List? events, String? schedule, int? timeout, bool? enabled, bool? logging, String? entrypoint, String? commands, List? scopes, String? installationId, String? providerRepositoryId, String? providerBranch, bool? providerSilentMode, String? providerRootDirectory, String? templateRepository, String? templateOwner, String? templateRootDirectory, String? templateVersion, String? specification}) async { + final String apiPath = '/functions'; + + final Map apiParams = { + + 'functionId': functionId, +'name': name, +'runtime': runtime.value, +'execute': execute, +'events': events, +'schedule': schedule, +'timeout': timeout, +'enabled': enabled, +'logging': logging, +'entrypoint': entrypoint, +'commands': commands, +'scopes': scopes, +'installationId': installationId, +'providerRepositoryId': providerRepositoryId, +'providerBranch': providerBranch, +'providerSilentMode': providerSilentMode, +'providerRootDirectory': providerRootDirectory, +'templateRepository': templateRepository, +'templateOwner': templateOwner, +'templateRootDirectory': templateRootDirectory, +'templateVersion': templateVersion, +'specification': specification, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + + } + + /// List runtimes + /// + /// Get a list of all runtimes that are currently active on your instance. + Future listRuntimes() async { + final String apiPath = '/functions/runtimes'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.RuntimeList.fromMap(res.data); + + } + + /// List available function runtime specifications + /// + /// List allowed function specifications for this instance. + /// + Future listSpecifications() async { + final String apiPath = '/functions/specifications'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SpecificationList.fromMap(res.data); + + } + + /// Get function + /// + /// Get a function by its unique ID. + Future get({required String functionId}) async { + final String apiPath = '/functions/{functionId}'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + + } + + /// Update function + /// + /// Update function by its unique ID. + Future update({required String functionId, required String name, enums.Runtime? runtime, List? execute, List? events, String? schedule, int? timeout, bool? enabled, bool? logging, String? entrypoint, String? commands, List? scopes, String? installationId, String? providerRepositoryId, String? providerBranch, bool? providerSilentMode, String? providerRootDirectory, String? specification}) async { + final String apiPath = '/functions/{functionId}'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + + 'name': name, +'runtime': runtime?.value, +'execute': execute, +'events': events, +'schedule': schedule, +'timeout': timeout, +'enabled': enabled, +'logging': logging, +'entrypoint': entrypoint, +'commands': commands, +'scopes': scopes, +'installationId': installationId, +'providerRepositoryId': providerRepositoryId, +'providerBranch': providerBranch, +'providerSilentMode': providerSilentMode, +'providerRootDirectory': providerRootDirectory, +'specification': specification, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + + } + + /// Delete function + /// + /// Delete a function by its unique ID. + Future delete({required String functionId}) async { + final String apiPath = '/functions/{functionId}'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List deployments + /// + /// Get a list of all the project's code deployments. You can use the query + /// params to filter your results. + Future listDeployments({required String functionId, List? queries, String? search}) async { + final String apiPath = '/functions/{functionId}/deployments'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DeploymentList.fromMap(res.data); + + } + + /// Create deployment + /// + /// Create a new function code deployment. Use this endpoint to upload a new + /// version of your code function. To execute your newly uploaded code, you'll + /// need to update the function's deployment to use your new deployment UID. + /// + /// This endpoint accepts a tar.gz file compressed with your code. Make sure to + /// include any dependencies your code has within the compressed file. You can + /// learn more about code packaging in the [Appwrite Cloud Functions + /// tutorial](https://appwrite.io/docs/functions). + /// + /// Use the "command" param to set the entrypoint used to execute your code. + Future createDeployment({required String functionId, required Payload code, required bool activate, String? entrypoint, String? commands, Function(UploadProgress)? onProgress}) async { + final String apiPath = '/functions/{functionId}/deployments'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + + 'entrypoint': entrypoint, +'commands': commands, +'code': code, +'activate': activate, + + }; + + final Map apiHeaders = { + 'content-type': 'multipart/form-data', + + }; + + String idParamName = ''; + final paramName = 'code'; + final res = await client.chunkedUpload( + path: apiPath, + params: apiParams, + paramName: paramName, + idParamName: idParamName, + headers: apiHeaders, + onProgress: onProgress, + ); + + return models.Deployment.fromMap(res.data); + + } + + /// Get deployment + /// + /// Get a code deployment by its unique ID. + Future getDeployment({required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Deployment.fromMap(res.data); + + } + + /// Update deployment + /// + /// Update the function code deployment ID using the unique function ID. Use + /// this endpoint to switch the code deployment that should be executed by the + /// execution endpoint. + Future updateDeployment({required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + + } + + /// Delete deployment + /// + /// Delete a code deployment by its unique ID. + Future deleteDeployment({required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Rebuild deployment + /// + Future createBuild({required String functionId, required String deploymentId, String? buildId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}/build'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map apiParams = { + + 'buildId': buildId, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Cancel deployment + /// + Future updateDeploymentBuild({required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}/build'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Build.fromMap(res.data); + + } + + /// Download deployment + /// + /// Get a Deployment's contents by its unique ID. This endpoint supports range + /// requests for partial or streaming file download. + Future getDeploymentDownload({required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}/download'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map params = { + + + 'project': client.config['project'], + 'key': client.config['key'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: params, responseType: ResponseType.bytes); + 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. + Future listExecutions({required String functionId, List? queries, String? search}) async { + final String apiPath = '/functions/{functionId}/executions'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + 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, Payload? body, bool? xasync, String? path, enums.ExecutionMethod? method, Map? headers, String? scheduledAt, Function(UploadProgress)? onProgress}) async { + final String apiPath = '/functions/{functionId}/executions'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + + 'body': body, +'async': xasync, +'path': path, +'method': method?.value, +'headers': headers, +'scheduledAt': scheduledAt, + + }; + + final Map apiHeaders = { + 'content-type': 'multipart/form-data', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/functions/{functionId}/executions/{executionId}'.replaceAll('{functionId}', functionId).replaceAll('{executionId}', executionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Execution.fromMap(res.data); + + } + + /// Delete execution + /// + /// Delete a function execution by its unique ID. + /// + Future deleteExecution({required String functionId, required String executionId}) async { + final String apiPath = '/functions/{functionId}/executions/{executionId}'.replaceAll('{functionId}', functionId).replaceAll('{executionId}', executionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List variables + /// + /// Get a list of all variables of a specific function. + Future listVariables({required String functionId}) async { + final String apiPath = '/functions/{functionId}/variables'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.VariableList.fromMap(res.data); + + } + + /// Create variable + /// + /// Create a new function environment variable. These variables can be accessed + /// in the function at runtime as environment variables. + Future createVariable({required String functionId, required String key, required String value}) async { + final String apiPath = '/functions/{functionId}/variables'.replaceAll('{functionId}', functionId); + + final Map apiParams = { + + 'key': key, +'value': value, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Variable.fromMap(res.data); + + } + + /// Get variable + /// + /// Get a variable by its unique ID. + Future getVariable({required String functionId, required String variableId}) async { + final String apiPath = '/functions/{functionId}/variables/{variableId}'.replaceAll('{functionId}', functionId).replaceAll('{variableId}', variableId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Variable.fromMap(res.data); + + } + + /// Update variable + /// + /// Update variable by its unique ID. + Future updateVariable({required String functionId, required String variableId, required String key, String? value}) async { + final String apiPath = '/functions/{functionId}/variables/{variableId}'.replaceAll('{functionId}', functionId).replaceAll('{variableId}', variableId); + + final Map apiParams = { + + 'key': key, +'value': value, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Variable.fromMap(res.data); + + } + + /// Delete variable + /// + /// Delete a variable by its unique ID. + Future deleteVariable({required String functionId, required String variableId}) async { + final String apiPath = '/functions/{functionId}/variables/{variableId}'.replaceAll('{functionId}', functionId).replaceAll('{variableId}', variableId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } +} \ No newline at end of file diff --git a/lib/services/graphql.dart b/lib/services/graphql.dart index fdc1ae0b..be9d037b 100644 --- a/lib/services/graphql.dart +++ b/lib/services/graphql.dart @@ -3,47 +3,53 @@ part of '../dart_appwrite.dart'; /// The GraphQL API allows you to query and mutate your Appwrite server using /// GraphQL. class Graphql extends Service { - Graphql(super.client); - - /// GraphQL endpoint - /// - /// Execute a GraphQL mutation. - Future query({required Map query}) async { - final String apiPath = '/graphql'; - - final Map apiParams = { - 'query': query, - }; - - final Map apiHeaders = { - 'x-sdk-graphql': 'true', - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// GraphQL endpoint - /// - /// Execute a GraphQL mutation. - Future mutation({required Map query}) async { - final String apiPath = '/graphql/mutation'; - - final Map apiParams = { - 'query': query, - }; - - final Map apiHeaders = { - 'x-sdk-graphql': 'true', - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } -} + Graphql(super.client); + + /// GraphQL endpoint + /// + /// Execute a GraphQL mutation. + Future query({required Map query}) async { + final String apiPath = '/graphql'; + + final Map apiParams = { + + 'query': query, + + }; + + final Map apiHeaders = { + 'x-sdk-graphql': 'true', +'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// GraphQL endpoint + /// + /// Execute a GraphQL mutation. + Future mutation({required Map query}) async { + final String apiPath = '/graphql/mutation'; + + final Map apiParams = { + + 'query': query, + + }; + + final Map apiHeaders = { + 'x-sdk-graphql': 'true', +'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } +} \ No newline at end of file diff --git a/lib/services/health.dart b/lib/services/health.dart index 121083c0..4e7b4603 100644 --- a/lib/services/health.dart +++ b/lib/services/health.dart @@ -3,473 +3,548 @@ part of '../dart_appwrite.dart'; /// The Health service allows you to both validate and monitor your Appwrite /// server's health. class Health extends Service { - Health(super.client); + Health(super.client); - /// Get HTTP - /// - /// Check the Appwrite HTTP server is up and responsive. - Future get() async { - final String apiPath = '/health'; + /// Get HTTP + /// + /// Check the Appwrite HTTP server is up and responsive. + Future get() async { + final String apiPath = '/health'; - final Map apiParams = {}; + final Map apiParams = { + + + }; - final Map apiHeaders = { - 'content-type': 'application/json', - }; + final Map apiHeaders = { + 'content-type': 'application/json', - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + }; - return models.HealthStatus.fromMap(res.data); - } + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - /// Get antivirus - /// - /// Check the Appwrite Antivirus server is up and connection is successful. - Future getAntivirus() async { - final String apiPath = '/health/anti-virus'; + return models.HealthStatus.fromMap(res.data); - final Map apiParams = {}; + } - final Map apiHeaders = { - 'content-type': 'application/json', - }; + /// Get antivirus + /// + /// Check the Appwrite Antivirus server is up and connection is successful. + Future getAntivirus() async { + final String apiPath = '/health/anti-virus'; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + final Map apiParams = { + + + }; - return models.HealthAntivirus.fromMap(res.data); - } + final Map apiHeaders = { + 'content-type': 'application/json', - /// Get cache - /// - /// Check the Appwrite in-memory cache servers are up and connection is - /// successful. - Future getCache() async { - final String apiPath = '/health/cache'; + }; - final Map apiParams = {}; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final Map apiHeaders = { - 'content-type': 'application/json', - }; + return models.HealthAntivirus.fromMap(res.data); - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + } - return models.HealthStatus.fromMap(res.data); - } + /// Get cache + /// + /// Check the Appwrite in-memory cache servers are up and connection is + /// successful. + Future getCache() async { + final String apiPath = '/health/cache'; - /// Get the SSL certificate for a domain - /// - /// Get the SSL certificate for a domain - Future getCertificate({String? domain}) async { - final String apiPath = '/health/certificate'; + final Map apiParams = { + + + }; - final Map apiParams = { - 'domain': domain, - }; + final Map apiHeaders = { + 'content-type': 'application/json', - final Map apiHeaders = { - 'content-type': 'application/json', - }; + }; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - return models.HealthCertificate.fromMap(res.data); - } + return models.HealthStatus.fromMap(res.data); - /// Get DB - /// - /// Check the Appwrite database servers are up and connection is successful. - Future getDB() async { - final String apiPath = '/health/db'; + } - final Map apiParams = {}; + /// Get the SSL certificate for a domain + /// + /// Get the SSL certificate for a domain + Future getCertificate({String? domain}) async { + final String apiPath = '/health/certificate'; - final Map apiHeaders = { - 'content-type': 'application/json', - }; + final Map apiParams = { + 'domain': domain, - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + + }; - return models.HealthStatus.fromMap(res.data); - } + final Map apiHeaders = { + 'content-type': 'application/json', - /// Get pubsub - /// - /// Check the Appwrite pub-sub servers are up and connection is successful. - Future getPubSub() async { - final String apiPath = '/health/pubsub'; + }; - final Map apiParams = {}; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final Map apiHeaders = { - 'content-type': 'application/json', - }; + return models.HealthCertificate.fromMap(res.data); - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + } - return models.HealthStatus.fromMap(res.data); - } + /// Get DB + /// + /// Check the Appwrite database servers are up and connection is successful. + Future getDB() async { + final String apiPath = '/health/db'; - /// Get queue - /// - /// Check the Appwrite queue messaging servers are up and connection is - /// successful. - Future getQueue() async { - final String apiPath = '/health/queue'; + final Map apiParams = { + + + }; - final Map apiParams = {}; + final Map apiHeaders = { + 'content-type': 'application/json', - final Map apiHeaders = { - 'content-type': 'application/json', - }; + }; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthStatus.fromMap(res.data); - } + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - /// Get builds queue - /// - /// Get the number of builds that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueBuilds({int? threshold}) async { - final String apiPath = '/health/queue/builds'; - - final Map apiParams = { - 'threshold': threshold, - }; + return models.HealthStatus.fromMap(res.data); - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get certificates queue - /// - /// Get the number of certificates that are waiting to be issued against - /// [Letsencrypt](https://letsencrypt.org/) in the Appwrite internal queue - /// server. - Future getQueueCertificates({int? threshold}) async { - final String apiPath = '/health/queue/certificates'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get databases queue - /// - /// Get the number of database changes that are waiting to be processed in the - /// Appwrite internal queue server. - Future getQueueDatabases( - {String? name, int? threshold}) async { - final String apiPath = '/health/queue/databases'; - - final Map apiParams = { - 'name': name, - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get deletes queue - /// - /// Get the number of background destructive changes that are waiting to be - /// processed in the Appwrite internal queue server. - Future getQueueDeletes({int? threshold}) async { - final String apiPath = '/health/queue/deletes'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get number of failed queue jobs - /// - /// Returns the amount of failed jobs in a given queue. - /// - Future getFailedJobs( - {required enums.Name name, int? threshold}) async { - final String apiPath = - '/health/queue/failed/{name}'.replaceAll('{name}', name.value); - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get functions queue - /// - /// Get the number of function executions that are waiting to be processed in - /// the Appwrite internal queue server. - Future getQueueFunctions({int? threshold}) async { - final String apiPath = '/health/queue/functions'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get logs queue - /// - /// Get the number of logs that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueLogs({int? threshold}) async { - final String apiPath = '/health/queue/logs'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get mails queue - /// - /// Get the number of mails that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueMails({int? threshold}) async { - final String apiPath = '/health/queue/mails'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get messaging queue - /// - /// Get the number of messages that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueMessaging({int? threshold}) async { - final String apiPath = '/health/queue/messaging'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get migrations queue - /// - /// Get the number of migrations that are waiting to be processed in the - /// Appwrite internal queue server. - Future getQueueMigrations({int? threshold}) async { - final String apiPath = '/health/queue/migrations'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } + } - /// Get usage queue - /// - /// Get the number of metrics that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueUsage({int? threshold}) async { - final String apiPath = '/health/queue/usage'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get usage dump queue - /// - /// Get the number of projects containing metrics that are waiting to be - /// processed in the Appwrite internal queue server. - Future getQueueUsageDump({int? threshold}) async { - final String apiPath = '/health/queue/usage-dump'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get webhooks queue - /// - /// Get the number of webhooks that are waiting to be processed in the Appwrite - /// internal queue server. - Future getQueueWebhooks({int? threshold}) async { - final String apiPath = '/health/queue/webhooks'; - - final Map apiParams = { - 'threshold': threshold, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get storage - /// - /// Check the Appwrite storage device is up and connection is successful. - Future getStorage() async { - final String apiPath = '/health/storage'; + /// Get pubsub + /// + /// Check the Appwrite pub-sub servers are up and connection is successful. + Future getPubSub() async { + final String apiPath = '/health/pubsub'; - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthStatus.fromMap(res.data); - } - - /// Get local storage - /// - /// Check the Appwrite local storage device is up and connection is successful. - Future getStorageLocal() async { - final String apiPath = '/health/storage/local'; - - final Map apiParams = {}; + final Map apiParams = { + + + }; - final Map apiHeaders = { - 'content-type': 'application/json', - }; + final Map apiHeaders = { + 'content-type': 'application/json', - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthStatus.fromMap(res.data); - } - - /// Get time - /// - /// Check the Appwrite server time is synced with Google remote NTP server. We - /// use this technology to smoothly handle leap seconds with no disruptive - /// events. The [Network Time - /// Protocol](https://en.wikipedia.org/wiki/Network_Time_Protocol) (NTP) is - /// used by hundreds of millions of computers and devices to synchronize their - /// clocks over the Internet. If your computer sets its own clock, it likely - /// uses NTP. - Future getTime() async { - final String apiPath = '/health/time'; + }; - final Map apiParams = {}; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final Map apiHeaders = { - 'content-type': 'application/json', - }; + return models.HealthStatus.fromMap(res.data); - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthTime.fromMap(res.data); - } -} + } + + /// Get queue + /// + /// Check the Appwrite queue messaging servers are up and connection is + /// successful. + Future getQueue() async { + final String apiPath = '/health/queue'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthStatus.fromMap(res.data); + + } + + /// Get builds queue + /// + /// Get the number of builds that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueBuilds({int? threshold}) async { + final String apiPath = '/health/queue/builds'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get certificates queue + /// + /// Get the number of certificates that are waiting to be issued against + /// [Letsencrypt](https://letsencrypt.org/) in the Appwrite internal queue + /// server. + Future getQueueCertificates({int? threshold}) async { + final String apiPath = '/health/queue/certificates'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get databases queue + /// + /// Get the number of database changes that are waiting to be processed in the + /// Appwrite internal queue server. + Future getQueueDatabases({String? name, int? threshold}) async { + final String apiPath = '/health/queue/databases'; + + final Map apiParams = { + 'name': name, +'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get deletes queue + /// + /// Get the number of background destructive changes that are waiting to be + /// processed in the Appwrite internal queue server. + Future getQueueDeletes({int? threshold}) async { + final String apiPath = '/health/queue/deletes'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get number of failed queue jobs + /// + /// Returns the amount of failed jobs in a given queue. + /// + Future getFailedJobs({required enums.Name name, int? threshold}) async { + final String apiPath = '/health/queue/failed/{name}'.replaceAll('{name}', name.value); + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get functions queue + /// + /// Get the number of function executions that are waiting to be processed in + /// the Appwrite internal queue server. + Future getQueueFunctions({int? threshold}) async { + final String apiPath = '/health/queue/functions'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get logs queue + /// + /// Get the number of logs that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueLogs({int? threshold}) async { + final String apiPath = '/health/queue/logs'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get mails queue + /// + /// Get the number of mails that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueMails({int? threshold}) async { + final String apiPath = '/health/queue/mails'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get messaging queue + /// + /// Get the number of messages that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueMessaging({int? threshold}) async { + final String apiPath = '/health/queue/messaging'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get migrations queue + /// + /// Get the number of migrations that are waiting to be processed in the + /// Appwrite internal queue server. + Future getQueueMigrations({int? threshold}) async { + final String apiPath = '/health/queue/migrations'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get usage queue + /// + /// Get the number of metrics that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueUsage({int? threshold}) async { + final String apiPath = '/health/queue/usage'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get usage dump queue + /// + /// Get the number of projects containing metrics that are waiting to be + /// processed in the Appwrite internal queue server. + Future getQueueUsageDump({int? threshold}) async { + final String apiPath = '/health/queue/usage-dump'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get webhooks queue + /// + /// Get the number of webhooks that are waiting to be processed in the Appwrite + /// internal queue server. + Future getQueueWebhooks({int? threshold}) async { + final String apiPath = '/health/queue/webhooks'; + + final Map apiParams = { + 'threshold': threshold, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get storage + /// + /// Check the Appwrite storage device is up and connection is successful. + Future getStorage() async { + final String apiPath = '/health/storage'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthStatus.fromMap(res.data); + + } + + /// Get local storage + /// + /// Check the Appwrite local storage device is up and connection is successful. + Future getStorageLocal() async { + final String apiPath = '/health/storage/local'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthStatus.fromMap(res.data); + + } + + /// Get time + /// + /// Check the Appwrite server time is synced with Google remote NTP server. We + /// use this technology to smoothly handle leap seconds with no disruptive + /// events. The [Network Time + /// Protocol](https://en.wikipedia.org/wiki/Network_Time_Protocol) (NTP) is + /// used by hundreds of millions of computers and devices to synchronize their + /// clocks over the Internet. If your computer sets its own clock, it likely + /// uses NTP. + Future getTime() async { + final String apiPath = '/health/time'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthTime.fromMap(res.data); + + } +} \ No newline at end of file diff --git a/lib/services/locale.dart b/lib/services/locale.dart index b287c8e9..cf65a2f3 100644 --- a/lib/services/locale.dart +++ b/lib/services/locale.dart @@ -3,162 +3,194 @@ part of '../dart_appwrite.dart'; /// The Locale service allows you to customize your app based on your users' /// location. class Locale extends Service { - Locale(super.client); + Locale(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 { - final String apiPath = '/locale'; + /// 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 { + final String apiPath = '/locale'; - final Map apiParams = {}; + final Map apiParams = { + + + }; - final Map apiHeaders = { - 'content-type': 'application/json', - }; + final Map apiHeaders = { + 'content-type': 'application/json', - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + }; - return models.Locale.fromMap(res.data); - } + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - /// List Locale Codes - /// - /// List of all locale codes in [ISO - /// 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). - Future listCodes() async { - final String apiPath = '/locale/codes'; + return models.Locale.fromMap(res.data); - final Map apiParams = {}; + } - final Map apiHeaders = { - 'content-type': 'application/json', - }; + /// List locale codes + /// + /// List of all locale codes in [ISO + /// 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). + Future listCodes() async { + final String apiPath = '/locale/codes'; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + final Map apiParams = { + + + }; - return models.LocaleCodeList.fromMap(res.data); - } + final Map apiHeaders = { + 'content-type': 'application/json', - /// List continents - /// - /// List of all continents. You can use the locale header to get the data in a - /// supported language. - Future listContinents() async { - final String apiPath = '/locale/continents'; + }; - final Map apiParams = {}; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final Map apiHeaders = { - 'content-type': 'application/json', - }; + return models.LocaleCodeList.fromMap(res.data); - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + } - return models.ContinentList.fromMap(res.data); - } + /// List continents + /// + /// List of all continents. You can use the locale header to get the data in a + /// supported language. + Future listContinents() async { + final String apiPath = '/locale/continents'; - /// List countries - /// - /// List of all countries. You can use the locale header to get the data in a - /// supported language. - Future listCountries() async { - final String apiPath = '/locale/countries'; + final Map apiParams = { + + + }; - final Map apiParams = {}; + final Map apiHeaders = { + 'content-type': 'application/json', - final Map apiHeaders = { - 'content-type': 'application/json', - }; + }; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - return models.CountryList.fromMap(res.data); - } + return models.ContinentList.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 listCountriesEU() async { - final String apiPath = '/locale/countries/eu'; + } - final Map apiParams = {}; + /// List countries + /// + /// List of all countries. You can use the locale header to get the data in a + /// supported language. + Future listCountries() async { + final String apiPath = '/locale/countries'; - final Map apiHeaders = { - 'content-type': 'application/json', - }; + final Map apiParams = { + + + }; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + final Map apiHeaders = { + 'content-type': 'application/json', - 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 listCountriesPhones() async { - final String apiPath = '/locale/countries/phones'; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final Map apiParams = {}; + return models.CountryList.fromMap(res.data); - final Map apiHeaders = { - 'content-type': 'application/json', - }; + } - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + /// 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 listCountriesEU() async { + final String apiPath = '/locale/countries/eu'; - return models.PhoneList.fromMap(res.data); - } + final Map apiParams = { + + + }; - /// 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 listCurrencies() async { - final String apiPath = '/locale/currencies'; + final Map apiHeaders = { + 'content-type': 'application/json', - final Map apiParams = {}; + }; - final Map apiHeaders = { - 'content-type': 'application/json', - }; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + return models.CountryList.fromMap(res.data); - 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 listLanguages() async { - final String apiPath = '/locale/languages'; + /// 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 listCountriesPhones() async { + final String apiPath = '/locale/countries/phones'; - final Map apiParams = {}; + final Map apiParams = { + + + }; - final Map apiHeaders = { - 'content-type': 'application/json', - }; + final Map apiHeaders = { + 'content-type': 'application/json', - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + }; - return models.LanguageList.fromMap(res.data); - } -} + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 listCurrencies() async { + final String apiPath = '/locale/currencies'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.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 listLanguages() async { + final String apiPath = '/locale/languages'; + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LanguageList.fromMap(res.data); + + } +} \ No newline at end of file diff --git a/lib/services/messaging.dart b/lib/services/messaging.dart index ecde5409..e88b18f5 100644 --- a/lib/services/messaging.dart +++ b/lib/services/messaging.dart @@ -3,1374 +3,1251 @@ part of '../dart_appwrite.dart'; /// The Messaging service allows you to send messages to any provider type /// (SMTP, push notification, SMS, etc.). class Messaging extends Service { - Messaging(super.client); - - /// List messages - /// - /// Get a list of all messages from the current Appwrite project. - Future listMessages( - {List? queries, String? search}) async { - final String apiPath = '/messaging/messages'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MessageList.fromMap(res.data); - } - - /// Create email - /// - /// Create a new email message. - Future createEmail( - {required String messageId, - required String subject, - required String content, - List? topics, - List? users, - List? targets, - List? cc, - List? bcc, - List? attachments, - bool? draft, - bool? html, - String? scheduledAt}) async { - final String apiPath = '/messaging/messages/email'; - - final Map apiParams = { - 'messageId': messageId, - 'subject': subject, - 'content': content, - 'topics': topics, - 'users': users, - 'targets': targets, - 'cc': cc, - 'bcc': bcc, - 'attachments': attachments, - 'draft': draft, - 'html': html, - 'scheduledAt': scheduledAt, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Update email - /// - /// Update an email message by its unique ID. - /// - Future updateEmail( - {required String messageId, - List? topics, - List? users, - List? targets, - String? subject, - String? content, - bool? draft, - bool? html, - List? cc, - List? bcc, - String? scheduledAt, - List? attachments}) async { - final String apiPath = '/messaging/messages/email/{messageId}' - .replaceAll('{messageId}', messageId); - - final Map apiParams = { - 'topics': topics, - 'users': users, - 'targets': targets, - 'subject': subject, - 'content': content, - 'draft': draft, - 'html': html, - 'cc': cc, - 'bcc': bcc, - 'scheduledAt': scheduledAt, - 'attachments': attachments, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Create push notification - /// - /// Create a new push notification. - Future createPush( - {required String messageId, - required String title, - required String body, - List? topics, - List? users, - List? targets, - Map? data, - String? action, - String? image, - String? icon, - String? sound, - String? color, - String? tag, - String? badge, - bool? draft, - String? scheduledAt}) async { - final String apiPath = '/messaging/messages/push'; - - final Map apiParams = { - 'messageId': messageId, - 'title': title, - 'body': body, - 'topics': topics, - 'users': users, - 'targets': targets, - 'data': data, - 'action': action, - 'image': image, - 'icon': icon, - 'sound': sound, - 'color': color, - 'tag': tag, - 'badge': badge, - 'draft': draft, - 'scheduledAt': scheduledAt, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Update push notification - /// - /// Update a push notification by its unique ID. - /// - Future updatePush( - {required String messageId, - List? topics, - List? users, - List? targets, - String? title, - String? body, - Map? data, - String? action, - String? image, - String? icon, - String? sound, - String? color, - String? tag, - int? badge, - bool? draft, - String? scheduledAt}) async { - final String apiPath = '/messaging/messages/push/{messageId}' - .replaceAll('{messageId}', messageId); - - final Map apiParams = { - 'topics': topics, - 'users': users, - 'targets': targets, - 'title': title, - 'body': body, - 'data': data, - 'action': action, - 'image': image, - 'icon': icon, - 'sound': sound, - 'color': color, - 'tag': tag, - 'badge': badge, - 'draft': draft, - 'scheduledAt': scheduledAt, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Create SMS - /// - /// Create a new SMS message. - Future createSms( - {required String messageId, - required String content, - List? topics, - List? users, - List? targets, - bool? draft, - String? scheduledAt}) async { - final String apiPath = '/messaging/messages/sms'; - - final Map apiParams = { - 'messageId': messageId, - 'content': content, - 'topics': topics, - 'users': users, - 'targets': targets, - 'draft': draft, - 'scheduledAt': scheduledAt, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Update SMS - /// - /// Update an email message by its unique ID. - /// - Future updateSms( - {required String messageId, - List? topics, - List? users, - List? targets, - String? content, - bool? draft, - String? scheduledAt}) async { - final String apiPath = '/messaging/messages/sms/{messageId}' - .replaceAll('{messageId}', messageId); - - final Map apiParams = { - 'topics': topics, - 'users': users, - 'targets': targets, - 'content': content, - 'draft': draft, - 'scheduledAt': scheduledAt, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Get message - /// - /// Get a message by its unique ID. - /// - Future getMessage({required String messageId}) async { - final String apiPath = - '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Delete message - /// - /// Delete a message. If the message is not a draft or scheduled, but has been - /// sent, this will not recall the message. - Future delete({required String messageId}) async { - final String apiPath = - '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List message logs - /// - /// Get the message activity logs listed by its unique ID. - Future listMessageLogs( - {required String messageId, List? queries}) async { - final String apiPath = '/messaging/messages/{messageId}/logs' - .replaceAll('{messageId}', messageId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// List message targets - /// - /// Get a list of the targets associated with a message. - Future listTargets( - {required String messageId, List? queries}) async { - final String apiPath = '/messaging/messages/{messageId}/targets' - .replaceAll('{messageId}', messageId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.TargetList.fromMap(res.data); - } - - /// List providers - /// - /// Get a list of all providers from the current Appwrite project. - Future listProviders( - {List? queries, String? search}) async { - final String apiPath = '/messaging/providers'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.ProviderList.fromMap(res.data); - } - - /// Create APNS provider - /// - /// Create a new Apple Push Notification service provider. - Future createApnsProvider( - {required String providerId, - required String name, - String? authKey, - String? authKeyId, - String? teamId, - String? bundleId, - bool? sandbox, - bool? enabled}) async { - final String apiPath = '/messaging/providers/apns'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'authKey': authKey, - 'authKeyId': authKeyId, - 'teamId': teamId, - 'bundleId': bundleId, - 'sandbox': sandbox, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update APNS provider - /// - /// Update a Apple Push Notification service provider by its unique ID. - Future updateApnsProvider( - {required String providerId, - String? name, - bool? enabled, - String? authKey, - String? authKeyId, - String? teamId, - String? bundleId, - bool? sandbox}) async { - final String apiPath = '/messaging/providers/apns/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - 'authKey': authKey, - 'authKeyId': authKeyId, - 'teamId': teamId, - 'bundleId': bundleId, - 'sandbox': sandbox, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create FCM provider - /// - /// Create a new Firebase Cloud Messaging provider. - Future createFcmProvider( - {required String providerId, - required String name, - Map? serviceAccountJSON, - bool? enabled}) async { - final String apiPath = '/messaging/providers/fcm'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'serviceAccountJSON': serviceAccountJSON, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update FCM provider - /// - /// Update a Firebase Cloud Messaging provider by its unique ID. - Future updateFcmProvider( - {required String providerId, - String? name, - bool? enabled, - Map? serviceAccountJSON}) async { - final String apiPath = '/messaging/providers/fcm/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - 'serviceAccountJSON': serviceAccountJSON, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Mailgun provider - /// - /// Create a new Mailgun provider. - Future createMailgunProvider( - {required String providerId, - required String name, - String? apiKey, - String? domain, - bool? isEuRegion, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail, - bool? enabled}) async { - final String apiPath = '/messaging/providers/mailgun'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'apiKey': apiKey, - 'domain': domain, - 'isEuRegion': isEuRegion, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Mailgun provider - /// - /// Update a Mailgun provider by its unique ID. - Future updateMailgunProvider( - {required String providerId, - String? name, - String? apiKey, - String? domain, - bool? isEuRegion, - bool? enabled, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail}) async { - final String apiPath = '/messaging/providers/mailgun/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'apiKey': apiKey, - 'domain': domain, - 'isEuRegion': isEuRegion, - 'enabled': enabled, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Msg91 provider - /// - /// Create a new MSG91 provider. - Future createMsg91Provider( - {required String providerId, - required String name, - String? templateId, - String? senderId, - String? authKey, - bool? enabled}) async { - final String apiPath = '/messaging/providers/msg91'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'templateId': templateId, - 'senderId': senderId, - 'authKey': authKey, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Msg91 provider - /// - /// Update a MSG91 provider by its unique ID. - Future updateMsg91Provider( - {required String providerId, - String? name, - bool? enabled, - String? templateId, - String? senderId, - String? authKey}) async { - final String apiPath = '/messaging/providers/msg91/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - 'templateId': templateId, - 'senderId': senderId, - 'authKey': authKey, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Sendgrid provider - /// - /// Create a new Sendgrid provider. - Future createSendgridProvider( - {required String providerId, - required String name, - String? apiKey, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail, - bool? enabled}) async { - final String apiPath = '/messaging/providers/sendgrid'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'apiKey': apiKey, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Sendgrid provider - /// - /// Update a Sendgrid provider by its unique ID. - Future updateSendgridProvider( - {required String providerId, - String? name, - bool? enabled, - String? apiKey, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail}) async { - final String apiPath = '/messaging/providers/sendgrid/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - 'apiKey': apiKey, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create SMTP provider - /// - /// Create a new SMTP provider. - Future createSmtpProvider( - {required String providerId, - required String name, - required String host, - int? port, - String? username, - String? password, - enums.SmtpEncryption? encryption, - bool? autoTLS, - String? mailer, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail, - bool? enabled}) async { - final String apiPath = '/messaging/providers/smtp'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'host': host, - 'port': port, - 'username': username, - 'password': password, - 'encryption': encryption?.value, - 'autoTLS': autoTLS, - 'mailer': mailer, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update SMTP provider - /// - /// Update a SMTP provider by its unique ID. - Future updateSmtpProvider( - {required String providerId, - String? name, - String? host, - int? port, - String? username, - String? password, - enums.SmtpEncryption? encryption, - bool? autoTLS, - String? mailer, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail, - bool? enabled}) async { - final String apiPath = '/messaging/providers/smtp/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'host': host, - 'port': port, - 'username': username, - 'password': password, - 'encryption': encryption?.value, - 'autoTLS': autoTLS, - 'mailer': mailer, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Telesign provider - /// - /// Create a new Telesign provider. - Future createTelesignProvider( - {required String providerId, - required String name, - String? from, - String? customerId, - String? apiKey, - bool? enabled}) async { - final String apiPath = '/messaging/providers/telesign'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'from': from, - 'customerId': customerId, - 'apiKey': apiKey, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Telesign provider - /// - /// Update a Telesign provider by its unique ID. - Future updateTelesignProvider( - {required String providerId, - String? name, - bool? enabled, - String? customerId, - String? apiKey, - String? from}) async { - final String apiPath = '/messaging/providers/telesign/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - 'customerId': customerId, - 'apiKey': apiKey, - 'from': from, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Textmagic provider - /// - /// Create a new Textmagic provider. - Future createTextmagicProvider( - {required String providerId, - required String name, - String? from, - String? username, - String? apiKey, - bool? enabled}) async { - final String apiPath = '/messaging/providers/textmagic'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'from': from, - 'username': username, - 'apiKey': apiKey, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Textmagic provider - /// - /// Update a Textmagic provider by its unique ID. - Future updateTextmagicProvider( - {required String providerId, - String? name, - bool? enabled, - String? username, - String? apiKey, - String? from}) async { - final String apiPath = '/messaging/providers/textmagic/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - 'username': username, - 'apiKey': apiKey, - 'from': from, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Twilio provider - /// - /// Create a new Twilio provider. - Future createTwilioProvider( - {required String providerId, - required String name, - String? from, - String? accountSid, - String? authToken, - bool? enabled}) async { - final String apiPath = '/messaging/providers/twilio'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'from': from, - 'accountSid': accountSid, - 'authToken': authToken, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Twilio provider - /// - /// Update a Twilio provider by its unique ID. - Future updateTwilioProvider( - {required String providerId, - String? name, - bool? enabled, - String? accountSid, - String? authToken, - String? from}) async { - final String apiPath = '/messaging/providers/twilio/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - 'accountSid': accountSid, - 'authToken': authToken, - 'from': from, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Vonage provider - /// - /// Create a new Vonage provider. - Future createVonageProvider( - {required String providerId, - required String name, - String? from, - String? apiKey, - String? apiSecret, - bool? enabled}) async { - final String apiPath = '/messaging/providers/vonage'; - - final Map apiParams = { - 'providerId': providerId, - 'name': name, - 'from': from, - 'apiKey': apiKey, - 'apiSecret': apiSecret, - 'enabled': enabled, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Vonage provider - /// - /// Update a Vonage provider by its unique ID. - Future updateVonageProvider( - {required String providerId, - String? name, - bool? enabled, - String? apiKey, - String? apiSecret, - String? from}) async { - final String apiPath = '/messaging/providers/vonage/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'name': name, - 'enabled': enabled, - 'apiKey': apiKey, - 'apiSecret': apiSecret, - 'from': from, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Get provider - /// - /// Get a provider by its unique ID. - /// - Future getProvider({required String providerId}) async { - final String apiPath = '/messaging/providers/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Delete provider - /// - /// Delete a provider by its unique ID. - Future deleteProvider({required String providerId}) async { - final String apiPath = '/messaging/providers/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List provider logs - /// - /// Get the provider activity logs listed by its unique ID. - Future listProviderLogs( - {required String providerId, List? queries}) async { - final String apiPath = '/messaging/providers/{providerId}/logs' - .replaceAll('{providerId}', providerId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// List subscriber logs - /// - /// Get the subscriber activity logs listed by its unique ID. - Future listSubscriberLogs( - {required String subscriberId, List? queries}) async { - final String apiPath = '/messaging/subscribers/{subscriberId}/logs' - .replaceAll('{subscriberId}', subscriberId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// List topics - /// - /// Get a list of all topics from the current Appwrite project. - Future listTopics( - {List? queries, String? search}) async { - final String apiPath = '/messaging/topics'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.TopicList.fromMap(res.data); - } - - /// Create topic - /// - /// Create a new topic. - Future createTopic( - {required String topicId, - required String name, - List? subscribe}) async { - final String apiPath = '/messaging/topics'; - - final Map apiParams = { - 'topicId': topicId, - 'name': name, - 'subscribe': subscribe, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Topic.fromMap(res.data); - } - - /// Get topic - /// - /// Get a topic by its unique ID. - /// - Future getTopic({required String topicId}) async { - final String apiPath = - '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Topic.fromMap(res.data); - } - - /// Update topic - /// - /// Update a topic by its unique ID. - /// - Future updateTopic( - {required String topicId, String? name, List? subscribe}) async { - final String apiPath = - '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); - - final Map apiParams = { - 'name': name, - 'subscribe': subscribe, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Topic.fromMap(res.data); - } - - /// Delete topic - /// - /// Delete a topic by its unique ID. - Future deleteTopic({required String topicId}) async { - final String apiPath = - '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List topic logs - /// - /// Get the topic activity logs listed by its unique ID. - Future listTopicLogs( - {required String topicId, List? queries}) async { - final String apiPath = - '/messaging/topics/{topicId}/logs'.replaceAll('{topicId}', topicId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// List subscribers - /// - /// Get a list of all subscribers from the current Appwrite project. - Future listSubscribers( - {required String topicId, List? queries, String? search}) async { - final String apiPath = '/messaging/topics/{topicId}/subscribers' - .replaceAll('{topicId}', topicId); - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SubscriberList.fromMap(res.data); - } - - /// Create subscriber - /// - /// Create a new subscriber. - Future createSubscriber( - {required String topicId, - required String subscriberId, - required String targetId}) async { - final String apiPath = '/messaging/topics/{topicId}/subscribers' - .replaceAll('{topicId}', topicId); - - final Map apiParams = { - 'subscriberId': subscriberId, - 'targetId': targetId, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Subscriber.fromMap(res.data); - } - - /// Get subscriber - /// - /// Get a subscriber by its unique ID. - /// - Future getSubscriber( - {required String topicId, required String subscriberId}) async { - final String apiPath = - '/messaging/topics/{topicId}/subscribers/{subscriberId}' - .replaceAll('{topicId}', topicId) - .replaceAll('{subscriberId}', subscriberId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Subscriber.fromMap(res.data); - } - - /// Delete subscriber - /// - /// Delete a subscriber by its unique ID. - Future deleteSubscriber( - {required String topicId, required String subscriberId}) async { - final String apiPath = - '/messaging/topics/{topicId}/subscribers/{subscriberId}' - .replaceAll('{topicId}', topicId) - .replaceAll('{subscriberId}', subscriberId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } -} + Messaging(super.client); + + /// List messages + /// + /// Get a list of all messages from the current Appwrite project. + Future listMessages({List? queries, String? search}) async { + final String apiPath = '/messaging/messages'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MessageList.fromMap(res.data); + + } + + /// Create email + /// + /// Create a new email message. + Future createEmail({required String messageId, required String subject, required String content, List? topics, List? users, List? targets, List? cc, List? bcc, List? attachments, bool? draft, bool? html, String? scheduledAt}) async { + final String apiPath = '/messaging/messages/email'; + + final Map apiParams = { + + 'messageId': messageId, +'subject': subject, +'content': content, +'topics': topics, +'users': users, +'targets': targets, +'cc': cc, +'bcc': bcc, +'attachments': attachments, +'draft': draft, +'html': html, +'scheduledAt': scheduledAt, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Update email + /// + /// Update an email message by its unique ID. + /// + Future updateEmail({required String messageId, List? topics, List? users, List? targets, String? subject, String? content, bool? draft, bool? html, List? cc, List? bcc, String? scheduledAt, List? attachments}) async { + final String apiPath = '/messaging/messages/email/{messageId}'.replaceAll('{messageId}', messageId); + + final Map apiParams = { + + 'topics': topics, +'users': users, +'targets': targets, +'subject': subject, +'content': content, +'draft': draft, +'html': html, +'cc': cc, +'bcc': bcc, +'scheduledAt': scheduledAt, +'attachments': attachments, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Create push notification + /// + /// Create a new push notification. + Future createPush({required String messageId, required String title, required String body, List? topics, List? users, List? targets, Map? data, String? action, String? image, String? icon, String? sound, String? color, String? tag, String? badge, bool? draft, String? scheduledAt}) async { + final String apiPath = '/messaging/messages/push'; + + final Map apiParams = { + + 'messageId': messageId, +'title': title, +'body': body, +'topics': topics, +'users': users, +'targets': targets, +'data': data, +'action': action, +'image': image, +'icon': icon, +'sound': sound, +'color': color, +'tag': tag, +'badge': badge, +'draft': draft, +'scheduledAt': scheduledAt, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Update push notification + /// + /// Update a push notification by its unique ID. + /// + Future updatePush({required String messageId, List? topics, List? users, List? targets, String? title, String? body, Map? data, String? action, String? image, String? icon, String? sound, String? color, String? tag, int? badge, bool? draft, String? scheduledAt}) async { + final String apiPath = '/messaging/messages/push/{messageId}'.replaceAll('{messageId}', messageId); + + final Map apiParams = { + + 'topics': topics, +'users': users, +'targets': targets, +'title': title, +'body': body, +'data': data, +'action': action, +'image': image, +'icon': icon, +'sound': sound, +'color': color, +'tag': tag, +'badge': badge, +'draft': draft, +'scheduledAt': scheduledAt, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Create SMS + /// + /// Create a new SMS message. + Future createSms({required String messageId, required String content, List? topics, List? users, List? targets, bool? draft, String? scheduledAt}) async { + final String apiPath = '/messaging/messages/sms'; + + final Map apiParams = { + + 'messageId': messageId, +'content': content, +'topics': topics, +'users': users, +'targets': targets, +'draft': draft, +'scheduledAt': scheduledAt, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Update SMS + /// + /// Update an email message by its unique ID. + /// + Future updateSms({required String messageId, List? topics, List? users, List? targets, String? content, bool? draft, String? scheduledAt}) async { + final String apiPath = '/messaging/messages/sms/{messageId}'.replaceAll('{messageId}', messageId); + + final Map apiParams = { + + 'topics': topics, +'users': users, +'targets': targets, +'content': content, +'draft': draft, +'scheduledAt': scheduledAt, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Get message + /// + /// Get a message by its unique ID. + /// + Future getMessage({required String messageId}) async { + final String apiPath = '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Delete message + /// + /// Delete a message. If the message is not a draft or scheduled, but has been + /// sent, this will not recall the message. + Future delete({required String messageId}) async { + final String apiPath = '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List message logs + /// + /// Get the message activity logs listed by its unique ID. + Future listMessageLogs({required String messageId, List? queries}) async { + final String apiPath = '/messaging/messages/{messageId}/logs'.replaceAll('{messageId}', messageId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// List message targets + /// + /// Get a list of the targets associated with a message. + Future listTargets({required String messageId, List? queries}) async { + final String apiPath = '/messaging/messages/{messageId}/targets'.replaceAll('{messageId}', messageId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.TargetList.fromMap(res.data); + + } + + /// List providers + /// + /// Get a list of all providers from the current Appwrite project. + Future listProviders({List? queries, String? search}) async { + final String apiPath = '/messaging/providers'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.ProviderList.fromMap(res.data); + + } + + /// Create APNS provider + /// + /// Create a new Apple Push Notification service provider. + Future createApnsProvider({required String providerId, required String name, String? authKey, String? authKeyId, String? teamId, String? bundleId, bool? sandbox, bool? enabled}) async { + final String apiPath = '/messaging/providers/apns'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'authKey': authKey, +'authKeyId': authKeyId, +'teamId': teamId, +'bundleId': bundleId, +'sandbox': sandbox, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update APNS provider + /// + /// Update a Apple Push Notification service provider by its unique ID. + Future updateApnsProvider({required String providerId, String? name, bool? enabled, String? authKey, String? authKeyId, String? teamId, String? bundleId, bool? sandbox}) async { + final String apiPath = '/messaging/providers/apns/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, +'authKey': authKey, +'authKeyId': authKeyId, +'teamId': teamId, +'bundleId': bundleId, +'sandbox': sandbox, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create FCM provider + /// + /// Create a new Firebase Cloud Messaging provider. + Future createFcmProvider({required String providerId, required String name, Map? serviceAccountJSON, bool? enabled}) async { + final String apiPath = '/messaging/providers/fcm'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'serviceAccountJSON': serviceAccountJSON, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update FCM provider + /// + /// Update a Firebase Cloud Messaging provider by its unique ID. + Future updateFcmProvider({required String providerId, String? name, bool? enabled, Map? serviceAccountJSON}) async { + final String apiPath = '/messaging/providers/fcm/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, +'serviceAccountJSON': serviceAccountJSON, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Mailgun provider + /// + /// Create a new Mailgun provider. + Future createMailgunProvider({required String providerId, required String name, String? apiKey, String? domain, bool? isEuRegion, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { + final String apiPath = '/messaging/providers/mailgun'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'apiKey': apiKey, +'domain': domain, +'isEuRegion': isEuRegion, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Mailgun provider + /// + /// Update a Mailgun provider by its unique ID. + Future updateMailgunProvider({required String providerId, String? name, String? apiKey, String? domain, bool? isEuRegion, bool? enabled, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail}) async { + final String apiPath = '/messaging/providers/mailgun/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'apiKey': apiKey, +'domain': domain, +'isEuRegion': isEuRegion, +'enabled': enabled, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Msg91 provider + /// + /// Create a new MSG91 provider. + Future createMsg91Provider({required String providerId, required String name, String? templateId, String? senderId, String? authKey, bool? enabled}) async { + final String apiPath = '/messaging/providers/msg91'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'templateId': templateId, +'senderId': senderId, +'authKey': authKey, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Msg91 provider + /// + /// Update a MSG91 provider by its unique ID. + Future updateMsg91Provider({required String providerId, String? name, bool? enabled, String? templateId, String? senderId, String? authKey}) async { + final String apiPath = '/messaging/providers/msg91/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, +'templateId': templateId, +'senderId': senderId, +'authKey': authKey, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Sendgrid provider + /// + /// Create a new Sendgrid provider. + Future createSendgridProvider({required String providerId, required String name, String? apiKey, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { + final String apiPath = '/messaging/providers/sendgrid'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'apiKey': apiKey, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Sendgrid provider + /// + /// Update a Sendgrid provider by its unique ID. + Future updateSendgridProvider({required String providerId, String? name, bool? enabled, String? apiKey, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail}) async { + final String apiPath = '/messaging/providers/sendgrid/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, +'apiKey': apiKey, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create SMTP provider + /// + /// Create a new SMTP provider. + Future createSmtpProvider({required String providerId, required String name, required String host, int? port, String? username, String? password, enums.SmtpEncryption? encryption, bool? autoTLS, String? mailer, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { + final String apiPath = '/messaging/providers/smtp'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'host': host, +'port': port, +'username': username, +'password': password, +'encryption': encryption?.value, +'autoTLS': autoTLS, +'mailer': mailer, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update SMTP provider + /// + /// Update a SMTP provider by its unique ID. + Future updateSmtpProvider({required String providerId, String? name, String? host, int? port, String? username, String? password, enums.SmtpEncryption? encryption, bool? autoTLS, String? mailer, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { + final String apiPath = '/messaging/providers/smtp/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'host': host, +'port': port, +'username': username, +'password': password, +'encryption': encryption?.value, +'autoTLS': autoTLS, +'mailer': mailer, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Telesign provider + /// + /// Create a new Telesign provider. + Future createTelesignProvider({required String providerId, required String name, String? from, String? customerId, String? apiKey, bool? enabled}) async { + final String apiPath = '/messaging/providers/telesign'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'from': from, +'customerId': customerId, +'apiKey': apiKey, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Telesign provider + /// + /// Update a Telesign provider by its unique ID. + Future updateTelesignProvider({required String providerId, String? name, bool? enabled, String? customerId, String? apiKey, String? from}) async { + final String apiPath = '/messaging/providers/telesign/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, +'customerId': customerId, +'apiKey': apiKey, +'from': from, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Textmagic provider + /// + /// Create a new Textmagic provider. + Future createTextmagicProvider({required String providerId, required String name, String? from, String? username, String? apiKey, bool? enabled}) async { + final String apiPath = '/messaging/providers/textmagic'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'from': from, +'username': username, +'apiKey': apiKey, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Textmagic provider + /// + /// Update a Textmagic provider by its unique ID. + Future updateTextmagicProvider({required String providerId, String? name, bool? enabled, String? username, String? apiKey, String? from}) async { + final String apiPath = '/messaging/providers/textmagic/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, +'username': username, +'apiKey': apiKey, +'from': from, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Twilio provider + /// + /// Create a new Twilio provider. + Future createTwilioProvider({required String providerId, required String name, String? from, String? accountSid, String? authToken, bool? enabled}) async { + final String apiPath = '/messaging/providers/twilio'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'from': from, +'accountSid': accountSid, +'authToken': authToken, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Twilio provider + /// + /// Update a Twilio provider by its unique ID. + Future updateTwilioProvider({required String providerId, String? name, bool? enabled, String? accountSid, String? authToken, String? from}) async { + final String apiPath = '/messaging/providers/twilio/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, +'accountSid': accountSid, +'authToken': authToken, +'from': from, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Vonage provider + /// + /// Create a new Vonage provider. + Future createVonageProvider({required String providerId, required String name, String? from, String? apiKey, String? apiSecret, bool? enabled}) async { + final String apiPath = '/messaging/providers/vonage'; + + final Map apiParams = { + + 'providerId': providerId, +'name': name, +'from': from, +'apiKey': apiKey, +'apiSecret': apiSecret, +'enabled': enabled, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Vonage provider + /// + /// Update a Vonage provider by its unique ID. + Future updateVonageProvider({required String providerId, String? name, bool? enabled, String? apiKey, String? apiSecret, String? from}) async { + final String apiPath = '/messaging/providers/vonage/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + 'name': name, +'enabled': enabled, +'apiKey': apiKey, +'apiSecret': apiSecret, +'from': from, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Get provider + /// + /// Get a provider by its unique ID. + /// + Future getProvider({required String providerId}) async { + final String apiPath = '/messaging/providers/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Delete provider + /// + /// Delete a provider by its unique ID. + Future deleteProvider({required String providerId}) async { + final String apiPath = '/messaging/providers/{providerId}'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List provider logs + /// + /// Get the provider activity logs listed by its unique ID. + Future listProviderLogs({required String providerId, List? queries}) async { + final String apiPath = '/messaging/providers/{providerId}/logs'.replaceAll('{providerId}', providerId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// List subscriber logs + /// + /// Get the subscriber activity logs listed by its unique ID. + Future listSubscriberLogs({required String subscriberId, List? queries}) async { + final String apiPath = '/messaging/subscribers/{subscriberId}/logs'.replaceAll('{subscriberId}', subscriberId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// List topics + /// + /// Get a list of all topics from the current Appwrite project. + Future listTopics({List? queries, String? search}) async { + final String apiPath = '/messaging/topics'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.TopicList.fromMap(res.data); + + } + + /// Create topic + /// + /// Create a new topic. + Future createTopic({required String topicId, required String name, List? subscribe}) async { + final String apiPath = '/messaging/topics'; + + final Map apiParams = { + + 'topicId': topicId, +'name': name, +'subscribe': subscribe, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Topic.fromMap(res.data); + + } + + /// Get topic + /// + /// Get a topic by its unique ID. + /// + Future getTopic({required String topicId}) async { + final String apiPath = '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Topic.fromMap(res.data); + + } + + /// Update topic + /// + /// Update a topic by its unique ID. + /// + Future updateTopic({required String topicId, String? name, List? subscribe}) async { + final String apiPath = '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); + + final Map apiParams = { + + 'name': name, +'subscribe': subscribe, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Topic.fromMap(res.data); + + } + + /// Delete topic + /// + /// Delete a topic by its unique ID. + Future deleteTopic({required String topicId}) async { + final String apiPath = '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List topic logs + /// + /// Get the topic activity logs listed by its unique ID. + Future listTopicLogs({required String topicId, List? queries}) async { + final String apiPath = '/messaging/topics/{topicId}/logs'.replaceAll('{topicId}', topicId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// List subscribers + /// + /// Get a list of all subscribers from the current Appwrite project. + Future listSubscribers({required String topicId, List? queries, String? search}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers'.replaceAll('{topicId}', topicId); + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SubscriberList.fromMap(res.data); + + } + + /// Create subscriber + /// + /// Create a new subscriber. + Future createSubscriber({required String topicId, required String subscriberId, required String targetId}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers'.replaceAll('{topicId}', topicId); + + final Map apiParams = { + + 'subscriberId': subscriberId, +'targetId': targetId, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Subscriber.fromMap(res.data); + + } + + /// Get subscriber + /// + /// Get a subscriber by its unique ID. + /// + Future getSubscriber({required String topicId, required String subscriberId}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replaceAll('{topicId}', topicId).replaceAll('{subscriberId}', subscriberId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Subscriber.fromMap(res.data); + + } + + /// Delete subscriber + /// + /// Delete a subscriber by its unique ID. + Future deleteSubscriber({required String topicId, required String subscriberId}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replaceAll('{topicId}', topicId).replaceAll('{subscriberId}', subscriberId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } +} \ No newline at end of file diff --git a/lib/services/storage.dart b/lib/services/storage.dart index 14354786..1b2048e0 100644 --- a/lib/services/storage.dart +++ b/lib/services/storage.dart @@ -2,382 +2,356 @@ part of '../dart_appwrite.dart'; /// The Storage service allows you to manage your project files. class Storage extends Service { - Storage(super.client); - - /// List buckets - /// - /// Get a list of all the storage buckets. You can use the query params to - /// filter your results. - Future listBuckets( - {List? queries, String? search}) async { - final String apiPath = '/storage/buckets'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.BucketList.fromMap(res.data); - } - - /// Create bucket - /// - /// Create a new storage bucket. - Future createBucket( - {required String bucketId, - required String name, - List? permissions, - bool? fileSecurity, - bool? enabled, - int? maximumFileSize, - List? allowedFileExtensions, - enums.Compression? compression, - bool? encryption, - bool? antivirus}) async { - final String apiPath = '/storage/buckets'; - - final Map apiParams = { - 'bucketId': bucketId, - 'name': name, - 'permissions': permissions, - 'fileSecurity': fileSecurity, - 'enabled': enabled, - 'maximumFileSize': maximumFileSize, - 'allowedFileExtensions': allowedFileExtensions, - 'compression': compression?.value, - 'encryption': encryption, - 'antivirus': antivirus, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Bucket.fromMap(res.data); - } - - /// Get bucket - /// - /// Get a storage bucket by its unique ID. This endpoint response returns a - /// JSON object with the storage bucket metadata. - Future getBucket({required String bucketId}) async { - final String apiPath = - '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Bucket.fromMap(res.data); - } - - /// Update bucket - /// - /// Update a storage bucket by its unique ID. - Future updateBucket( - {required String bucketId, - required String name, - List? permissions, - bool? fileSecurity, - bool? enabled, - int? maximumFileSize, - List? allowedFileExtensions, - enums.Compression? compression, - bool? encryption, - bool? antivirus}) async { - final String apiPath = - '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); - - final Map apiParams = { - 'name': name, - 'permissions': permissions, - 'fileSecurity': fileSecurity, - 'enabled': enabled, - 'maximumFileSize': maximumFileSize, - 'allowedFileExtensions': allowedFileExtensions, - 'compression': compression?.value, - 'encryption': encryption, - 'antivirus': antivirus, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Bucket.fromMap(res.data); - } - - /// Delete bucket - /// - /// Delete a storage bucket by its unique ID. - Future deleteBucket({required String bucketId}) async { - final String apiPath = - '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List files - /// - /// Get a list of all the user files. You can use the query params to filter - /// your results. - Future listFiles( - {required String bucketId, List? queries, String? search}) async { - final String apiPath = - '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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](https://appwrite.io/docs/server/storage#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 Payload file, - List? permissions, - Function(UploadProgress)? onProgress}) async { - final String apiPath = - '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); - - final Map apiParams = { - 'fileId': fileId, - 'file': file, - 'permissions': permissions, - }; - - final Map apiHeaders = { - 'content-type': 'multipart/form-data', - }; - - String idParamName = ''; - idParamName = 'fileId'; - final paramName = 'file'; - final res = await client.chunkedUpload( - path: apiPath, - params: apiParams, - paramName: paramName, - idParamName: idParamName, - headers: apiHeaders, - onProgress: onProgress, - ); - - 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 { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.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, - String? name, - List? permissions}) async { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map apiParams = { - 'name': name, - 'permissions': permissions, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// 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 apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map params = { - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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, - enums.ImageGravity? gravity, - int? quality, - int? borderWidth, - String? borderColor, - int? borderRadius, - double? opacity, - int? rotation, - String? background, - enums.ImageFormat? output}) async { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map params = { - 'width': width, - 'height': height, - 'gravity': gravity?.value, - 'quality': quality, - 'borderWidth': borderWidth, - 'borderColor': borderColor, - 'borderRadius': borderRadius, - 'opacity': opacity, - 'rotation': rotation, - 'background': background, - 'output': output?.value, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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 { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map params = { - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: params, responseType: ResponseType.bytes); - return res.data; - } -} + Storage(super.client); + + /// List buckets + /// + /// Get a list of all the storage buckets. You can use the query params to + /// filter your results. + Future listBuckets({List? queries, String? search}) async { + final String apiPath = '/storage/buckets'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.BucketList.fromMap(res.data); + + } + + /// Create bucket + /// + /// Create a new storage bucket. + Future createBucket({required String bucketId, required String name, List? permissions, bool? fileSecurity, bool? enabled, int? maximumFileSize, List? allowedFileExtensions, enums.Compression? compression, bool? encryption, bool? antivirus}) async { + final String apiPath = '/storage/buckets'; + + final Map apiParams = { + + 'bucketId': bucketId, +'name': name, +'permissions': permissions, +'fileSecurity': fileSecurity, +'enabled': enabled, +'maximumFileSize': maximumFileSize, +'allowedFileExtensions': allowedFileExtensions, +'compression': compression?.value, +'encryption': encryption, +'antivirus': antivirus, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Bucket.fromMap(res.data); + + } + + /// Get bucket + /// + /// Get a storage bucket by its unique ID. This endpoint response returns a + /// JSON object with the storage bucket metadata. + Future getBucket({required String bucketId}) async { + final String apiPath = '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Bucket.fromMap(res.data); + + } + + /// Update bucket + /// + /// Update a storage bucket by its unique ID. + Future updateBucket({required String bucketId, required String name, List? permissions, bool? fileSecurity, bool? enabled, int? maximumFileSize, List? allowedFileExtensions, enums.Compression? compression, bool? encryption, bool? antivirus}) async { + final String apiPath = '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); + + final Map apiParams = { + + 'name': name, +'permissions': permissions, +'fileSecurity': fileSecurity, +'enabled': enabled, +'maximumFileSize': maximumFileSize, +'allowedFileExtensions': allowedFileExtensions, +'compression': compression?.value, +'encryption': encryption, +'antivirus': antivirus, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Bucket.fromMap(res.data); + + } + + /// Delete bucket + /// + /// Delete a storage bucket by its unique ID. + Future deleteBucket({required String bucketId}) async { + final String apiPath = '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List files + /// + /// Get a list of all the user files. You can use the query params to filter + /// your results. + Future listFiles({required String bucketId, List? queries, String? search}) async { + final String apiPath = '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + 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](https://appwrite.io/docs/server/storage#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 Payload file, List? permissions, Function(UploadProgress)? onProgress}) async { + final String apiPath = '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); + + final Map apiParams = { + + 'fileId': fileId, +'file': file, +'permissions': permissions, + + }; + + final Map apiHeaders = { + 'content-type': 'multipart/form-data', + + }; + + String idParamName = ''; + idParamName = 'fileId'; + final paramName = 'file'; + final res = await client.chunkedUpload( + path: apiPath, + params: apiParams, + paramName: paramName, + idParamName: idParamName, + headers: apiHeaders, + onProgress: onProgress, + ); + + 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 { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.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, String? name, List? permissions}) async { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map apiParams = { + + 'name': name, +'permissions': permissions, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// 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 apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map params = { + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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, enums.ImageGravity? gravity, int? quality, int? borderWidth, String? borderColor, int? borderRadius, double? opacity, int? rotation, String? background, enums.ImageFormat? output}) async { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map params = { + 'width': width, +'height': height, +'gravity': gravity?.value, +'quality': quality, +'borderWidth': borderWidth, +'borderColor': borderColor, +'borderRadius': borderRadius, +'opacity': opacity, +'rotation': rotation, +'background': background, +'output': output?.value, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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 { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map params = { + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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 27f5aff5..4d7ee475 100644 --- a/lib/services/teams.dart +++ b/lib/services/teams.dart @@ -3,340 +3,350 @@ part of '../dart_appwrite.dart'; /// 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(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. - Future list({List? queries, String? search}) async { - final String apiPath = '/teams'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams'; - - final Map apiParams = { - 'teamId': teamId, - 'name': name, - 'roles': roles, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Team.fromMap(res.data); - } - - /// Update name - /// - /// Update the team's name by its unique ID. - Future updateName( - {required String teamId, required String name}) async { - final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); - - final Map apiParams = { - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List 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 listMemberships( - {required String teamId, List? queries, String? search}) async { - final String apiPath = - '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MembershipList.fromMap(res.data); - } - - /// Create team membership - /// - /// Invite a new member to join your team. Provide an ID for existing users, or - /// invite unregistered users using an email or phone number. If initiated from - /// a Client SDK, Appwrite will send an email or sms with a link to join the - /// team to the invited user, and an account will be created for them if one - /// doesn't exist. If initiated from a Server SDK, the new member will be added - /// automatically to the team. - /// - /// You only need to provide one of a user ID, email, or phone number. Appwrite - /// will prioritize accepting the user ID > email > phone number if you provide - /// more than one of these parameters. - /// - /// Use the `url` parameter to redirect the user from the invitation email to - /// your app. After the user is redirected, use the [Update Team Membership - /// Status](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus) - /// 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) - /// Appwrite will accept the only redirect URLs under the domains you have - /// added as a platform on the Appwrite Console. - /// - Future createMembership( - {required String teamId, - required List roles, - String? email, - String? userId, - String? phone, - String? url, - String? name}) async { - final String apiPath = - '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); - - final Map apiParams = { - 'email': email, - 'userId': userId, - 'phone': phone, - 'roles': roles, - 'url': url, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams/{teamId}/memberships/{membershipId}' - .replaceAll('{teamId}', teamId) - .replaceAll('{membershipId}', membershipId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Membership.fromMap(res.data); - } - - /// Update membership - /// - /// 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](https://appwrite.io/docs/permissions). - /// - Future updateMembership( - {required String teamId, - required String membershipId, - required List roles}) async { - final String apiPath = '/teams/{teamId}/memberships/{membershipId}' - .replaceAll('{teamId}', teamId) - .replaceAll('{membershipId}', membershipId); - - final Map apiParams = { - 'roles': roles, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams/{teamId}/memberships/{membershipId}' - .replaceAll('{teamId}', teamId) - .replaceAll('{membershipId}', membershipId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// 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 apiPath = '/teams/{teamId}/memberships/{membershipId}/status' - .replaceAll('{teamId}', teamId) - .replaceAll('{membershipId}', membershipId); - - final Map apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Membership.fromMap(res.data); - } - - /// Get team preferences - /// - /// Get the team's shared preferences by its unique ID. If a preference doesn't - /// need to be shared by all team members, prefer storing them in [user - /// preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs). - Future getPrefs({required String teamId}) async { - final String apiPath = - '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - } - - /// Update preferences - /// - /// Update the team's preferences by its unique ID. The object you pass is - /// stored as is and replaces any previous value. The maximum allowed prefs - /// size is 64kB and throws an error if exceeded. - Future updatePrefs( - {required String teamId, required Map prefs}) async { - final String apiPath = - '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); - - final Map apiParams = { - 'prefs': prefs, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - } -} + Teams(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. + Future list({List? queries, String? search}) async { + final String apiPath = '/teams'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams'; + + final Map apiParams = { + + 'teamId': teamId, +'name': name, +'roles': roles, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Team.fromMap(res.data); + + } + + /// Update name + /// + /// Update the team's name by its unique ID. + Future updateName({required String teamId, required String name}) async { + final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + + 'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List 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 listMemberships({required String teamId, List? queries, String? search}) async { + final String apiPath = '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MembershipList.fromMap(res.data); + + } + + /// Create team membership + /// + /// Invite a new member to join your team. Provide an ID for existing users, or + /// invite unregistered users using an email or phone number. If initiated from + /// a Client SDK, Appwrite will send an email or sms with a link to join the + /// team to the invited user, and an account will be created for them if one + /// doesn't exist. If initiated from a Server SDK, the new member will be added + /// automatically to the team. + /// + /// You only need to provide one of a user ID, email, or phone number. Appwrite + /// will prioritize accepting the user ID > email > phone number if you provide + /// more than one of these parameters. + /// + /// Use the `url` parameter to redirect the user from the invitation email to + /// your app. After the user is redirected, use the [Update Team Membership + /// Status](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus) + /// 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) + /// Appwrite will accept the only redirect URLs under the domains you have + /// added as a platform on the Appwrite Console. + /// + Future createMembership({required String teamId, required List roles, String? email, String? userId, String? phone, String? url, String? name}) async { + final String apiPath = '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + + 'email': email, +'userId': userId, +'phone': phone, +'roles': roles, +'url': url, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Membership.fromMap(res.data); + + } + + /// Update membership + /// + /// 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](https://appwrite.io/docs/permissions). + /// + Future updateMembership({required String teamId, required String membershipId, required List roles}) async { + final String apiPath = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); + + final Map apiParams = { + + 'roles': roles, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// 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 apiPath = '/teams/{teamId}/memberships/{membershipId}/status'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); + + final Map apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Membership.fromMap(res.data); + + } + + /// Get team preferences + /// + /// Get the team's shared preferences by its unique ID. If a preference doesn't + /// need to be shared by all team members, prefer storing them in [user + /// preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs). + Future getPrefs({required String teamId}) async { + final String apiPath = '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + + } + + /// Update preferences + /// + /// Update the team's preferences by its unique ID. The object you pass is + /// stored as is and replaces any previous value. The maximum allowed prefs + /// size is 64kB and throws an error if exceeded. + Future updatePrefs({required String teamId, required Map prefs}) async { + final String apiPath = '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); + + final Map apiParams = { + + 'prefs': prefs, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + + } +} \ No newline at end of file diff --git a/lib/services/users.dart b/lib/services/users.dart index 74c375eb..25acfa75 100644 --- a/lib/services/users.dart +++ b/lib/services/users.dart @@ -2,1023 +2,1055 @@ part of '../dart_appwrite.dart'; /// The Users service allows you to manage your project users. class Users extends Service { - Users(super.client); - - /// List users - /// - /// Get a list of all the project's users. You can use the query params to - /// filter your results. - Future list({List? queries, String? search}) async { - final String apiPath = '/users'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.UserList.fromMap(res.data); - } - - /// Create user - /// - /// Create a new user. - Future create( - {required String userId, - String? email, - String? phone, - String? password, - String? name}) async { - final String apiPath = '/users'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'phone': phone, - 'password': password, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with Argon2 password - /// - /// Create a new user. Password provided must be hashed with the - /// [Argon2](https://en.wikipedia.org/wiki/Argon2) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createArgon2User( - {required String userId, - required String email, - required String password, - String? name}) async { - final String apiPath = '/users/argon2'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with bcrypt password - /// - /// Create a new user. Password provided must be hashed with the - /// [Bcrypt](https://en.wikipedia.org/wiki/Bcrypt) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createBcryptUser( - {required String userId, - required String email, - required String password, - String? name}) async { - final String apiPath = '/users/bcrypt'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// List Identities - /// - /// Get identities for all users. - Future listIdentities( - {List? queries, String? search}) async { - final String apiPath = '/users/identities'; - - final Map apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.IdentityList.fromMap(res.data); - } - - /// Delete identity - /// - /// Delete an identity by its unique ID. - Future deleteIdentity({required String identityId}) async { - final String apiPath = - '/users/identities/{identityId}'.replaceAll('{identityId}', identityId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Create user with MD5 password - /// - /// Create a new user. Password provided must be hashed with the - /// [MD5](https://en.wikipedia.org/wiki/MD5) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createMD5User( - {required String userId, - required String email, - required String password, - String? name}) async { - final String apiPath = '/users/md5'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with PHPass password - /// - /// Create a new user. Password provided must be hashed with the - /// [PHPass](https://www.openwall.com/phpass/) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createPHPassUser( - {required String userId, - required String email, - required String password, - String? name}) async { - final String apiPath = '/users/phpass'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with Scrypt password - /// - /// Create a new user. Password provided must be hashed with the - /// [Scrypt](https://github.com/Tarsnap/scrypt) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createScryptUser( - {required String userId, - required String email, - required String password, - required String passwordSalt, - required int passwordCpu, - required int passwordMemory, - required int passwordParallel, - required int passwordLength, - String? name}) async { - final String apiPath = '/users/scrypt'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'passwordSalt': passwordSalt, - 'passwordCpu': passwordCpu, - 'passwordMemory': passwordMemory, - 'passwordParallel': passwordParallel, - 'passwordLength': passwordLength, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with Scrypt modified password - /// - /// Create a new user. Password provided must be hashed with the [Scrypt - /// Modified](https://gist.github.com/Meldiron/eecf84a0225eccb5a378d45bb27462cc) - /// algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future createScryptModifiedUser( - {required String userId, - required String email, - required String password, - required String passwordSalt, - required String passwordSaltSeparator, - required String passwordSignerKey, - String? name}) async { - final String apiPath = '/users/scrypt-modified'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'passwordSalt': passwordSalt, - 'passwordSaltSeparator': passwordSaltSeparator, - 'passwordSignerKey': passwordSignerKey, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with SHA password - /// - /// Create a new user. Password provided must be hashed with the - /// [SHA](https://en.wikipedia.org/wiki/Secure_Hash_Algorithm) algorithm. Use - /// the [POST /users](https://appwrite.io/docs/server/users#usersCreate) - /// endpoint to create users with a plain text password. - Future createSHAUser( - {required String userId, - required String email, - required String password, - enums.PasswordHash? passwordVersion, - String? name}) async { - final String apiPath = '/users/sha'; - - final Map apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'passwordVersion': passwordVersion?.value, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Get user - /// - /// Get a user by its unique ID. - Future get({required String userId}) async { - final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Delete user - /// - /// Delete a user by its unique ID, thereby releasing it's ID. Since ID is - /// released and can be reused, all user-related resources like documents or - /// storage files should be deleted before user deletion. If you want to keep - /// ID reserved, use the - /// [updateStatus](https://appwrite.io/docs/server/users#usersUpdateStatus) - /// endpoint instead. - Future delete({required String userId}) async { - final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Update email - /// - /// Update the user email by its unique ID. - Future updateEmail( - {required String userId, required String email}) async { - final String apiPath = - '/users/{userId}/email'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'email': email, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user JWT - /// - /// Use this endpoint to create a JSON Web Token for user by its unique ID. You - /// can use the resulting JWT to authenticate on behalf of the user. The JWT - /// secret will become invalid if the session it uses gets deleted. - Future createJWT( - {required String userId, String? sessionId, int? duration}) async { - final String apiPath = - '/users/{userId}/jwts'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'sessionId': sessionId, - 'duration': duration, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Jwt.fromMap(res.data); - } - - /// Update user labels - /// - /// Update the user labels by its unique ID. - /// - /// Labels can be used to grant access to resources. While teams are a way for - /// user's to share access to a resource, labels can be defined by the - /// developer to grant access without an invitation. See the [Permissions - /// docs](https://appwrite.io/docs/permissions) for more info. - Future updateLabels( - {required String userId, required List labels}) async { - final String apiPath = - '/users/{userId}/labels'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'labels': labels, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// List user logs - /// - /// Get the user activity logs list by its unique ID. - Future listLogs( - {required String userId, List? queries}) async { - final String apiPath = - '/users/{userId}/logs'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// List user memberships - /// - /// Get the user membership list by its unique ID. - Future listMemberships( - {required String userId}) async { - final String apiPath = - '/users/{userId}/memberships'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MembershipList.fromMap(res.data); - } - - /// Update MFA - /// - /// Enable or disable MFA on a user account. - Future updateMfa( - {required String userId, required bool mfa}) async { - final String apiPath = '/users/{userId}/mfa'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'mfa': mfa, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Delete Authenticator - /// - /// Delete an authenticator app. - Future deleteMfaAuthenticator( - {required String userId, required enums.AuthenticatorType type}) async { - final String apiPath = '/users/{userId}/mfa/authenticators/{type}' - .replaceAll('{userId}', userId) - .replaceAll('{type}', type.value); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// List Factors - /// - /// List the factors available on the account to be used as a MFA challange. - Future listMfaFactors({required String userId}) async { - final String apiPath = - '/users/{userId}/mfa/factors'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaFactors.fromMap(res.data); - } - - /// Get MFA Recovery Codes - /// - /// Get recovery codes that can be used as backup for MFA flow by User ID. - /// Before getting codes, they must be generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. - Future getMfaRecoveryCodes( - {required String userId}) async { - final String apiPath = - '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Regenerate MFA Recovery Codes - /// - /// Regenerate recovery codes that can be used as backup for MFA flow by User - /// ID. Before regenerating codes, they must be first generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. - Future updateMfaRecoveryCodes( - {required String userId}) async { - final String apiPath = - '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Create MFA Recovery Codes - /// - /// Generate recovery codes used as backup for MFA flow for User ID. Recovery - /// codes can be used as a MFA verification type in - /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) - /// method by client SDK. - Future createMfaRecoveryCodes( - {required String userId}) async { - final String apiPath = - '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Update name - /// - /// Update the user name by its unique ID. - Future updateName( - {required String userId, required String name}) async { - final String apiPath = - '/users/{userId}/name'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update password - /// - /// Update the user password by its unique ID. - Future updatePassword( - {required String userId, required String password}) async { - final String apiPath = - '/users/{userId}/password'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'password': password, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update phone - /// - /// Update the user phone by its unique ID. - Future updatePhone( - {required String userId, required String number}) async { - final String apiPath = - '/users/{userId}/phone'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'number': number, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Get user preferences - /// - /// Get the user preferences by its unique ID. - Future getPrefs({required String userId}) async { - final String apiPath = - '/users/{userId}/prefs'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - } - - /// Update user preferences - /// - /// Update the user preferences by its unique ID. 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 String userId, required Map prefs}) async { - final String apiPath = - '/users/{userId}/prefs'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'prefs': prefs, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - } - - /// List user sessions - /// - /// Get the user sessions list by its unique ID. - Future listSessions({required String userId}) async { - final String apiPath = - '/users/{userId}/sessions'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SessionList.fromMap(res.data); - } - - /// Create session - /// - /// Creates a session for a user. Returns an immediately usable session object. - /// - /// If you want to generate a token for a custom authentication flow, use the - /// [POST - /// /users/{userId}/tokens](https://appwrite.io/docs/server/users#createToken) - /// endpoint. - Future createSession({required String userId}) async { - final String apiPath = - '/users/{userId}/sessions'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Delete user sessions - /// - /// Delete all user's sessions by using the user's unique ID. - Future deleteSessions({required String userId}) async { - final String apiPath = - '/users/{userId}/sessions'.replaceAll('{userId}', userId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Delete user session - /// - /// Delete a user sessions by its unique ID. - Future deleteSession( - {required String userId, required String sessionId}) async { - final String apiPath = '/users/{userId}/sessions/{sessionId}' - .replaceAll('{userId}', userId) - .replaceAll('{sessionId}', sessionId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Update user status - /// - /// Update the user status by its unique ID. Use this endpoint as an - /// alternative to deleting a user if you want to keep user's ID reserved. - Future updateStatus( - {required String userId, required bool status}) async { - final String apiPath = - '/users/{userId}/status'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'status': status, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// List User Targets - /// - /// List the messaging targets that are associated with a user. - Future listTargets( - {required String userId, List? queries}) async { - final String apiPath = - '/users/{userId}/targets'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'queries': queries, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.TargetList.fromMap(res.data); - } - - /// Create User Target - /// - /// Create a messaging target. - Future createTarget( - {required String userId, - required String targetId, - required enums.MessagingProviderType providerType, - required String identifier, - String? providerId, - String? name}) async { - final String apiPath = - '/users/{userId}/targets'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'targetId': targetId, - 'providerType': providerType.value, - 'identifier': identifier, - 'providerId': providerId, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Target.fromMap(res.data); - } - - /// Get User Target - /// - /// Get a user's push notification target by ID. - Future getTarget( - {required String userId, required String targetId}) async { - final String apiPath = '/users/{userId}/targets/{targetId}' - .replaceAll('{userId}', userId) - .replaceAll('{targetId}', targetId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Target.fromMap(res.data); - } - - /// Update User target - /// - /// Update a messaging target. - Future updateTarget( - {required String userId, - required String targetId, - String? identifier, - String? providerId, - String? name}) async { - final String apiPath = '/users/{userId}/targets/{targetId}' - .replaceAll('{userId}', userId) - .replaceAll('{targetId}', targetId); - - final Map apiParams = { - 'identifier': identifier, - 'providerId': providerId, - 'name': name, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Target.fromMap(res.data); - } - - /// Delete user target - /// - /// Delete a messaging target. - Future deleteTarget( - {required String userId, required String targetId}) async { - final String apiPath = '/users/{userId}/targets/{targetId}' - .replaceAll('{userId}', userId) - .replaceAll('{targetId}', targetId); - - final Map apiParams = {}; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Create token - /// - /// Returns a token with a secret key for creating a session. Use the user ID - /// and secret and submit a request to the [PUT - /// /account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. - /// - Future createToken( - {required String userId, int? length, int? expire}) async { - final String apiPath = - '/users/{userId}/tokens'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'length': length, - 'expire': expire, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Update email verification - /// - /// Update the user email verification status by its unique ID. - Future updateEmailVerification( - {required String userId, required bool emailVerification}) async { - final String apiPath = - '/users/{userId}/verification'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'emailVerification': emailVerification, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update phone verification - /// - /// Update the user phone verification status by its unique ID. - Future updatePhoneVerification( - {required String userId, required bool phoneVerification}) async { - final String apiPath = - '/users/{userId}/verification/phone'.replaceAll('{userId}', userId); - - final Map apiParams = { - 'phoneVerification': phoneVerification, - }; - - final Map apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } -} + Users(super.client); + + /// List users + /// + /// Get a list of all the project's users. You can use the query params to + /// filter your results. + Future list({List? queries, String? search}) async { + final String apiPath = '/users'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.UserList.fromMap(res.data); + + } + + /// Create user + /// + /// Create a new user. + Future create({required String userId, String? email, String? phone, String? password, String? name}) async { + final String apiPath = '/users'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'phone': phone, +'password': password, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with Argon2 password + /// + /// Create a new user. Password provided must be hashed with the + /// [Argon2](https://en.wikipedia.org/wiki/Argon2) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createArgon2User({required String userId, required String email, required String password, String? name}) async { + final String apiPath = '/users/argon2'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with bcrypt password + /// + /// Create a new user. Password provided must be hashed with the + /// [Bcrypt](https://en.wikipedia.org/wiki/Bcrypt) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createBcryptUser({required String userId, required String email, required String password, String? name}) async { + final String apiPath = '/users/bcrypt'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// List identities + /// + /// Get identities for all users. + Future listIdentities({List? queries, String? search}) async { + final String apiPath = '/users/identities'; + + final Map apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.IdentityList.fromMap(res.data); + + } + + /// Delete identity + /// + /// Delete an identity by its unique ID. + Future deleteIdentity({required String identityId}) async { + final String apiPath = '/users/identities/{identityId}'.replaceAll('{identityId}', identityId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Create user with MD5 password + /// + /// Create a new user. Password provided must be hashed with the + /// [MD5](https://en.wikipedia.org/wiki/MD5) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createMD5User({required String userId, required String email, required String password, String? name}) async { + final String apiPath = '/users/md5'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with PHPass password + /// + /// Create a new user. Password provided must be hashed with the + /// [PHPass](https://www.openwall.com/phpass/) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createPHPassUser({required String userId, required String email, required String password, String? name}) async { + final String apiPath = '/users/phpass'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with Scrypt password + /// + /// Create a new user. Password provided must be hashed with the + /// [Scrypt](https://github.com/Tarsnap/scrypt) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createScryptUser({required String userId, required String email, required String password, required String passwordSalt, required int passwordCpu, required int passwordMemory, required int passwordParallel, required int passwordLength, String? name}) async { + final String apiPath = '/users/scrypt'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'passwordSalt': passwordSalt, +'passwordCpu': passwordCpu, +'passwordMemory': passwordMemory, +'passwordParallel': passwordParallel, +'passwordLength': passwordLength, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with Scrypt modified password + /// + /// Create a new user. Password provided must be hashed with the [Scrypt + /// Modified](https://gist.github.com/Meldiron/eecf84a0225eccb5a378d45bb27462cc) + /// algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future createScryptModifiedUser({required String userId, required String email, required String password, required String passwordSalt, required String passwordSaltSeparator, required String passwordSignerKey, String? name}) async { + final String apiPath = '/users/scrypt-modified'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'passwordSalt': passwordSalt, +'passwordSaltSeparator': passwordSaltSeparator, +'passwordSignerKey': passwordSignerKey, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with SHA password + /// + /// Create a new user. Password provided must be hashed with the + /// [SHA](https://en.wikipedia.org/wiki/Secure_Hash_Algorithm) algorithm. Use + /// the [POST /users](https://appwrite.io/docs/server/users#usersCreate) + /// endpoint to create users with a plain text password. + Future createSHAUser({required String userId, required String email, required String password, enums.PasswordHash? passwordVersion, String? name}) async { + final String apiPath = '/users/sha'; + + final Map apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'passwordVersion': passwordVersion?.value, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Get user + /// + /// Get a user by its unique ID. + Future get({required String userId}) async { + final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Delete user + /// + /// Delete a user by its unique ID, thereby releasing it's ID. Since ID is + /// released and can be reused, all user-related resources like documents or + /// storage files should be deleted before user deletion. If you want to keep + /// ID reserved, use the + /// [updateStatus](https://appwrite.io/docs/server/users#usersUpdateStatus) + /// endpoint instead. + Future delete({required String userId}) async { + final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Update email + /// + /// Update the user email by its unique ID. + Future updateEmail({required String userId, required String email}) async { + final String apiPath = '/users/{userId}/email'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'email': email, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user JWT + /// + /// Use this endpoint to create a JSON Web Token for user by its unique ID. You + /// can use the resulting JWT to authenticate on behalf of the user. The JWT + /// secret will become invalid if the session it uses gets deleted. + Future createJWT({required String userId, String? sessionId, int? duration}) async { + final String apiPath = '/users/{userId}/jwts'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'sessionId': sessionId, +'duration': duration, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Jwt.fromMap(res.data); + + } + + /// Update user labels + /// + /// Update the user labels by its unique ID. + /// + /// Labels can be used to grant access to resources. While teams are a way for + /// user's to share access to a resource, labels can be defined by the + /// developer to grant access without an invitation. See the [Permissions + /// docs](https://appwrite.io/docs/permissions) for more info. + Future updateLabels({required String userId, required List labels}) async { + final String apiPath = '/users/{userId}/labels'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'labels': labels, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// List user logs + /// + /// Get the user activity logs list by its unique ID. + Future listLogs({required String userId, List? queries}) async { + final String apiPath = '/users/{userId}/logs'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// List user memberships + /// + /// Get the user membership list by its unique ID. + Future listMemberships({required String userId}) async { + final String apiPath = '/users/{userId}/memberships'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MembershipList.fromMap(res.data); + + } + + /// Update MFA + /// + /// Enable or disable MFA on a user account. + Future updateMfa({required String userId, required bool mfa}) async { + final String apiPath = '/users/{userId}/mfa'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'mfa': mfa, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Delete authenticator + /// + /// Delete an authenticator app. + Future deleteMfaAuthenticator({required String userId, required enums.AuthenticatorType type}) async { + final String apiPath = '/users/{userId}/mfa/authenticators/{type}'.replaceAll('{userId}', userId).replaceAll('{type}', type.value); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// List factors + /// + /// List the factors available on the account to be used as a MFA challange. + Future listMfaFactors({required String userId}) async { + final String apiPath = '/users/{userId}/mfa/factors'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaFactors.fromMap(res.data); + + } + + /// Get MFA recovery codes + /// + /// Get recovery codes that can be used as backup for MFA flow by User ID. + /// Before getting codes, they must be generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. + Future getMfaRecoveryCodes({required String userId}) async { + final String apiPath = '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Regenerate MFA recovery codes + /// + /// Regenerate recovery codes that can be used as backup for MFA flow by User + /// ID. Before regenerating codes, they must be first generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. + Future updateMfaRecoveryCodes({required String userId}) async { + final String apiPath = '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Create MFA recovery codes + /// + /// Generate recovery codes used as backup for MFA flow for User ID. Recovery + /// codes can be used as a MFA verification type in + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method by client SDK. + Future createMfaRecoveryCodes({required String userId}) async { + final String apiPath = '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Update name + /// + /// Update the user name by its unique ID. + Future updateName({required String userId, required String name}) async { + final String apiPath = '/users/{userId}/name'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update password + /// + /// Update the user password by its unique ID. + Future updatePassword({required String userId, required String password}) async { + final String apiPath = '/users/{userId}/password'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'password': password, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update phone + /// + /// Update the user phone by its unique ID. + Future updatePhone({required String userId, required String number}) async { + final String apiPath = '/users/{userId}/phone'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'number': number, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Get user preferences + /// + /// Get the user preferences by its unique ID. + Future getPrefs({required String userId}) async { + final String apiPath = '/users/{userId}/prefs'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + + } + + /// Update user preferences + /// + /// Update the user preferences by its unique ID. 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 String userId, required Map prefs}) async { + final String apiPath = '/users/{userId}/prefs'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'prefs': prefs, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + + } + + /// List user sessions + /// + /// Get the user sessions list by its unique ID. + Future listSessions({required String userId}) async { + final String apiPath = '/users/{userId}/sessions'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SessionList.fromMap(res.data); + + } + + /// Create session + /// + /// Creates a session for a user. Returns an immediately usable session object. + /// + /// If you want to generate a token for a custom authentication flow, use the + /// [POST + /// /users/{userId}/tokens](https://appwrite.io/docs/server/users#createToken) + /// endpoint. + Future createSession({required String userId}) async { + final String apiPath = '/users/{userId}/sessions'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Delete user sessions + /// + /// Delete all user's sessions by using the user's unique ID. + Future deleteSessions({required String userId}) async { + final String apiPath = '/users/{userId}/sessions'.replaceAll('{userId}', userId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Delete user session + /// + /// Delete a user sessions by its unique ID. + Future deleteSession({required String userId, required String sessionId}) async { + final String apiPath = '/users/{userId}/sessions/{sessionId}'.replaceAll('{userId}', userId).replaceAll('{sessionId}', sessionId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Update user status + /// + /// Update the user status by its unique ID. Use this endpoint as an + /// alternative to deleting a user if you want to keep user's ID reserved. + Future updateStatus({required String userId, required bool status}) async { + final String apiPath = '/users/{userId}/status'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'status': status, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// List user targets + /// + /// List the messaging targets that are associated with a user. + Future listTargets({required String userId, List? queries}) async { + final String apiPath = '/users/{userId}/targets'.replaceAll('{userId}', userId); + + final Map apiParams = { + 'queries': queries, + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.TargetList.fromMap(res.data); + + } + + /// Create user target + /// + /// Create a messaging target. + Future createTarget({required String userId, required String targetId, required enums.MessagingProviderType providerType, required String identifier, String? providerId, String? name}) async { + final String apiPath = '/users/{userId}/targets'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'targetId': targetId, +'providerType': providerType.value, +'identifier': identifier, +'providerId': providerId, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Target.fromMap(res.data); + + } + + /// Get user target + /// + /// Get a user's push notification target by ID. + Future getTarget({required String userId, required String targetId}) async { + final String apiPath = '/users/{userId}/targets/{targetId}'.replaceAll('{userId}', userId).replaceAll('{targetId}', targetId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Target.fromMap(res.data); + + } + + /// Update user target + /// + /// Update a messaging target. + Future updateTarget({required String userId, required String targetId, String? identifier, String? providerId, String? name}) async { + final String apiPath = '/users/{userId}/targets/{targetId}'.replaceAll('{userId}', userId).replaceAll('{targetId}', targetId); + + final Map apiParams = { + + 'identifier': identifier, +'providerId': providerId, +'name': name, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Target.fromMap(res.data); + + } + + /// Delete user target + /// + /// Delete a messaging target. + Future deleteTarget({required String userId, required String targetId}) async { + final String apiPath = '/users/{userId}/targets/{targetId}'.replaceAll('{userId}', userId).replaceAll('{targetId}', targetId); + + final Map apiParams = { + + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Create token + /// + /// Returns a token with a secret key for creating a session. Use the user ID + /// and secret and submit a request to the [PUT + /// /account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. + /// + Future createToken({required String userId, int? length, int? expire}) async { + final String apiPath = '/users/{userId}/tokens'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'length': length, +'expire': expire, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Update email verification + /// + /// Update the user email verification status by its unique ID. + Future updateEmailVerification({required String userId, required bool emailVerification}) async { + final String apiPath = '/users/{userId}/verification'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'emailVerification': emailVerification, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update phone verification + /// + /// Update the user phone verification status by its unique ID. + Future updatePhoneVerification({required String userId, required bool phoneVerification}) async { + final String apiPath = '/users/{userId}/verification/phone'.replaceAll('{userId}', userId); + + final Map apiParams = { + + 'phoneVerification': phoneVerification, + + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } +} \ No newline at end of file diff --git a/lib/src/client.dart b/lib/src/client.dart index bac07cfb..8dee2426 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -8,7 +8,7 @@ import 'upload_progress.dart'; /// [Client] that handles requests to Appwrite abstract class Client { /// The size for cunked uploads in bytes. - static const int CHUNK_SIZE = 5 * 1024 * 1024; + static const int CHUNK_SIZE = 5*1024*1024; /// Holds configuration such as project. late Map config; @@ -27,7 +27,7 @@ abstract class Client { Future webAuth(Uri url); /// Set self signed to [status]. - /// + /// /// If self signed is true, [Client] will ignore invalid certificates. /// This is helpful in environments where your Appwrite /// instance does not have a valid SSL certificate. @@ -78,8 +78,7 @@ abstract class Client { }); /// Send the API request. - Future call( - HttpMethod method, { + Future call(HttpMethod method, { String path = '', Map headers = const {}, Map params = const {}, diff --git a/lib/src/client_base.dart b/lib/src/client_base.dart index 95476465..21992eb0 100644 --- a/lib/src/client_base.dart +++ b/lib/src/client_base.dart @@ -2,25 +2,21 @@ import 'response.dart'; import 'client.dart'; import 'enums.dart'; -abstract class ClientBase implements Client { +abstract class ClientBase implements Client { /// Your project ID @override ClientBase setProject(value); - /// Your secret API key @override ClientBase setKey(value); - /// Your secret JSON Web Token @override ClientBase setJWT(value); @override ClientBase setLocale(value); - /// The user session to authenticate with @override ClientBase setSession(value); - /// The user agent string of the client that made the request @override ClientBase setForwardedUserAgent(value); diff --git a/lib/src/client_browser.dart b/lib/src/client_browser.dart index e9da960a..c7789db2 100644 --- a/lib/src/client_browser.dart +++ b/lib/src/client_browser.dart @@ -16,7 +16,7 @@ ClientBase createClient({ ClientBrowser(endPoint: endPoint, selfSigned: selfSigned); class ClientBrowser extends ClientBase with ClientMixin { - static const int CHUNK_SIZE = 5 * 1024 * 1024; + static const int CHUNK_SIZE = 5*1024*1024; String _endPoint; Map? _headers; @override @@ -33,8 +33,8 @@ class ClientBrowser extends ClientBase with ClientMixin { 'x-sdk-name': 'Dart', 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', - 'x-sdk-version': '13.0.0-rc1', - 'X-Appwrite-Response-Format': '1.6.0', + 'x-sdk-version': '13.0.0', + 'X-Appwrite-Response-Format' : '1.6.0', }; config = {}; @@ -46,52 +46,47 @@ class ClientBrowser extends ClientBase with ClientMixin { @override String get endPoint => _endPoint; - /// Your project ID - @override - ClientBrowser setProject(value) { - config['project'] = value; - addHeader('X-Appwrite-Project', value); - return this; - } - - /// Your secret API key - @override - ClientBrowser setKey(value) { - config['key'] = value; - addHeader('X-Appwrite-Key', value); - return this; - } - - /// Your secret JSON Web Token - @override - ClientBrowser setJWT(value) { - config['jWT'] = value; - addHeader('X-Appwrite-JWT', value); - return this; - } - - @override - ClientBrowser setLocale(value) { - config['locale'] = value; - addHeader('X-Appwrite-Locale', value); - return this; - } - - /// The user session to authenticate with - @override - ClientBrowser setSession(value) { - config['session'] = value; - addHeader('X-Appwrite-Session', value); - return this; - } - - /// The user agent string of the client that made the request - @override - ClientBrowser setForwardedUserAgent(value) { - config['forwardedUserAgent'] = value; - addHeader('X-Forwarded-User-Agent', value); - return this; - } + /// Your project ID + @override + ClientBrowser setProject(value) { + config['project'] = value; + addHeader('X-Appwrite-Project', value); + return this; + } + /// Your secret API key + @override + ClientBrowser setKey(value) { + config['key'] = value; + addHeader('X-Appwrite-Key', value); + return this; + } + /// Your secret JSON Web Token + @override + ClientBrowser setJWT(value) { + config['jWT'] = value; + addHeader('X-Appwrite-JWT', value); + return this; + } + @override + ClientBrowser setLocale(value) { + config['locale'] = value; + addHeader('X-Appwrite-Locale', value); + return this; + } + /// The user session to authenticate with + @override + ClientBrowser setSession(value) { + config['session'] = value; + addHeader('X-Appwrite-Session', value); + return this; + } + /// The user agent string of the client that made the request + @override + ClientBrowser setForwardedUserAgent(value) { + config['forwardedUserAgent'] = value; + addHeader('X-Forwarded-User-Agent', value); + return this; + } @override ClientBrowser setSelfSigned({bool status = true}) { @@ -136,8 +131,7 @@ class ClientBrowser extends ClientBase with ClientMixin { late Response res; if (size <= CHUNK_SIZE) { - params[paramName] = http.MultipartFile.fromBytes(paramName, file.data!, - filename: file.filename); + params[paramName] = http.MultipartFile.fromBytes(paramName, file.data!, filename: file.filename); return call( HttpMethod.post, path: path, @@ -163,10 +157,9 @@ class ClientBrowser extends ClientBase with ClientMixin { while (offset < size) { List chunk = []; final end = min(offset + CHUNK_SIZE, size); - chunk = - file.toBinary(length: offset, length: min(CHUNK_SIZE, size - offset)); - params[paramName] = http.MultipartFile.fromBytes(paramName, chunk, - filename: file.filename); + chunk = file.toBinary(length: offset, length: min(CHUNK_SIZE, size - offset)); + params[paramName] = + http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename); headers['content-range'] = 'bytes $offset-${min((offset + CHUNK_SIZE - 1), size - 1)}/$size'; res = await call(HttpMethod.post, diff --git a/lib/src/client_io.dart b/lib/src/client_io.dart index de1c2d3f..e841fdda 100644 --- a/lib/src/client_io.dart +++ b/lib/src/client_io.dart @@ -21,7 +21,7 @@ ClientBase createClient({ ); class ClientIO extends ClientBase with ClientMixin { - static const int CHUNK_SIZE = 5 * 1024 * 1024; + static const int CHUNK_SIZE = 5*1024*1024; String _endPoint; Map? _headers; @override @@ -43,10 +43,9 @@ class ClientIO extends ClientBase with ClientMixin { 'x-sdk-name': 'Dart', 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', - 'x-sdk-version': '13.0.0-rc1', - 'user-agent': - 'AppwriteDartSDK/13.0.0-rc1 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', - 'X-Appwrite-Response-Format': '1.6.0', + 'x-sdk-version': '13.0.0', + 'user-agent' : 'AppwriteDartSDK/13.0.0 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', + 'X-Appwrite-Response-Format' : '1.6.0', }; config = {}; @@ -58,52 +57,47 @@ class ClientIO extends ClientBase with ClientMixin { @override String get endPoint => _endPoint; - /// Your project ID - @override - ClientIO setProject(value) { - config['project'] = value; - addHeader('X-Appwrite-Project', value); - return this; - } - - /// Your secret API key - @override - ClientIO setKey(value) { - config['key'] = value; - addHeader('X-Appwrite-Key', value); - return this; - } - - /// Your secret JSON Web Token - @override - ClientIO setJWT(value) { - config['jWT'] = value; - addHeader('X-Appwrite-JWT', value); - return this; - } - - @override - ClientIO setLocale(value) { - config['locale'] = value; - addHeader('X-Appwrite-Locale', value); - return this; - } - - /// The user session to authenticate with - @override - ClientIO setSession(value) { - config['session'] = value; - addHeader('X-Appwrite-Session', value); - return this; - } - - /// The user agent string of the client that made the request - @override - ClientIO setForwardedUserAgent(value) { - config['forwardedUserAgent'] = value; - addHeader('X-Forwarded-User-Agent', value); - return this; - } + /// Your project ID + @override + ClientIO setProject(value) { + config['project'] = value; + addHeader('X-Appwrite-Project', value); + return this; + } + /// Your secret API key + @override + ClientIO setKey(value) { + config['key'] = value; + addHeader('X-Appwrite-Key', value); + return this; + } + /// Your secret JSON Web Token + @override + ClientIO setJWT(value) { + config['jWT'] = value; + addHeader('X-Appwrite-JWT', value); + return this; + } + @override + ClientIO setLocale(value) { + config['locale'] = value; + addHeader('X-Appwrite-Locale', value); + return this; + } + /// The user session to authenticate with + @override + ClientIO setSession(value) { + config['session'] = value; + addHeader('X-Appwrite-Session', value); + return this; + } + /// The user agent string of the client that made the request + @override + ClientIO setForwardedUserAgent(value) { + config['forwardedUserAgent'] = value; + addHeader('X-Forwarded-User-Agent', value); + return this; + } @override ClientIO setSelfSigned({bool status = true}) { @@ -191,14 +185,13 @@ class ClientIO extends ClientBase with ClientMixin { while (offset < size) { List chunk = []; if (file.data != null) { - chunk = file.toBinary( - offset: offset, length: min(CHUNK_SIZE, size - offset)); + chunk = file.toBinary(offset: offset, length: min(CHUNK_SIZE, size - offset)); } else { raf!.setPositionSync(offset); chunk = raf.readSync(CHUNK_SIZE); } - params[paramName] = http.MultipartFile.fromBytes(paramName, chunk, - filename: file.filename); + params[paramName] = + http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename); headers['content-range'] = 'bytes $offset-${min((offset + CHUNK_SIZE - 1), size - 1)}/$size'; res = await call(HttpMethod.post, diff --git a/lib/src/client_mixin.dart b/lib/src/client_mixin.dart index 5f35191d..f7dd73a7 100644 --- a/lib/src/client_mixin.dart +++ b/lib/src/client_mixin.dart @@ -50,7 +50,7 @@ mixin ClientMixin { } } else if (method == HttpMethod.get) { if (params.isNotEmpty) { - params = params.map((key, value) { + params = params.map((key, value){ if (value is int || value is double) { return MapEntry(key, value.toString()); } @@ -76,8 +76,7 @@ mixin ClientMixin { return request; } - Future prepareResponse(http.Response res, - {ResponseType? responseType}) async { + Future prepareResponse(http.Response res, {ResponseType? responseType}) async { responseType ??= ResponseType.json; String? warnings = res.headers['x-appwrite-warning']; @@ -107,10 +106,8 @@ mixin ClientMixin { } else { data = res.body; } - } else if ((res.headers['content-type'] ?? '') - .contains('multipart/form-data')) { - data = await _parseMultipart( - res.headers['content-type']!, Stream.value(res.bodyBytes)); + } else if((res.headers['content-type'] ?? '').contains('multipart/form-data')) { + data = await _parseMultipart(res.headers['content-type']!, Stream.value(res.bodyBytes)); return Response(data: data); } else { if (responseType == ResponseType.bytes) { @@ -122,24 +119,19 @@ mixin ClientMixin { return Response(data: data); } - Future toResponse( - http.StreamedResponse streamedResponse) async { - if (streamedResponse.statusCode == 204) { - return http.Response( - '', - streamedResponse.statusCode, - headers: streamedResponse.headers.map((k, v) => - k.toLowerCase() == 'content-type' - ? MapEntry(k, 'text/plain') - : MapEntry(k, v)), - request: streamedResponse.request, - isRedirect: streamedResponse.isRedirect, - persistentConnection: streamedResponse.persistentConnection, - reasonPhrase: streamedResponse.reasonPhrase, - ); - } else { - return await http.Response.fromStream(streamedResponse); - } + Future toResponse(http.StreamedResponse streamedResponse) async { + if(streamedResponse.statusCode == 204) { + return http.Response('', + streamedResponse.statusCode, + headers: streamedResponse.headers.map((k,v) => k.toLowerCase()=='content-type' ? MapEntry(k, 'text/plain') : MapEntry(k,v)), + request: streamedResponse.request, + isRedirect: streamedResponse.isRedirect, + persistentConnection: streamedResponse.persistentConnection, + reasonPhrase: streamedResponse.reasonPhrase, + ); + } else { + return await http.Response.fromStream(streamedResponse); + } } Future> _decodeMimeMultipart(MimeMultipart part) async { @@ -187,9 +179,8 @@ mixin ClientMixin { final Map out = {}; for (final item in data) { if (item!.name == 'responseBody') { - out[item.name] = Payload.fromBinary( - data: await _decodeMimeMultipart(item.value), - filename: item.filename); + out[item.name] = + Payload.fromBinary(data: await _decodeMimeMultipart(item.value), filename: item.filename); } else { out[item.name] = await item.value; } @@ -257,4 +248,4 @@ class _FormData { final String? filename; _FormData._(this.name, this.filename, this.value); -} +} \ No newline at end of file diff --git a/lib/src/enums/authentication_factor.dart b/lib/src/enums/authentication_factor.dart index 1d5271eb..00d12830 100644 --- a/lib/src/enums/authentication_factor.dart +++ b/lib/src/enums/authentication_factor.dart @@ -1,14 +1,16 @@ part of '../../enums.dart'; enum AuthenticationFactor { - email(value: 'email'), - phone(value: 'phone'), - totp(value: 'totp'), - recoverycode(value: 'recoverycode'); + email(value: 'email'), + phone(value: 'phone'), + totp(value: 'totp'), + recoverycode(value: 'recoverycode'); - const AuthenticationFactor({required this.value}); + const AuthenticationFactor({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/authenticator_type.dart b/lib/src/enums/authenticator_type.dart index c1fe8584..10460393 100644 --- a/lib/src/enums/authenticator_type.dart +++ b/lib/src/enums/authenticator_type.dart @@ -1,11 +1,13 @@ part of '../../enums.dart'; enum AuthenticatorType { - totp(value: 'totp'); + totp(value: 'totp'); - const AuthenticatorType({required this.value}); + const AuthenticatorType({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/browser.dart b/lib/src/enums/browser.dart index 949f4c47..386fa11d 100644 --- a/lib/src/enums/browser.dart +++ b/lib/src/enums/browser.dart @@ -1,24 +1,26 @@ part of '../../enums.dart'; enum Browser { - avantBrowser(value: 'aa'), - androidWebViewBeta(value: 'an'), - googleChrome(value: 'ch'), - googleChromeIOS(value: 'ci'), - googleChromeMobile(value: 'cm'), - chromium(value: 'cr'), - mozillaFirefox(value: 'ff'), - safari(value: 'sf'), - mobileSafari(value: 'mf'), - microsoftEdge(value: 'ps'), - microsoftEdgeIOS(value: 'oi'), - operaMini(value: 'om'), - opera(value: 'op'), - operaNext(value: 'on'); + avantBrowser(value: 'aa'), + androidWebViewBeta(value: 'an'), + googleChrome(value: 'ch'), + googleChromeIOS(value: 'ci'), + googleChromeMobile(value: 'cm'), + chromium(value: 'cr'), + mozillaFirefox(value: 'ff'), + safari(value: 'sf'), + mobileSafari(value: 'mf'), + microsoftEdge(value: 'ps'), + microsoftEdgeIOS(value: 'oi'), + operaMini(value: 'om'), + opera(value: 'op'), + operaNext(value: 'on'); - const Browser({required this.value}); + const Browser({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/compression.dart b/lib/src/enums/compression.dart index 768930d9..209acfb8 100644 --- a/lib/src/enums/compression.dart +++ b/lib/src/enums/compression.dart @@ -1,13 +1,15 @@ part of '../../enums.dart'; enum Compression { - none(value: 'none'), - gzip(value: 'gzip'), - zstd(value: 'zstd'); + none(value: 'none'), + gzip(value: 'gzip'), + zstd(value: 'zstd'); - const Compression({required this.value}); + const Compression({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/credit_card.dart b/lib/src/enums/credit_card.dart index 3a6b256a..878db2f0 100644 --- a/lib/src/enums/credit_card.dart +++ b/lib/src/enums/credit_card.dart @@ -1,26 +1,28 @@ part of '../../enums.dart'; enum CreditCard { - americanExpress(value: 'amex'), - argencard(value: 'argencard'), - cabal(value: 'cabal'), - cencosud(value: 'cencosud'), - dinersClub(value: 'diners'), - discover(value: 'discover'), - elo(value: 'elo'), - hipercard(value: 'hipercard'), - jCB(value: 'jcb'), - mastercard(value: 'mastercard'), - naranja(value: 'naranja'), - tarjetaShopping(value: 'targeta-shopping'), - unionChinaPay(value: 'union-china-pay'), - visa(value: 'visa'), - mIR(value: 'mir'), - maestro(value: 'maestro'); + americanExpress(value: 'amex'), + argencard(value: 'argencard'), + cabal(value: 'cabal'), + cencosud(value: 'cencosud'), + dinersClub(value: 'diners'), + discover(value: 'discover'), + elo(value: 'elo'), + hipercard(value: 'hipercard'), + jcb(value: 'jcb'), + mastercard(value: 'mastercard'), + naranja(value: 'naranja'), + tarjetaShopping(value: 'targeta-shopping'), + unionChinaPay(value: 'union-china-pay'), + visa(value: 'visa'), + mir(value: 'mir'), + maestro(value: 'maestro'); - const CreditCard({required this.value}); + const CreditCard({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/execution_method.dart b/lib/src/enums/execution_method.dart index 42954430..d6f43cf0 100644 --- a/lib/src/enums/execution_method.dart +++ b/lib/src/enums/execution_method.dart @@ -1,16 +1,18 @@ part of '../../enums.dart'; enum ExecutionMethod { - gET(value: 'GET'), - pOST(value: 'POST'), - pUT(value: 'PUT'), - pATCH(value: 'PATCH'), - dELETE(value: 'DELETE'), - oPTIONS(value: 'OPTIONS'); + get(value: 'GET'), + post(value: 'POST'), + put(value: 'PUT'), + patch(value: 'PATCH'), + delete(value: 'DELETE'), + options(value: 'OPTIONS'); - const ExecutionMethod({required this.value}); + const ExecutionMethod({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/flag.dart b/lib/src/enums/flag.dart index a44cb81d..27c25cac 100644 --- a/lib/src/enums/flag.dart +++ b/lib/src/enums/flag.dart @@ -1,205 +1,207 @@ part of '../../enums.dart'; enum Flag { - afghanistan(value: 'af'), - angola(value: 'ao'), - albania(value: 'al'), - andorra(value: 'ad'), - unitedArabEmirates(value: 'ae'), - argentina(value: 'ar'), - armenia(value: 'am'), - antiguaAndBarbuda(value: 'ag'), - australia(value: 'au'), - austria(value: 'at'), - azerbaijan(value: 'az'), - burundi(value: 'bi'), - belgium(value: 'be'), - benin(value: 'bj'), - burkinaFaso(value: 'bf'), - bangladesh(value: 'bd'), - bulgaria(value: 'bg'), - bahrain(value: 'bh'), - bahamas(value: 'bs'), - bosniaAndHerzegovina(value: 'ba'), - belarus(value: 'by'), - belize(value: 'bz'), - bolivia(value: 'bo'), - brazil(value: 'br'), - barbados(value: 'bb'), - bruneiDarussalam(value: 'bn'), - bhutan(value: 'bt'), - botswana(value: 'bw'), - centralAfricanRepublic(value: 'cf'), - canada(value: 'ca'), - switzerland(value: 'ch'), - chile(value: 'cl'), - china(value: 'cn'), - coteDIvoire(value: 'ci'), - cameroon(value: 'cm'), - democraticRepublicOfTheCongo(value: 'cd'), - republicOfTheCongo(value: 'cg'), - colombia(value: 'co'), - comoros(value: 'km'), - capeVerde(value: 'cv'), - costaRica(value: 'cr'), - cuba(value: 'cu'), - cyprus(value: 'cy'), - czechRepublic(value: 'cz'), - germany(value: 'de'), - djibouti(value: 'dj'), - dominica(value: 'dm'), - denmark(value: 'dk'), - dominicanRepublic(value: 'do'), - algeria(value: 'dz'), - ecuador(value: 'ec'), - egypt(value: 'eg'), - eritrea(value: 'er'), - spain(value: 'es'), - estonia(value: 'ee'), - ethiopia(value: 'et'), - finland(value: 'fi'), - fiji(value: 'fj'), - france(value: 'fr'), - micronesiaFederatedStatesOf(value: 'fm'), - gabon(value: 'ga'), - unitedKingdom(value: 'gb'), - georgia(value: 'ge'), - ghana(value: 'gh'), - guinea(value: 'gn'), - gambia(value: 'gm'), - guineaBissau(value: 'gw'), - equatorialGuinea(value: 'gq'), - greece(value: 'gr'), - grenada(value: 'gd'), - guatemala(value: 'gt'), - guyana(value: 'gy'), - honduras(value: 'hn'), - croatia(value: 'hr'), - haiti(value: 'ht'), - hungary(value: 'hu'), - indonesia(value: 'id'), - india(value: 'in'), - ireland(value: 'ie'), - iranIslamicRepublicOf(value: 'ir'), - iraq(value: 'iq'), - iceland(value: 'is'), - israel(value: 'il'), - italy(value: 'it'), - jamaica(value: 'jm'), - jordan(value: 'jo'), - japan(value: 'jp'), - kazakhstan(value: 'kz'), - kenya(value: 'ke'), - kyrgyzstan(value: 'kg'), - cambodia(value: 'kh'), - kiribati(value: 'ki'), - saintKittsAndNevis(value: 'kn'), - southKorea(value: 'kr'), - kuwait(value: 'kw'), - laoPeopleSDemocraticRepublic(value: 'la'), - lebanon(value: 'lb'), - liberia(value: 'lr'), - libya(value: 'ly'), - saintLucia(value: 'lc'), - liechtenstein(value: 'li'), - sriLanka(value: 'lk'), - lesotho(value: 'ls'), - lithuania(value: 'lt'), - luxembourg(value: 'lu'), - latvia(value: 'lv'), - morocco(value: 'ma'), - monaco(value: 'mc'), - moldova(value: 'md'), - madagascar(value: 'mg'), - maldives(value: 'mv'), - mexico(value: 'mx'), - marshallIslands(value: 'mh'), - northMacedonia(value: 'mk'), - mali(value: 'ml'), - malta(value: 'mt'), - myanmar(value: 'mm'), - montenegro(value: 'me'), - mongolia(value: 'mn'), - mozambique(value: 'mz'), - mauritania(value: 'mr'), - mauritius(value: 'mu'), - malawi(value: 'mw'), - malaysia(value: 'my'), - namibia(value: 'na'), - niger(value: 'ne'), - nigeria(value: 'ng'), - nicaragua(value: 'ni'), - netherlands(value: 'nl'), - norway(value: 'no'), - nepal(value: 'np'), - nauru(value: 'nr'), - newZealand(value: 'nz'), - oman(value: 'om'), - pakistan(value: 'pk'), - panama(value: 'pa'), - peru(value: 'pe'), - philippines(value: 'ph'), - palau(value: 'pw'), - papuaNewGuinea(value: 'pg'), - poland(value: 'pl'), - frenchPolynesia(value: 'pf'), - northKorea(value: 'kp'), - portugal(value: 'pt'), - paraguay(value: 'py'), - qatar(value: 'qa'), - romania(value: 'ro'), - russia(value: 'ru'), - rwanda(value: 'rw'), - saudiArabia(value: 'sa'), - sudan(value: 'sd'), - senegal(value: 'sn'), - singapore(value: 'sg'), - solomonIslands(value: 'sb'), - sierraLeone(value: 'sl'), - elSalvador(value: 'sv'), - sanMarino(value: 'sm'), - somalia(value: 'so'), - serbia(value: 'rs'), - southSudan(value: 'ss'), - saoTomeAndPrincipe(value: 'st'), - suriname(value: 'sr'), - slovakia(value: 'sk'), - slovenia(value: 'si'), - sweden(value: 'se'), - eswatini(value: 'sz'), - seychelles(value: 'sc'), - syria(value: 'sy'), - chad(value: 'td'), - togo(value: 'tg'), - thailand(value: 'th'), - tajikistan(value: 'tj'), - turkmenistan(value: 'tm'), - timorLeste(value: 'tl'), - tonga(value: 'to'), - trinidadAndTobago(value: 'tt'), - tunisia(value: 'tn'), - turkey(value: 'tr'), - tuvalu(value: 'tv'), - tanzania(value: 'tz'), - uganda(value: 'ug'), - ukraine(value: 'ua'), - uruguay(value: 'uy'), - unitedStates(value: 'us'), - uzbekistan(value: 'uz'), - vaticanCity(value: 'va'), - saintVincentAndTheGrenadines(value: 'vc'), - venezuela(value: 've'), - vietnam(value: 'vn'), - vanuatu(value: 'vu'), - samoa(value: 'ws'), - yemen(value: 'ye'), - southAfrica(value: 'za'), - zambia(value: 'zm'), - zimbabwe(value: 'zw'); + afghanistan(value: 'af'), + angola(value: 'ao'), + albania(value: 'al'), + andorra(value: 'ad'), + unitedArabEmirates(value: 'ae'), + argentina(value: 'ar'), + armenia(value: 'am'), + antiguaAndBarbuda(value: 'ag'), + australia(value: 'au'), + austria(value: 'at'), + azerbaijan(value: 'az'), + burundi(value: 'bi'), + belgium(value: 'be'), + benin(value: 'bj'), + burkinaFaso(value: 'bf'), + bangladesh(value: 'bd'), + bulgaria(value: 'bg'), + bahrain(value: 'bh'), + bahamas(value: 'bs'), + bosniaAndHerzegovina(value: 'ba'), + belarus(value: 'by'), + belize(value: 'bz'), + bolivia(value: 'bo'), + brazil(value: 'br'), + barbados(value: 'bb'), + bruneiDarussalam(value: 'bn'), + bhutan(value: 'bt'), + botswana(value: 'bw'), + centralAfricanRepublic(value: 'cf'), + canada(value: 'ca'), + switzerland(value: 'ch'), + chile(value: 'cl'), + china(value: 'cn'), + coteDIvoire(value: 'ci'), + cameroon(value: 'cm'), + democraticRepublicOfTheCongo(value: 'cd'), + republicOfTheCongo(value: 'cg'), + colombia(value: 'co'), + comoros(value: 'km'), + capeVerde(value: 'cv'), + costaRica(value: 'cr'), + cuba(value: 'cu'), + cyprus(value: 'cy'), + czechRepublic(value: 'cz'), + germany(value: 'de'), + djibouti(value: 'dj'), + dominica(value: 'dm'), + denmark(value: 'dk'), + dominicanRepublic(value: 'do'), + algeria(value: 'dz'), + ecuador(value: 'ec'), + egypt(value: 'eg'), + eritrea(value: 'er'), + spain(value: 'es'), + estonia(value: 'ee'), + ethiopia(value: 'et'), + finland(value: 'fi'), + fiji(value: 'fj'), + france(value: 'fr'), + micronesiaFederatedStatesOf(value: 'fm'), + gabon(value: 'ga'), + unitedKingdom(value: 'gb'), + georgia(value: 'ge'), + ghana(value: 'gh'), + guinea(value: 'gn'), + gambia(value: 'gm'), + guineaBissau(value: 'gw'), + equatorialGuinea(value: 'gq'), + greece(value: 'gr'), + grenada(value: 'gd'), + guatemala(value: 'gt'), + guyana(value: 'gy'), + honduras(value: 'hn'), + croatia(value: 'hr'), + haiti(value: 'ht'), + hungary(value: 'hu'), + indonesia(value: 'id'), + india(value: 'in'), + ireland(value: 'ie'), + iranIslamicRepublicOf(value: 'ir'), + iraq(value: 'iq'), + iceland(value: 'is'), + israel(value: 'il'), + italy(value: 'it'), + jamaica(value: 'jm'), + jordan(value: 'jo'), + japan(value: 'jp'), + kazakhstan(value: 'kz'), + kenya(value: 'ke'), + kyrgyzstan(value: 'kg'), + cambodia(value: 'kh'), + kiribati(value: 'ki'), + saintKittsAndNevis(value: 'kn'), + southKorea(value: 'kr'), + kuwait(value: 'kw'), + laoPeopleSDemocraticRepublic(value: 'la'), + lebanon(value: 'lb'), + liberia(value: 'lr'), + libya(value: 'ly'), + saintLucia(value: 'lc'), + liechtenstein(value: 'li'), + sriLanka(value: 'lk'), + lesotho(value: 'ls'), + lithuania(value: 'lt'), + luxembourg(value: 'lu'), + latvia(value: 'lv'), + morocco(value: 'ma'), + monaco(value: 'mc'), + moldova(value: 'md'), + madagascar(value: 'mg'), + maldives(value: 'mv'), + mexico(value: 'mx'), + marshallIslands(value: 'mh'), + northMacedonia(value: 'mk'), + mali(value: 'ml'), + malta(value: 'mt'), + myanmar(value: 'mm'), + montenegro(value: 'me'), + mongolia(value: 'mn'), + mozambique(value: 'mz'), + mauritania(value: 'mr'), + mauritius(value: 'mu'), + malawi(value: 'mw'), + malaysia(value: 'my'), + namibia(value: 'na'), + niger(value: 'ne'), + nigeria(value: 'ng'), + nicaragua(value: 'ni'), + netherlands(value: 'nl'), + norway(value: 'no'), + nepal(value: 'np'), + nauru(value: 'nr'), + newZealand(value: 'nz'), + oman(value: 'om'), + pakistan(value: 'pk'), + panama(value: 'pa'), + peru(value: 'pe'), + philippines(value: 'ph'), + palau(value: 'pw'), + papuaNewGuinea(value: 'pg'), + poland(value: 'pl'), + frenchPolynesia(value: 'pf'), + northKorea(value: 'kp'), + portugal(value: 'pt'), + paraguay(value: 'py'), + qatar(value: 'qa'), + romania(value: 'ro'), + russia(value: 'ru'), + rwanda(value: 'rw'), + saudiArabia(value: 'sa'), + sudan(value: 'sd'), + senegal(value: 'sn'), + singapore(value: 'sg'), + solomonIslands(value: 'sb'), + sierraLeone(value: 'sl'), + elSalvador(value: 'sv'), + sanMarino(value: 'sm'), + somalia(value: 'so'), + serbia(value: 'rs'), + southSudan(value: 'ss'), + saoTomeAndPrincipe(value: 'st'), + suriname(value: 'sr'), + slovakia(value: 'sk'), + slovenia(value: 'si'), + sweden(value: 'se'), + eswatini(value: 'sz'), + seychelles(value: 'sc'), + syria(value: 'sy'), + chad(value: 'td'), + togo(value: 'tg'), + thailand(value: 'th'), + tajikistan(value: 'tj'), + turkmenistan(value: 'tm'), + timorLeste(value: 'tl'), + tonga(value: 'to'), + trinidadAndTobago(value: 'tt'), + tunisia(value: 'tn'), + turkey(value: 'tr'), + tuvalu(value: 'tv'), + tanzania(value: 'tz'), + uganda(value: 'ug'), + ukraine(value: 'ua'), + uruguay(value: 'uy'), + unitedStates(value: 'us'), + uzbekistan(value: 'uz'), + vaticanCity(value: 'va'), + saintVincentAndTheGrenadines(value: 'vc'), + venezuela(value: 've'), + vietnam(value: 'vn'), + vanuatu(value: 'vu'), + samoa(value: 'ws'), + yemen(value: 'ye'), + southAfrica(value: 'za'), + zambia(value: 'zm'), + zimbabwe(value: 'zw'); - const Flag({required this.value}); + const Flag({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/image_format.dart b/lib/src/enums/image_format.dart index 2ab5d7b9..66527dfa 100644 --- a/lib/src/enums/image_format.dart +++ b/lib/src/enums/image_format.dart @@ -1,15 +1,17 @@ part of '../../enums.dart'; enum ImageFormat { - jpg(value: 'jpg'), - jpeg(value: 'jpeg'), - gif(value: 'gif'), - png(value: 'png'), - webp(value: 'webp'); + jpg(value: 'jpg'), + jpeg(value: 'jpeg'), + gif(value: 'gif'), + png(value: 'png'), + webp(value: 'webp'); - const ImageFormat({required this.value}); + const ImageFormat({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/image_gravity.dart b/lib/src/enums/image_gravity.dart index 88029044..79bc4d62 100644 --- a/lib/src/enums/image_gravity.dart +++ b/lib/src/enums/image_gravity.dart @@ -1,19 +1,21 @@ part of '../../enums.dart'; enum ImageGravity { - center(value: 'center'), - topLeft(value: 'top-left'), - top(value: 'top'), - topRight(value: 'top-right'), - left(value: 'left'), - right(value: 'right'), - bottomLeft(value: 'bottom-left'), - bottom(value: 'bottom'), - bottomRight(value: 'bottom-right'); + center(value: 'center'), + topLeft(value: 'top-left'), + top(value: 'top'), + topRight(value: 'top-right'), + left(value: 'left'), + right(value: 'right'), + bottomLeft(value: 'bottom-left'), + bottom(value: 'bottom'), + bottomRight(value: 'bottom-right'); - const ImageGravity({required this.value}); + const ImageGravity({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/index_type.dart b/lib/src/enums/index_type.dart index b101d35f..8d86530d 100644 --- a/lib/src/enums/index_type.dart +++ b/lib/src/enums/index_type.dart @@ -1,13 +1,15 @@ part of '../../enums.dart'; enum IndexType { - key(value: 'key'), - fulltext(value: 'fulltext'), - unique(value: 'unique'); + key(value: 'key'), + fulltext(value: 'fulltext'), + unique(value: 'unique'); - const IndexType({required this.value}); + const IndexType({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/messaging_provider_type.dart b/lib/src/enums/messaging_provider_type.dart index c69bf01e..a6859648 100644 --- a/lib/src/enums/messaging_provider_type.dart +++ b/lib/src/enums/messaging_provider_type.dart @@ -1,13 +1,15 @@ part of '../../enums.dart'; enum MessagingProviderType { - email(value: 'email'), - sms(value: 'sms'), - push(value: 'push'); + email(value: 'email'), + sms(value: 'sms'), + push(value: 'push'); - const MessagingProviderType({required this.value}); + const MessagingProviderType({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/name.dart b/lib/src/enums/name.dart index cb35c288..638017f7 100644 --- a/lib/src/enums/name.dart +++ b/lib/src/enums/name.dart @@ -1,22 +1,24 @@ part of '../../enums.dart'; enum Name { - v1Database(value: 'v1-database'), - v1Deletes(value: 'v1-deletes'), - v1Audits(value: 'v1-audits'), - v1Mails(value: 'v1-mails'), - v1Functions(value: 'v1-functions'), - v1Usage(value: 'v1-usage'), - v1UsageDump(value: 'v1-usage-dump'), - v1Webhooks(value: 'v1-webhooks'), - v1Certificates(value: 'v1-certificates'), - v1Builds(value: 'v1-builds'), - v1Messaging(value: 'v1-messaging'), - v1Migrations(value: 'v1-migrations'); + v1Database(value: 'v1-database'), + v1Deletes(value: 'v1-deletes'), + v1Audits(value: 'v1-audits'), + v1Mails(value: 'v1-mails'), + v1Functions(value: 'v1-functions'), + v1Usage(value: 'v1-usage'), + v1UsageDump(value: 'v1-usage-dump'), + v1Webhooks(value: 'v1-webhooks'), + v1Certificates(value: 'v1-certificates'), + v1Builds(value: 'v1-builds'), + v1Messaging(value: 'v1-messaging'), + v1Migrations(value: 'v1-migrations'); - const Name({required this.value}); + const Name({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/o_auth_provider.dart b/lib/src/enums/o_auth_provider.dart index 2bc1a82a..b09e9df2 100644 --- a/lib/src/enums/o_auth_provider.dart +++ b/lib/src/enums/o_auth_provider.dart @@ -1,49 +1,51 @@ part of '../../enums.dart'; enum OAuthProvider { - amazon(value: 'amazon'), - apple(value: 'apple'), - auth0(value: 'auth0'), - authentik(value: 'authentik'), - autodesk(value: 'autodesk'), - bitbucket(value: 'bitbucket'), - bitly(value: 'bitly'), - box(value: 'box'), - dailymotion(value: 'dailymotion'), - discord(value: 'discord'), - disqus(value: 'disqus'), - dropbox(value: 'dropbox'), - etsy(value: 'etsy'), - facebook(value: 'facebook'), - github(value: 'github'), - gitlab(value: 'gitlab'), - google(value: 'google'), - linkedin(value: 'linkedin'), - microsoft(value: 'microsoft'), - notion(value: 'notion'), - oidc(value: 'oidc'), - okta(value: 'okta'), - paypal(value: 'paypal'), - paypalSandbox(value: 'paypalSandbox'), - podio(value: 'podio'), - salesforce(value: 'salesforce'), - slack(value: 'slack'), - spotify(value: 'spotify'), - stripe(value: 'stripe'), - tradeshift(value: 'tradeshift'), - tradeshiftBox(value: 'tradeshiftBox'), - twitch(value: 'twitch'), - wordpress(value: 'wordpress'), - yahoo(value: 'yahoo'), - yammer(value: 'yammer'), - yandex(value: 'yandex'), - zoho(value: 'zoho'), - zoom(value: 'zoom'), - mock(value: 'mock'); + amazon(value: 'amazon'), + apple(value: 'apple'), + auth0(value: 'auth0'), + authentik(value: 'authentik'), + autodesk(value: 'autodesk'), + bitbucket(value: 'bitbucket'), + bitly(value: 'bitly'), + box(value: 'box'), + dailymotion(value: 'dailymotion'), + discord(value: 'discord'), + disqus(value: 'disqus'), + dropbox(value: 'dropbox'), + etsy(value: 'etsy'), + facebook(value: 'facebook'), + github(value: 'github'), + gitlab(value: 'gitlab'), + google(value: 'google'), + linkedin(value: 'linkedin'), + microsoft(value: 'microsoft'), + notion(value: 'notion'), + oidc(value: 'oidc'), + okta(value: 'okta'), + paypal(value: 'paypal'), + paypalSandbox(value: 'paypalSandbox'), + podio(value: 'podio'), + salesforce(value: 'salesforce'), + slack(value: 'slack'), + spotify(value: 'spotify'), + stripe(value: 'stripe'), + tradeshift(value: 'tradeshift'), + tradeshiftBox(value: 'tradeshiftBox'), + twitch(value: 'twitch'), + wordpress(value: 'wordpress'), + yahoo(value: 'yahoo'), + yammer(value: 'yammer'), + yandex(value: 'yandex'), + zoho(value: 'zoho'), + zoom(value: 'zoom'), + mock(value: 'mock'); - const OAuthProvider({required this.value}); + const OAuthProvider({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/password_hash.dart b/lib/src/enums/password_hash.dart index 9d98c26a..510ee260 100644 --- a/lib/src/enums/password_hash.dart +++ b/lib/src/enums/password_hash.dart @@ -1,21 +1,23 @@ part of '../../enums.dart'; enum PasswordHash { - sha1(value: 'sha1'), - sha224(value: 'sha224'), - sha256(value: 'sha256'), - sha384(value: 'sha384'), - sha512224(value: 'sha512/224'), - sha512256(value: 'sha512/256'), - sha512(value: 'sha512'), - sha3224(value: 'sha3-224'), - sha3256(value: 'sha3-256'), - sha3384(value: 'sha3-384'), - sha3512(value: 'sha3-512'); + sha1(value: 'sha1'), + sha224(value: 'sha224'), + sha256(value: 'sha256'), + sha384(value: 'sha384'), + sha512224(value: 'sha512/224'), + sha512256(value: 'sha512/256'), + sha512(value: 'sha512'), + sha3224(value: 'sha3-224'), + sha3256(value: 'sha3-256'), + sha3384(value: 'sha3-384'), + sha3512(value: 'sha3-512'); - const PasswordHash({required this.value}); + const PasswordHash({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/relation_mutate.dart b/lib/src/enums/relation_mutate.dart index b215a8fa..9f4c1a85 100644 --- a/lib/src/enums/relation_mutate.dart +++ b/lib/src/enums/relation_mutate.dart @@ -1,13 +1,15 @@ part of '../../enums.dart'; enum RelationMutate { - cascade(value: 'cascade'), - restrict(value: 'restrict'), - setNull(value: 'setNull'); + cascade(value: 'cascade'), + restrict(value: 'restrict'), + setNull(value: 'setNull'); - const RelationMutate({required this.value}); + const RelationMutate({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/relationship_type.dart b/lib/src/enums/relationship_type.dart index 30efc944..301bc61d 100644 --- a/lib/src/enums/relationship_type.dart +++ b/lib/src/enums/relationship_type.dart @@ -1,14 +1,16 @@ part of '../../enums.dart'; enum RelationshipType { - oneToOne(value: 'oneToOne'), - manyToOne(value: 'manyToOne'), - manyToMany(value: 'manyToMany'), - oneToMany(value: 'oneToMany'); + oneToOne(value: 'oneToOne'), + manyToOne(value: 'manyToOne'), + manyToMany(value: 'manyToMany'), + oneToMany(value: 'oneToMany'); - const RelationshipType({required this.value}); + const RelationshipType({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/runtime.dart b/lib/src/enums/runtime.dart index a4868100..6a0aec49 100644 --- a/lib/src/enums/runtime.dart +++ b/lib/src/enums/runtime.dart @@ -1,59 +1,61 @@ part of '../../enums.dart'; enum Runtime { - node145(value: 'node-14.5'), - node160(value: 'node-16.0'), - node180(value: 'node-18.0'), - node190(value: 'node-19.0'), - node200(value: 'node-20.0'), - node210(value: 'node-21.0'), - php80(value: 'php-8.0'), - php81(value: 'php-8.1'), - php82(value: 'php-8.2'), - php83(value: 'php-8.3'), - ruby30(value: 'ruby-3.0'), - ruby31(value: 'ruby-3.1'), - ruby32(value: 'ruby-3.2'), - ruby33(value: 'ruby-3.3'), - python38(value: 'python-3.8'), - python39(value: 'python-3.9'), - python310(value: 'python-3.10'), - python311(value: 'python-3.11'), - python312(value: 'python-3.12'), - pythonMl311(value: 'python-ml-3.11'), - deno121(value: 'deno-1.21'), - deno124(value: 'deno-1.24'), - deno135(value: 'deno-1.35'), - deno140(value: 'deno-1.40'), - dart215(value: 'dart-2.15'), - dart216(value: 'dart-2.16'), - dart217(value: 'dart-2.17'), - dart218(value: 'dart-2.18'), - dart30(value: 'dart-3.0'), - dart31(value: 'dart-3.1'), - dart33(value: 'dart-3.3'), - dotnet31(value: 'dotnet-3.1'), - dotnet60(value: 'dotnet-6.0'), - dotnet70(value: 'dotnet-7.0'), - java80(value: 'java-8.0'), - java110(value: 'java-11.0'), - java170(value: 'java-17.0'), - java180(value: 'java-18.0'), - java210(value: 'java-21.0'), - swift55(value: 'swift-5.5'), - swift58(value: 'swift-5.8'), - swift59(value: 'swift-5.9'), - kotlin16(value: 'kotlin-1.6'), - kotlin18(value: 'kotlin-1.8'), - kotlin19(value: 'kotlin-1.9'), - cpp17(value: 'cpp-17'), - cpp20(value: 'cpp-20'), - bun10(value: 'bun-1.0'), - go123(value: 'go-1.23'); + node145(value: 'node-14.5'), + node160(value: 'node-16.0'), + node180(value: 'node-18.0'), + node190(value: 'node-19.0'), + node200(value: 'node-20.0'), + node210(value: 'node-21.0'), + php80(value: 'php-8.0'), + php81(value: 'php-8.1'), + php82(value: 'php-8.2'), + php83(value: 'php-8.3'), + ruby30(value: 'ruby-3.0'), + ruby31(value: 'ruby-3.1'), + ruby32(value: 'ruby-3.2'), + ruby33(value: 'ruby-3.3'), + python38(value: 'python-3.8'), + python39(value: 'python-3.9'), + python310(value: 'python-3.10'), + python311(value: 'python-3.11'), + python312(value: 'python-3.12'), + pythonMl311(value: 'python-ml-3.11'), + deno121(value: 'deno-1.21'), + deno124(value: 'deno-1.24'), + deno135(value: 'deno-1.35'), + deno140(value: 'deno-1.40'), + dart215(value: 'dart-2.15'), + dart216(value: 'dart-2.16'), + dart217(value: 'dart-2.17'), + dart218(value: 'dart-2.18'), + dart30(value: 'dart-3.0'), + dart31(value: 'dart-3.1'), + dart33(value: 'dart-3.3'), + dotnet31(value: 'dotnet-3.1'), + dotnet60(value: 'dotnet-6.0'), + dotnet70(value: 'dotnet-7.0'), + java80(value: 'java-8.0'), + java110(value: 'java-11.0'), + java170(value: 'java-17.0'), + java180(value: 'java-18.0'), + java210(value: 'java-21.0'), + swift55(value: 'swift-5.5'), + swift58(value: 'swift-5.8'), + swift59(value: 'swift-5.9'), + kotlin16(value: 'kotlin-1.6'), + kotlin18(value: 'kotlin-1.8'), + kotlin19(value: 'kotlin-1.9'), + cpp17(value: 'cpp-17'), + cpp20(value: 'cpp-20'), + bun10(value: 'bun-1.0'), + go123(value: 'go-1.23'); - const Runtime({required this.value}); + const Runtime({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/smtp_encryption.dart b/lib/src/enums/smtp_encryption.dart index cb6cee26..6c880ed6 100644 --- a/lib/src/enums/smtp_encryption.dart +++ b/lib/src/enums/smtp_encryption.dart @@ -1,13 +1,15 @@ part of '../../enums.dart'; enum SmtpEncryption { - none(value: 'none'), - ssl(value: 'ssl'), - tls(value: 'tls'); + none(value: 'none'), + ssl(value: 'ssl'), + tls(value: 'tls'); - const SmtpEncryption({required this.value}); + const SmtpEncryption({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/exception.dart b/lib/src/exception.dart index 679e27b8..f579bfb8 100644 --- a/lib/src/exception.dart +++ b/lib/src/exception.dart @@ -13,7 +13,7 @@ class AppwriteException implements Exception { /// Initializes an Appwrite Exception. AppwriteException([this.message = "", this.code, this.type, this.response]); - + /// Returns the error type, message, and code. @override String toString() { diff --git a/lib/src/models/algo_argon2.dart b/lib/src/models/algo_argon2.dart index 9ad2e41e..92fa2593 100644 --- a/lib/src/models/algo_argon2.dart +++ b/lib/src/models/algo_argon2.dart @@ -2,46 +2,40 @@ part of '../../models.dart'; /// AlgoArgon2 class AlgoArgon2 implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; + /// Memory used to compute hash. + final int memoryCost; + /// Amount of time consumed to compute hash + final int timeCost; + /// Number of threads used to compute hash. + final int threads; - /// Memory used to compute hash. - final int memoryCost; + AlgoArgon2({ + required this.type, + required this.memoryCost, + required this.timeCost, + required this.threads, + }); - /// Amount of time consumed to compute hash - final int timeCost; + factory AlgoArgon2.fromMap(Map map) { + return AlgoArgon2( + type: map['type'].toString(), + memoryCost: (map['memoryCost'] is String) ? + int.tryParse(map['memoryCost']) ?? 0:map['memoryCost'] ?? 0, + timeCost: (map['timeCost'] is String) ? + int.tryParse(map['timeCost']) ?? 0:map['timeCost'] ?? 0, + threads: (map['threads'] is String) ? + int.tryParse(map['threads']) ?? 0:map['threads'] ?? 0, + ); + } - /// Number of threads used to compute hash. - final int threads; - - AlgoArgon2({ - required this.type, - required this.memoryCost, - required this.timeCost, - required this.threads, - }); - - factory AlgoArgon2.fromMap(Map map) { - return AlgoArgon2( - type: map['type'].toString(), - memoryCost: (map['memoryCost'] is String) - ? int.tryParse(map['memoryCost']) ?? 0 - : map['memoryCost'] ?? 0, - timeCost: (map['timeCost'] is String) - ? int.tryParse(map['timeCost']) ?? 0 - : map['timeCost'] ?? 0, - threads: (map['threads'] is String) - ? int.tryParse(map['threads']) ?? 0 - : map['threads'] ?? 0, - ); - } - - Map toMap() { - return { - "type": type, - "memoryCost": memoryCost, - "timeCost": timeCost, - "threads": threads, - }; - } + Map toMap() { + return { + "type": type, + "memoryCost": memoryCost, + "timeCost": timeCost, + "threads": threads, + }; + } } diff --git a/lib/src/models/algo_bcrypt.dart b/lib/src/models/algo_bcrypt.dart index 2ba0c398..c9f67200 100644 --- a/lib/src/models/algo_bcrypt.dart +++ b/lib/src/models/algo_bcrypt.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoBcrypt class AlgoBcrypt implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoBcrypt({ - required this.type, - }); + AlgoBcrypt({ + required this.type, + }); - factory AlgoBcrypt.fromMap(Map map) { - return AlgoBcrypt( - type: map['type'].toString(), - ); - } + factory AlgoBcrypt.fromMap(Map map) { + return AlgoBcrypt( + type: map['type'].toString(), + ); + } - Map toMap() { - return { - "type": type, - }; - } + Map toMap() { + return { + "type": type, + }; + } } diff --git a/lib/src/models/algo_md5.dart b/lib/src/models/algo_md5.dart index 8bdfca6f..2fabb416 100644 --- a/lib/src/models/algo_md5.dart +++ b/lib/src/models/algo_md5.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoMD5 class AlgoMd5 implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoMd5({ - required this.type, - }); + AlgoMd5({ + required this.type, + }); - factory AlgoMd5.fromMap(Map map) { - return AlgoMd5( - type: map['type'].toString(), - ); - } + factory AlgoMd5.fromMap(Map map) { + return AlgoMd5( + type: map['type'].toString(), + ); + } - Map toMap() { - return { - "type": type, - }; - } + Map toMap() { + return { + "type": type, + }; + } } diff --git a/lib/src/models/algo_phpass.dart b/lib/src/models/algo_phpass.dart index 4f5f9179..fdcee07a 100644 --- a/lib/src/models/algo_phpass.dart +++ b/lib/src/models/algo_phpass.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoPHPass class AlgoPhpass implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoPhpass({ - required this.type, - }); + AlgoPhpass({ + required this.type, + }); - factory AlgoPhpass.fromMap(Map map) { - return AlgoPhpass( - type: map['type'].toString(), - ); - } + factory AlgoPhpass.fromMap(Map map) { + return AlgoPhpass( + type: map['type'].toString(), + ); + } - Map toMap() { - return { - "type": type, - }; - } + Map toMap() { + return { + "type": type, + }; + } } diff --git a/lib/src/models/algo_scrypt.dart b/lib/src/models/algo_scrypt.dart index ee54b5e4..c3e55453 100644 --- a/lib/src/models/algo_scrypt.dart +++ b/lib/src/models/algo_scrypt.dart @@ -2,54 +2,46 @@ part of '../../models.dart'; /// AlgoScrypt class AlgoScrypt implements Model { - /// Algo type. - final String type; - - /// CPU complexity of computed hash. - final int costCpu; - - /// Memory complexity of computed hash. - final int costMemory; - - /// Parallelization of computed hash. - final int costParallel; - - /// Length used to compute hash. - final int length; - - AlgoScrypt({ - required this.type, - required this.costCpu, - required this.costMemory, - required this.costParallel, - required this.length, - }); - - factory AlgoScrypt.fromMap(Map map) { - return AlgoScrypt( - type: map['type'].toString(), - costCpu: (map['costCpu'] is String) - ? int.tryParse(map['costCpu']) ?? 0 - : map['costCpu'] ?? 0, - costMemory: (map['costMemory'] is String) - ? int.tryParse(map['costMemory']) ?? 0 - : map['costMemory'] ?? 0, - costParallel: (map['costParallel'] is String) - ? int.tryParse(map['costParallel']) ?? 0 - : map['costParallel'] ?? 0, - length: (map['length'] is String) - ? int.tryParse(map['length']) ?? 0 - : map['length'] ?? 0, - ); - } - - Map toMap() { - return { - "type": type, - "costCpu": costCpu, - "costMemory": costMemory, - "costParallel": costParallel, - "length": length, - }; - } + /// Algo type. + final String type; + /// CPU complexity of computed hash. + final int costCpu; + /// Memory complexity of computed hash. + final int costMemory; + /// Parallelization of computed hash. + final int costParallel; + /// Length used to compute hash. + final int length; + + AlgoScrypt({ + required this.type, + required this.costCpu, + required this.costMemory, + required this.costParallel, + required this.length, + }); + + factory AlgoScrypt.fromMap(Map map) { + return AlgoScrypt( + type: map['type'].toString(), + costCpu: (map['costCpu'] is String) ? + int.tryParse(map['costCpu']) ?? 0:map['costCpu'] ?? 0, + costMemory: (map['costMemory'] is String) ? + int.tryParse(map['costMemory']) ?? 0:map['costMemory'] ?? 0, + costParallel: (map['costParallel'] is String) ? + int.tryParse(map['costParallel']) ?? 0:map['costParallel'] ?? 0, + length: (map['length'] is String) ? + int.tryParse(map['length']) ?? 0:map['length'] ?? 0, + ); + } + + Map toMap() { + return { + "type": type, + "costCpu": costCpu, + "costMemory": costMemory, + "costParallel": costParallel, + "length": length, + }; + } } diff --git a/lib/src/models/algo_scrypt_modified.dart b/lib/src/models/algo_scrypt_modified.dart index 0e80700f..b10b14a6 100644 --- a/lib/src/models/algo_scrypt_modified.dart +++ b/lib/src/models/algo_scrypt_modified.dart @@ -2,40 +2,37 @@ part of '../../models.dart'; /// AlgoScryptModified class AlgoScryptModified implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; + /// Salt used to compute hash. + final String salt; + /// Separator used to compute hash. + final String saltSeparator; + /// Key used to compute hash. + final String signerKey; - /// Salt used to compute hash. - final String salt; + AlgoScryptModified({ + required this.type, + required this.salt, + required this.saltSeparator, + required this.signerKey, + }); - /// Separator used to compute hash. - final String saltSeparator; + factory AlgoScryptModified.fromMap(Map map) { + return AlgoScryptModified( + type: map['type'].toString(), + salt: map['salt'].toString(), + saltSeparator: map['saltSeparator'].toString(), + signerKey: map['signerKey'].toString(), + ); + } - /// Key used to compute hash. - final String signerKey; - - AlgoScryptModified({ - required this.type, - required this.salt, - required this.saltSeparator, - required this.signerKey, - }); - - factory AlgoScryptModified.fromMap(Map map) { - return AlgoScryptModified( - type: map['type'].toString(), - salt: map['salt'].toString(), - saltSeparator: map['saltSeparator'].toString(), - signerKey: map['signerKey'].toString(), - ); - } - - Map toMap() { - return { - "type": type, - "salt": salt, - "saltSeparator": saltSeparator, - "signerKey": signerKey, - }; - } + Map toMap() { + return { + "type": type, + "salt": salt, + "saltSeparator": saltSeparator, + "signerKey": signerKey, + }; + } } diff --git a/lib/src/models/algo_sha.dart b/lib/src/models/algo_sha.dart index 47068be0..5f3e1654 100644 --- a/lib/src/models/algo_sha.dart +++ b/lib/src/models/algo_sha.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoSHA class AlgoSha implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoSha({ - required this.type, - }); + AlgoSha({ + required this.type, + }); - factory AlgoSha.fromMap(Map map) { - return AlgoSha( - type: map['type'].toString(), - ); - } + factory AlgoSha.fromMap(Map map) { + return AlgoSha( + type: map['type'].toString(), + ); + } - Map toMap() { - return { - "type": type, - }; - } + Map toMap() { + return { + "type": type, + }; + } } diff --git a/lib/src/models/attribute_boolean.dart b/lib/src/models/attribute_boolean.dart index 0b8ca599..480c2042 100644 --- a/lib/src/models/attribute_boolean.dart +++ b/lib/src/models/attribute_boolean.dart @@ -2,58 +2,52 @@ part of '../../models.dart'; /// AttributeBoolean class AttributeBoolean implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final bool? xdefault; - - AttributeBoolean({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - this.xdefault, - }); - - factory AttributeBoolean.fromMap(Map map) { - return AttributeBoolean( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - xdefault: map['default'], - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final bool? xdefault; + + AttributeBoolean({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + this.xdefault, + }); + + factory AttributeBoolean.fromMap(Map map) { + return AttributeBoolean( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + xdefault: map['default'], + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_datetime.dart b/lib/src/models/attribute_datetime.dart index c4c96637..078a0723 100644 --- a/lib/src/models/attribute_datetime.dart +++ b/lib/src/models/attribute_datetime.dart @@ -2,64 +2,57 @@ part of '../../models.dart'; /// AttributeDatetime class AttributeDatetime implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// ISO 8601 format. - final String format; - - /// Default value for attribute when not provided. Only null is optional - final String? xdefault; - - AttributeDatetime({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.format, - this.xdefault, - }); - - factory AttributeDatetime.fromMap(Map map) { - return AttributeDatetime( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "format": format, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// ISO 8601 format. + final String format; + /// Default value for attribute when not provided. Only null is optional + final String? xdefault; + + AttributeDatetime({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.format, + this.xdefault, + }); + + factory AttributeDatetime.fromMap(Map map) { + return AttributeDatetime( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_email.dart b/lib/src/models/attribute_email.dart index 5d2fc8bd..08a67934 100644 --- a/lib/src/models/attribute_email.dart +++ b/lib/src/models/attribute_email.dart @@ -2,64 +2,57 @@ part of '../../models.dart'; /// AttributeEmail class AttributeEmail implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// String format. - final String format; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeEmail({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.format, - this.xdefault, - }); - - factory AttributeEmail.fromMap(Map map) { - return AttributeEmail( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "format": format, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// String format. + final String format; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeEmail({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.format, + this.xdefault, + }); + + factory AttributeEmail.fromMap(Map map) { + return AttributeEmail( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_enum.dart b/lib/src/models/attribute_enum.dart index 0017a44e..d461ecf4 100644 --- a/lib/src/models/attribute_enum.dart +++ b/lib/src/models/attribute_enum.dart @@ -2,70 +2,62 @@ part of '../../models.dart'; /// AttributeEnum class AttributeEnum implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Array of elements in enumerated type. - final List elements; - - /// String format. - final String format; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeEnum({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.elements, - required this.format, - this.xdefault, - }); - - factory AttributeEnum.fromMap(Map map) { - return AttributeEnum( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - elements: map['elements'] ?? [], - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "elements": elements, - "format": format, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Array of elements in enumerated type. + final List elements; + /// String format. + final String format; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeEnum({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.elements, + required this.format, + this.xdefault, + }); + + factory AttributeEnum.fromMap(Map map) { + return AttributeEnum( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + elements: map['elements'] ?? [], + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "elements": elements, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_float.dart b/lib/src/models/attribute_float.dart index 7c982afb..6d085aa4 100644 --- a/lib/src/models/attribute_float.dart +++ b/lib/src/models/attribute_float.dart @@ -2,70 +2,62 @@ part of '../../models.dart'; /// AttributeFloat class AttributeFloat implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Minimum value to enforce for new documents. - final double? min; - - /// Maximum value to enforce for new documents. - final double? max; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final double? xdefault; - - AttributeFloat({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - this.min, - this.max, - this.xdefault, - }); - - factory AttributeFloat.fromMap(Map map) { - return AttributeFloat( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - min: map['min']?.toDouble(), - max: map['max']?.toDouble(), - xdefault: map['default']?.toDouble(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "min": min, - "max": max, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Minimum value to enforce for new documents. + final double? min; + /// Maximum value to enforce for new documents. + final double? max; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final double? xdefault; + + AttributeFloat({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + this.min, + this.max, + this.xdefault, + }); + + factory AttributeFloat.fromMap(Map map) { + return AttributeFloat( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + min: map['min']?.toDouble(), + max: map['max']?.toDouble(), + xdefault: map['default']?.toDouble(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "min": min, + "max": max, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_integer.dart b/lib/src/models/attribute_integer.dart index 4c74127c..83e36858 100644 --- a/lib/src/models/attribute_integer.dart +++ b/lib/src/models/attribute_integer.dart @@ -2,72 +2,65 @@ part of '../../models.dart'; /// AttributeInteger class AttributeInteger implements Model { - /// Attribute Key. - final String key; + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Minimum value to enforce for new documents. + final int? min; + /// Maximum value to enforce for new documents. + final int? max; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final int? xdefault; - /// Attribute type. - final String type; + AttributeInteger({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + this.min, + this.max, + this.xdefault, + }); - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; + factory AttributeInteger.fromMap(Map map) { + return AttributeInteger( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + min: (map['min'] is String) ? + int.tryParse(map['min']):map['min'], + max: (map['max'] is String) ? + int.tryParse(map['max']):map['max'], + xdefault: (map['default'] is String) ? + int.tryParse(map['default']):map['default'], + ); + } - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Minimum value to enforce for new documents. - final int? min; - - /// Maximum value to enforce for new documents. - final int? max; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final int? xdefault; - - AttributeInteger({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - this.min, - this.max, - this.xdefault, - }); - - factory AttributeInteger.fromMap(Map map) { - return AttributeInteger( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - min: (map['min'] is String) ? int.tryParse(map['min']) : map['min'], - max: (map['max'] is String) ? int.tryParse(map['max']) : map['max'], - xdefault: (map['default'] is String) - ? int.tryParse(map['default']) - : map['default'], - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "min": min, - "max": max, - "default": xdefault, - }; - } + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "min": min, + "max": max, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_ip.dart b/lib/src/models/attribute_ip.dart index a63dd566..960f7064 100644 --- a/lib/src/models/attribute_ip.dart +++ b/lib/src/models/attribute_ip.dart @@ -2,64 +2,57 @@ part of '../../models.dart'; /// AttributeIP class AttributeIp implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// String format. - final String format; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeIp({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.format, - this.xdefault, - }); - - factory AttributeIp.fromMap(Map map) { - return AttributeIp( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "format": format, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// String format. + final String format; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeIp({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.format, + this.xdefault, + }); + + factory AttributeIp.fromMap(Map map) { + return AttributeIp( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_list.dart b/lib/src/models/attribute_list.dart index bf51398c..e15a0b35 100644 --- a/lib/src/models/attribute_list.dart +++ b/lib/src/models/attribute_list.dart @@ -2,30 +2,28 @@ part of '../../models.dart'; /// Attributes List class AttributeList implements Model { - /// Total number of attributes in the given collection. - final int total; + /// Total number of attributes in the given collection. + final int total; + /// List of attributes. + final List attributes; - /// List of attributes. - final List attributes; + AttributeList({ + required this.total, + required this.attributes, + }); - AttributeList({ - required this.total, - required this.attributes, - }); + factory AttributeList.fromMap(Map map) { + return AttributeList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + attributes: map['attributes'] ?? [], + ); + } - factory AttributeList.fromMap(Map map) { - return AttributeList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - attributes: map['attributes'] ?? [], - ); - } - - Map toMap() { - return { - "total": total, - "attributes": attributes, - }; - } + Map toMap() { + return { + "total": total, + "attributes": attributes, + }; + } } diff --git a/lib/src/models/attribute_relationship.dart b/lib/src/models/attribute_relationship.dart index 0230d9f9..d22c30d4 100644 --- a/lib/src/models/attribute_relationship.dart +++ b/lib/src/models/attribute_relationship.dart @@ -2,88 +2,77 @@ part of '../../models.dart'; /// AttributeRelationship class AttributeRelationship implements Model { - /// Attribute Key. - final String key; + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// The ID of the related collection. + final String relatedCollection; + /// The type of the relationship. + final String relationType; + /// Is the relationship two-way? + final bool twoWay; + /// The key of the two-way relationship. + final String twoWayKey; + /// How deleting the parent document will propagate to child documents. + final String onDelete; + /// Whether this is the parent or child side of the relationship + final String side; - /// Attribute type. - final String type; + AttributeRelationship({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.relatedCollection, + required this.relationType, + required this.twoWay, + required this.twoWayKey, + required this.onDelete, + required this.side, + }); - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; + factory AttributeRelationship.fromMap(Map map) { + return AttributeRelationship( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + relatedCollection: map['relatedCollection'].toString(), + relationType: map['relationType'].toString(), + twoWay: map['twoWay'], + twoWayKey: map['twoWayKey'].toString(), + onDelete: map['onDelete'].toString(), + side: map['side'].toString(), + ); + } - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// The ID of the related collection. - final String relatedCollection; - - /// The type of the relationship. - final String relationType; - - /// Is the relationship two-way? - final bool twoWay; - - /// The key of the two-way relationship. - final String twoWayKey; - - /// How deleting the parent document will propagate to child documents. - final String onDelete; - - /// Whether this is the parent or child side of the relationship - final String side; - - AttributeRelationship({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.relatedCollection, - required this.relationType, - required this.twoWay, - required this.twoWayKey, - required this.onDelete, - required this.side, - }); - - factory AttributeRelationship.fromMap(Map map) { - return AttributeRelationship( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - relatedCollection: map['relatedCollection'].toString(), - relationType: map['relationType'].toString(), - twoWay: map['twoWay'], - twoWayKey: map['twoWayKey'].toString(), - onDelete: map['onDelete'].toString(), - side: map['side'].toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "relatedCollection": relatedCollection, - "relationType": relationType, - "twoWay": twoWay, - "twoWayKey": twoWayKey, - "onDelete": onDelete, - "side": side, - }; - } + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "relatedCollection": relatedCollection, + "relationType": relationType, + "twoWay": twoWay, + "twoWayKey": twoWayKey, + "onDelete": onDelete, + "side": side, + }; + } } diff --git a/lib/src/models/attribute_string.dart b/lib/src/models/attribute_string.dart index 39c82811..c483317c 100644 --- a/lib/src/models/attribute_string.dart +++ b/lib/src/models/attribute_string.dart @@ -2,66 +2,58 @@ part of '../../models.dart'; /// AttributeString class AttributeString implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Attribute size. - final int size; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeString({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.size, - this.xdefault, - }); - - factory AttributeString.fromMap(Map map) { - return AttributeString( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - size: (map['size'] is String) - ? int.tryParse(map['size']) ?? 0 - : map['size'] ?? 0, - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "size": size, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Attribute size. + final int size; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeString({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.size, + this.xdefault, + }); + + factory AttributeString.fromMap(Map map) { + return AttributeString( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + size: (map['size'] is String) ? + int.tryParse(map['size']) ?? 0:map['size'] ?? 0, + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "size": size, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_url.dart b/lib/src/models/attribute_url.dart index 0a0d183f..691cfcf6 100644 --- a/lib/src/models/attribute_url.dart +++ b/lib/src/models/attribute_url.dart @@ -2,64 +2,57 @@ part of '../../models.dart'; /// AttributeURL class AttributeUrl implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// String format. - final String format; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeUrl({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.format, - this.xdefault, - }); - - factory AttributeUrl.fromMap(Map map) { - return AttributeUrl( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "format": format, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// String format. + final String format; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeUrl({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.format, + this.xdefault, + }); + + factory AttributeUrl.fromMap(Map map) { + return AttributeUrl( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/bucket.dart b/lib/src/models/bucket.dart index 4db92627..b72c0392 100644 --- a/lib/src/models/bucket.dart +++ b/lib/src/models/bucket.dart @@ -2,90 +2,78 @@ part of '../../models.dart'; /// Bucket class Bucket implements Model { - /// Bucket ID. - final String $id; + /// Bucket ID. + final String $id; + /// Bucket creation time in ISO 8601 format. + final String $createdAt; + /// Bucket update date in ISO 8601 format. + final String $updatedAt; + /// Bucket permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List $permissions; + /// Whether file-level security is enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). + final bool fileSecurity; + /// Bucket name. + final String name; + /// Bucket enabled. + final bool enabled; + /// Maximum file size supported. + final int maximumFileSize; + /// Allowed file extensions. + final List allowedFileExtensions; + /// Compression algorithm choosen for compression. Will be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd). + final String compression; + /// Bucket is encrypted. + final bool encryption; + /// Virus scanning is enabled. + final bool antivirus; - /// Bucket creation time in ISO 8601 format. - final String $createdAt; + Bucket({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.fileSecurity, + required this.name, + required this.enabled, + required this.maximumFileSize, + required this.allowedFileExtensions, + required this.compression, + required this.encryption, + required this.antivirus, + }); - /// Bucket update date in ISO 8601 format. - final String $updatedAt; + factory Bucket.fromMap(Map map) { + return Bucket( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + fileSecurity: map['fileSecurity'], + name: map['name'].toString(), + enabled: map['enabled'], + maximumFileSize: (map['maximumFileSize'] is String) ? + int.tryParse(map['maximumFileSize']) ?? 0:map['maximumFileSize'] ?? 0, + allowedFileExtensions: map['allowedFileExtensions'] ?? [], + compression: map['compression'].toString(), + encryption: map['encryption'], + antivirus: map['antivirus'], + ); + } - /// Bucket permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List $permissions; - - /// Whether file-level security is enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). - final bool fileSecurity; - - /// Bucket name. - final String name; - - /// Bucket enabled. - final bool enabled; - - /// Maximum file size supported. - final int maximumFileSize; - - /// Allowed file extensions. - final List allowedFileExtensions; - - /// Compression algorithm choosen for compression. Will be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd). - final String compression; - - /// Bucket is encrypted. - final bool encryption; - - /// Virus scanning is enabled. - final bool antivirus; - - Bucket({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.fileSecurity, - required this.name, - required this.enabled, - required this.maximumFileSize, - required this.allowedFileExtensions, - required this.compression, - required this.encryption, - required this.antivirus, - }); - - factory Bucket.fromMap(Map map) { - return Bucket( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - fileSecurity: map['fileSecurity'], - name: map['name'].toString(), - enabled: map['enabled'], - maximumFileSize: (map['maximumFileSize'] is String) - ? int.tryParse(map['maximumFileSize']) ?? 0 - : map['maximumFileSize'] ?? 0, - allowedFileExtensions: map['allowedFileExtensions'] ?? [], - compression: map['compression'].toString(), - encryption: map['encryption'], - antivirus: map['antivirus'], - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "fileSecurity": fileSecurity, - "name": name, - "enabled": enabled, - "maximumFileSize": maximumFileSize, - "allowedFileExtensions": allowedFileExtensions, - "compression": compression, - "encryption": encryption, - "antivirus": antivirus, - }; - } + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "fileSecurity": fileSecurity, + "name": name, + "enabled": enabled, + "maximumFileSize": maximumFileSize, + "allowedFileExtensions": allowedFileExtensions, + "compression": compression, + "encryption": encryption, + "antivirus": antivirus, + }; + } } diff --git a/lib/src/models/bucket_list.dart b/lib/src/models/bucket_list.dart index 70b61a9e..7687eb6e 100644 --- a/lib/src/models/bucket_list.dart +++ b/lib/src/models/bucket_list.dart @@ -2,30 +2,28 @@ part of '../../models.dart'; /// Buckets List class BucketList implements Model { - /// Total number of buckets documents that matched your query. - final int total; + /// Total number of buckets documents that matched your query. + final int total; + /// List of buckets. + final List buckets; - /// List of buckets. - final List buckets; + BucketList({ + required this.total, + required this.buckets, + }); - BucketList({ - required this.total, - required this.buckets, - }); + factory BucketList.fromMap(Map map) { + return BucketList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + buckets: List.from(map['buckets'].map((p) => Bucket.fromMap(p))), + ); + } - factory BucketList.fromMap(Map map) { - return BucketList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - buckets: List.from(map['buckets'].map((p) => Bucket.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "buckets": buckets.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "buckets": buckets.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/build.dart b/lib/src/models/build.dart index 65bde1ba..4c12e283 100644 --- a/lib/src/models/build.dart +++ b/lib/src/models/build.dart @@ -2,74 +2,64 @@ part of '../../models.dart'; /// Build class Build implements Model { - /// Build ID. - final String $id; + /// Build ID. + final String $id; + /// The deployment that created this build. + final String deploymentId; + /// The build status. There are a few different types and each one means something different. \nFailed - The deployment build has failed. More details can usually be found in buildStderr\nReady - The deployment build was successful and the deployment is ready to be deployed\nProcessing - The deployment is currently waiting to have a build triggered\nBuilding - The deployment is currently being built + final String status; + /// The stdout of the build. + final String stdout; + /// The stderr of the build. + final String stderr; + /// The deployment creation date in ISO 8601 format. + final String startTime; + /// The time the build was finished in ISO 8601 format. + final String endTime; + /// The build duration in seconds. + final int duration; + /// The code size in bytes. + final int size; - /// The deployment that created this build. - final String deploymentId; + Build({ + required this.$id, + required this.deploymentId, + required this.status, + required this.stdout, + required this.stderr, + required this.startTime, + required this.endTime, + required this.duration, + required this.size, + }); - /// The build status. There are a few different types and each one means something different. \nFailed - The deployment build has failed. More details can usually be found in buildStderr\nReady - The deployment build was successful and the deployment is ready to be deployed\nProcessing - The deployment is currently waiting to have a build triggered\nBuilding - The deployment is currently being built - final String status; + factory Build.fromMap(Map map) { + return Build( + $id: map['\$id'].toString(), + deploymentId: map['deploymentId'].toString(), + status: map['status'].toString(), + stdout: map['stdout'].toString(), + stderr: map['stderr'].toString(), + startTime: map['startTime'].toString(), + endTime: map['endTime'].toString(), + duration: (map['duration'] is String) ? + int.tryParse(map['duration']) ?? 0:map['duration'] ?? 0, + size: (map['size'] is String) ? + int.tryParse(map['size']) ?? 0:map['size'] ?? 0, + ); + } - /// The stdout of the build. - final String stdout; - - /// The stderr of the build. - final String stderr; - - /// The deployment creation date in ISO 8601 format. - final String startTime; - - /// The time the build was finished in ISO 8601 format. - final String endTime; - - /// The build duration in seconds. - final int duration; - - /// The code size in bytes. - final int size; - - Build({ - required this.$id, - required this.deploymentId, - required this.status, - required this.stdout, - required this.stderr, - required this.startTime, - required this.endTime, - required this.duration, - required this.size, - }); - - factory Build.fromMap(Map map) { - return Build( - $id: map['\$id'].toString(), - deploymentId: map['deploymentId'].toString(), - status: map['status'].toString(), - stdout: map['stdout'].toString(), - stderr: map['stderr'].toString(), - startTime: map['startTime'].toString(), - endTime: map['endTime'].toString(), - duration: (map['duration'] is String) - ? int.tryParse(map['duration']) ?? 0 - : map['duration'] ?? 0, - size: (map['size'] is String) - ? int.tryParse(map['size']) ?? 0 - : map['size'] ?? 0, - ); - } - - Map toMap() { - return { - "\$id": $id, - "deploymentId": deploymentId, - "status": status, - "stdout": stdout, - "stderr": stderr, - "startTime": startTime, - "endTime": endTime, - "duration": duration, - "size": size, - }; - } + Map toMap() { + return { + "\$id": $id, + "deploymentId": deploymentId, + "status": status, + "stdout": stdout, + "stderr": stderr, + "startTime": startTime, + "endTime": endTime, + "duration": duration, + "size": size, + }; + } } diff --git a/lib/src/models/collection.dart b/lib/src/models/collection.dart index 2595cd2f..d4649f55 100644 --- a/lib/src/models/collection.dart +++ b/lib/src/models/collection.dart @@ -2,76 +2,67 @@ part of '../../models.dart'; /// Collection class Collection implements Model { - /// Collection ID. - final String $id; + /// Collection ID. + final String $id; + /// Collection creation date in ISO 8601 format. + final String $createdAt; + /// Collection update date in ISO 8601 format. + final String $updatedAt; + /// Collection permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List $permissions; + /// Database ID. + final String databaseId; + /// Collection name. + final String name; + /// Collection enabled. Can be 'enabled' or 'disabled'. When disabled, the collection is inaccessible to users, but remains accessible to Server SDKs using API keys. + final bool enabled; + /// Whether document-level permissions are enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). + final bool documentSecurity; + /// Collection attributes. + final List attributes; + /// Collection indexes. + final List indexes; - /// Collection creation date in ISO 8601 format. - final String $createdAt; + Collection({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.databaseId, + required this.name, + required this.enabled, + required this.documentSecurity, + required this.attributes, + required this.indexes, + }); - /// Collection update date in ISO 8601 format. - final String $updatedAt; + factory Collection.fromMap(Map map) { + return Collection( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + databaseId: map['databaseId'].toString(), + name: map['name'].toString(), + enabled: map['enabled'], + documentSecurity: map['documentSecurity'], + attributes: map['attributes'] ?? [], + indexes: List.from(map['indexes'].map((p) => Index.fromMap(p))), + ); + } - /// Collection permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List $permissions; - - /// Database ID. - final String databaseId; - - /// Collection name. - final String name; - - /// Collection enabled. Can be 'enabled' or 'disabled'. When disabled, the collection is inaccessible to users, but remains accessible to Server SDKs using API keys. - final bool enabled; - - /// Whether document-level permissions are enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). - final bool documentSecurity; - - /// Collection attributes. - final List attributes; - - /// Collection indexes. - final List indexes; - - Collection({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.databaseId, - required this.name, - required this.enabled, - required this.documentSecurity, - required this.attributes, - required this.indexes, - }); - - factory Collection.fromMap(Map map) { - return Collection( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - databaseId: map['databaseId'].toString(), - name: map['name'].toString(), - enabled: map['enabled'], - documentSecurity: map['documentSecurity'], - attributes: map['attributes'] ?? [], - indexes: List.from(map['indexes'].map((p) => Index.fromMap(p))), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "databaseId": databaseId, - "name": name, - "enabled": enabled, - "documentSecurity": documentSecurity, - "attributes": attributes, - "indexes": indexes.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "databaseId": databaseId, + "name": name, + "enabled": enabled, + "documentSecurity": documentSecurity, + "attributes": attributes, + "indexes": indexes.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/collection_list.dart b/lib/src/models/collection_list.dart index 8e9bddb5..732bbf89 100644 --- a/lib/src/models/collection_list.dart +++ b/lib/src/models/collection_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Collections List class CollectionList implements Model { - /// Total number of collections documents that matched your query. - final int total; + /// Total number of collections documents that matched your query. + final int total; + /// List of collections. + final List collections; - /// List of collections. - final List collections; + CollectionList({ + required this.total, + required this.collections, + }); - CollectionList({ - required this.total, - required this.collections, - }); + factory CollectionList.fromMap(Map map) { + return CollectionList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + collections: List.from(map['collections'].map((p) => Collection.fromMap(p))), + ); + } - factory CollectionList.fromMap(Map map) { - return CollectionList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - collections: List.from( - map['collections'].map((p) => Collection.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "collections": collections.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "collections": collections.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/continent.dart b/lib/src/models/continent.dart index 990b1064..e1772f0d 100644 --- a/lib/src/models/continent.dart +++ b/lib/src/models/continent.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Continent class Continent implements Model { - /// Continent name. - final String name; + /// Continent name. + final String name; + /// Continent two letter code. + final String code; - /// Continent two letter code. - final String code; + Continent({ + required this.name, + required this.code, + }); - Continent({ - required this.name, - required this.code, - }); + factory Continent.fromMap(Map map) { + return Continent( + name: map['name'].toString(), + code: map['code'].toString(), + ); + } - factory Continent.fromMap(Map map) { - return Continent( - name: map['name'].toString(), - code: map['code'].toString(), - ); - } - - Map toMap() { - return { - "name": name, - "code": code, - }; - } + Map toMap() { + return { + "name": name, + "code": code, + }; + } } diff --git a/lib/src/models/continent_list.dart b/lib/src/models/continent_list.dart index 6064a8a2..d6c60999 100644 --- a/lib/src/models/continent_list.dart +++ b/lib/src/models/continent_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Continents List class ContinentList implements Model { - /// Total number of continents documents that matched your query. - final int total; + /// Total number of continents documents that matched your query. + final int total; + /// List of continents. + final List continents; - /// List of continents. - final List continents; + ContinentList({ + required this.total, + required this.continents, + }); - ContinentList({ - required this.total, - required this.continents, - }); + factory ContinentList.fromMap(Map map) { + return ContinentList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + continents: List.from(map['continents'].map((p) => Continent.fromMap(p))), + ); + } - factory ContinentList.fromMap(Map map) { - return ContinentList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - continents: List.from( - map['continents'].map((p) => Continent.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "continents": continents.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "continents": continents.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/country.dart b/lib/src/models/country.dart index d11c55db..b8757434 100644 --- a/lib/src/models/country.dart +++ b/lib/src/models/country.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Country class Country implements Model { - /// Country name. - final String name; + /// Country name. + final String name; + /// Country two-character ISO 3166-1 alpha code. + final String code; - /// Country two-character ISO 3166-1 alpha code. - final String code; + Country({ + required this.name, + required this.code, + }); - Country({ - required this.name, - required this.code, - }); + factory Country.fromMap(Map map) { + return Country( + name: map['name'].toString(), + code: map['code'].toString(), + ); + } - factory Country.fromMap(Map map) { - return Country( - name: map['name'].toString(), - code: map['code'].toString(), - ); - } - - Map toMap() { - return { - "name": name, - "code": code, - }; - } + Map toMap() { + return { + "name": name, + "code": code, + }; + } } diff --git a/lib/src/models/country_list.dart b/lib/src/models/country_list.dart index 3ff4a391..996b6aff 100644 --- a/lib/src/models/country_list.dart +++ b/lib/src/models/country_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Countries List class CountryList implements Model { - /// Total number of countries documents that matched your query. - final int total; + /// Total number of countries documents that matched your query. + final int total; + /// List of countries. + final List countries; - /// List of countries. - final List countries; + CountryList({ + required this.total, + required this.countries, + }); - CountryList({ - required this.total, - required this.countries, - }); + factory CountryList.fromMap(Map map) { + return CountryList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + countries: List.from(map['countries'].map((p) => Country.fromMap(p))), + ); + } - factory CountryList.fromMap(Map map) { - return CountryList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - countries: - List.from(map['countries'].map((p) => Country.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "countries": countries.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "countries": countries.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/currency.dart b/lib/src/models/currency.dart index 7ab4bb5c..1d0a3ed5 100644 --- a/lib/src/models/currency.dart +++ b/lib/src/models/currency.dart @@ -2,60 +2,53 @@ part of '../../models.dart'; /// Currency class Currency implements Model { - /// Currency symbol. - final String symbol; - - /// Currency name. - final String name; - - /// Currency native symbol. - final String symbolNative; - - /// Number of decimal digits. - final int decimalDigits; - - /// Currency digit rounding. - final double rounding; - - /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format. - final String code; - - /// Currency plural name - final String namePlural; - - Currency({ - required this.symbol, - required this.name, - required this.symbolNative, - required this.decimalDigits, - required this.rounding, - required this.code, - required this.namePlural, - }); - - factory Currency.fromMap(Map map) { - return Currency( - symbol: map['symbol'].toString(), - name: map['name'].toString(), - symbolNative: map['symbolNative'].toString(), - decimalDigits: (map['decimalDigits'] is String) - ? int.tryParse(map['decimalDigits']) ?? 0 - : map['decimalDigits'] ?? 0, - rounding: map['rounding'].toDouble(), - code: map['code'].toString(), - namePlural: map['namePlural'].toString(), - ); - } - - Map toMap() { - return { - "symbol": symbol, - "name": name, - "symbolNative": symbolNative, - "decimalDigits": decimalDigits, - "rounding": rounding, - "code": code, - "namePlural": namePlural, - }; - } + /// Currency symbol. + final String symbol; + /// Currency name. + final String name; + /// Currency native symbol. + final String symbolNative; + /// Number of decimal digits. + final int decimalDigits; + /// Currency digit rounding. + final double rounding; + /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format. + final String code; + /// Currency plural name + final String namePlural; + + Currency({ + required this.symbol, + required this.name, + required this.symbolNative, + required this.decimalDigits, + required this.rounding, + required this.code, + required this.namePlural, + }); + + factory Currency.fromMap(Map map) { + return Currency( + symbol: map['symbol'].toString(), + name: map['name'].toString(), + symbolNative: map['symbolNative'].toString(), + decimalDigits: (map['decimalDigits'] is String) ? + int.tryParse(map['decimalDigits']) ?? 0:map['decimalDigits'] ?? 0, + rounding: map['rounding'].toDouble(), + code: map['code'].toString(), + namePlural: map['namePlural'].toString(), + ); + } + + Map toMap() { + return { + "symbol": symbol, + "name": name, + "symbolNative": symbolNative, + "decimalDigits": decimalDigits, + "rounding": rounding, + "code": code, + "namePlural": namePlural, + }; + } } diff --git a/lib/src/models/currency_list.dart b/lib/src/models/currency_list.dart index d5f50881..c1cd94e1 100644 --- a/lib/src/models/currency_list.dart +++ b/lib/src/models/currency_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Currencies List class CurrencyList implements Model { - /// Total number of currencies documents that matched your query. - final int total; + /// Total number of currencies documents that matched your query. + final int total; + /// List of currencies. + final List currencies; - /// List of currencies. - final List currencies; + CurrencyList({ + required this.total, + required this.currencies, + }); - CurrencyList({ - required this.total, - required this.currencies, - }); + factory CurrencyList.fromMap(Map map) { + return CurrencyList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + currencies: List.from(map['currencies'].map((p) => Currency.fromMap(p))), + ); + } - factory CurrencyList.fromMap(Map map) { - return CurrencyList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - currencies: List.from( - map['currencies'].map((p) => Currency.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "currencies": currencies.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "currencies": currencies.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/database.dart b/lib/src/models/database.dart index 298a46a3..8eb9253b 100644 --- a/lib/src/models/database.dart +++ b/lib/src/models/database.dart @@ -2,46 +2,42 @@ part of '../../models.dart'; /// Database class Database implements Model { - /// Database ID. - final String $id; - - /// Database name. - final String name; - - /// Database creation date in ISO 8601 format. - final String $createdAt; - - /// Database update date in ISO 8601 format. - final String $updatedAt; - - /// If database is enabled. Can be 'enabled' or 'disabled'. When disabled, the database is inaccessible to users, but remains accessible to Server SDKs using API keys. - final bool enabled; - - Database({ - required this.$id, - required this.name, - required this.$createdAt, - required this.$updatedAt, - required this.enabled, - }); - - factory Database.fromMap(Map map) { - return Database( - $id: map['\$id'].toString(), - name: map['name'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - enabled: map['enabled'], - ); - } - - Map toMap() { - return { - "\$id": $id, - "name": name, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "enabled": enabled, - }; - } + /// Database ID. + final String $id; + /// Database name. + final String name; + /// Database creation date in ISO 8601 format. + final String $createdAt; + /// Database update date in ISO 8601 format. + final String $updatedAt; + /// If database is enabled. Can be 'enabled' or 'disabled'. When disabled, the database is inaccessible to users, but remains accessible to Server SDKs using API keys. + final bool enabled; + + Database({ + required this.$id, + required this.name, + required this.$createdAt, + required this.$updatedAt, + required this.enabled, + }); + + factory Database.fromMap(Map map) { + return Database( + $id: map['\$id'].toString(), + name: map['name'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + enabled: map['enabled'], + ); + } + + Map toMap() { + return { + "\$id": $id, + "name": name, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "enabled": enabled, + }; + } } diff --git a/lib/src/models/database_list.dart b/lib/src/models/database_list.dart index 0df34d5f..861b3c4f 100644 --- a/lib/src/models/database_list.dart +++ b/lib/src/models/database_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Databases List class DatabaseList implements Model { - /// Total number of databases documents that matched your query. - final int total; + /// Total number of databases documents that matched your query. + final int total; + /// List of databases. + final List databases; - /// List of databases. - final List databases; + DatabaseList({ + required this.total, + required this.databases, + }); - DatabaseList({ - required this.total, - required this.databases, - }); + factory DatabaseList.fromMap(Map map) { + return DatabaseList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + databases: List.from(map['databases'].map((p) => Database.fromMap(p))), + ); + } - factory DatabaseList.fromMap(Map map) { - return DatabaseList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - databases: - List.from(map['databases'].map((p) => Database.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "databases": databases.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "databases": databases.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/deployment.dart b/lib/src/models/deployment.dart index 1a1ce096..1c066b55 100644 --- a/lib/src/models/deployment.dart +++ b/lib/src/models/deployment.dart @@ -2,166 +2,140 @@ part of '../../models.dart'; /// Deployment class Deployment implements Model { - /// Deployment ID. - final String $id; - - /// Deployment creation date in ISO 8601 format. - final String $createdAt; - - /// Deployment update date in ISO 8601 format. - final String $updatedAt; - - /// Type of deployment. - final String type; - - /// Resource ID. - final String resourceId; - - /// Resource type. - final String resourceType; - - /// The entrypoint file to use to execute the deployment code. - final String entrypoint; - - /// The code size in bytes. - final int size; - - /// The build output size in bytes. - final int buildSize; - - /// The current build ID. - final String buildId; - - /// Whether the deployment should be automatically activated. - final bool activate; - - /// The deployment status. Possible values are "processing", "building", "waiting", "ready", and "failed". - final String status; - - /// The build logs. - final String buildLogs; - - /// The current build time in seconds. - final int buildTime; - - /// The name of the vcs provider repository - final String providerRepositoryName; - - /// The name of the vcs provider repository owner - final String providerRepositoryOwner; - - /// The url of the vcs provider repository - final String providerRepositoryUrl; - - /// The branch of the vcs repository - final String providerBranch; - - /// The commit hash of the vcs commit - final String providerCommitHash; - - /// The url of vcs commit author - final String providerCommitAuthorUrl; - - /// The name of vcs commit author - final String providerCommitAuthor; - - /// The commit message - final String providerCommitMessage; - - /// The url of the vcs commit - final String providerCommitUrl; - - /// The branch of the vcs repository - final String providerBranchUrl; - - Deployment({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.type, - required this.resourceId, - required this.resourceType, - required this.entrypoint, - required this.size, - required this.buildSize, - required this.buildId, - required this.activate, - required this.status, - required this.buildLogs, - required this.buildTime, - required this.providerRepositoryName, - required this.providerRepositoryOwner, - required this.providerRepositoryUrl, - required this.providerBranch, - required this.providerCommitHash, - required this.providerCommitAuthorUrl, - required this.providerCommitAuthor, - required this.providerCommitMessage, - required this.providerCommitUrl, - required this.providerBranchUrl, - }); - - factory Deployment.fromMap(Map map) { - return Deployment( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - type: map['type'].toString(), - resourceId: map['resourceId'].toString(), - resourceType: map['resourceType'].toString(), - entrypoint: map['entrypoint'].toString(), - size: (map['size'] is String) - ? int.tryParse(map['size']) ?? 0 - : map['size'] ?? 0, - buildSize: (map['buildSize'] is String) - ? int.tryParse(map['buildSize']) ?? 0 - : map['buildSize'] ?? 0, - buildId: map['buildId'].toString(), - activate: map['activate'], - status: map['status'].toString(), - buildLogs: map['buildLogs'].toString(), - buildTime: (map['buildTime'] is String) - ? int.tryParse(map['buildTime']) ?? 0 - : map['buildTime'] ?? 0, - providerRepositoryName: map['providerRepositoryName'].toString(), - providerRepositoryOwner: map['providerRepositoryOwner'].toString(), - providerRepositoryUrl: map['providerRepositoryUrl'].toString(), - providerBranch: map['providerBranch'].toString(), - providerCommitHash: map['providerCommitHash'].toString(), - providerCommitAuthorUrl: map['providerCommitAuthorUrl'].toString(), - providerCommitAuthor: map['providerCommitAuthor'].toString(), - providerCommitMessage: map['providerCommitMessage'].toString(), - providerCommitUrl: map['providerCommitUrl'].toString(), - providerBranchUrl: map['providerBranchUrl'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "type": type, - "resourceId": resourceId, - "resourceType": resourceType, - "entrypoint": entrypoint, - "size": size, - "buildSize": buildSize, - "buildId": buildId, - "activate": activate, - "status": status, - "buildLogs": buildLogs, - "buildTime": buildTime, - "providerRepositoryName": providerRepositoryName, - "providerRepositoryOwner": providerRepositoryOwner, - "providerRepositoryUrl": providerRepositoryUrl, - "providerBranch": providerBranch, - "providerCommitHash": providerCommitHash, - "providerCommitAuthorUrl": providerCommitAuthorUrl, - "providerCommitAuthor": providerCommitAuthor, - "providerCommitMessage": providerCommitMessage, - "providerCommitUrl": providerCommitUrl, - "providerBranchUrl": providerBranchUrl, - }; - } + /// Deployment ID. + final String $id; + /// Deployment creation date in ISO 8601 format. + final String $createdAt; + /// Deployment update date in ISO 8601 format. + final String $updatedAt; + /// Type of deployment. + final String type; + /// Resource ID. + final String resourceId; + /// Resource type. + final String resourceType; + /// The entrypoint file to use to execute the deployment code. + final String entrypoint; + /// The code size in bytes. + final int size; + /// The build output size in bytes. + final int buildSize; + /// The current build ID. + final String buildId; + /// Whether the deployment should be automatically activated. + final bool activate; + /// The deployment status. Possible values are "processing", "building", "waiting", "ready", and "failed". + final String status; + /// The build logs. + final String buildLogs; + /// The current build time in seconds. + final int buildTime; + /// The name of the vcs provider repository + final String providerRepositoryName; + /// The name of the vcs provider repository owner + final String providerRepositoryOwner; + /// The url of the vcs provider repository + final String providerRepositoryUrl; + /// The branch of the vcs repository + final String providerBranch; + /// The commit hash of the vcs commit + final String providerCommitHash; + /// The url of vcs commit author + final String providerCommitAuthorUrl; + /// The name of vcs commit author + final String providerCommitAuthor; + /// The commit message + final String providerCommitMessage; + /// The url of the vcs commit + final String providerCommitUrl; + /// The branch of the vcs repository + final String providerBranchUrl; + + Deployment({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.type, + required this.resourceId, + required this.resourceType, + required this.entrypoint, + required this.size, + required this.buildSize, + required this.buildId, + required this.activate, + required this.status, + required this.buildLogs, + required this.buildTime, + required this.providerRepositoryName, + required this.providerRepositoryOwner, + required this.providerRepositoryUrl, + required this.providerBranch, + required this.providerCommitHash, + required this.providerCommitAuthorUrl, + required this.providerCommitAuthor, + required this.providerCommitMessage, + required this.providerCommitUrl, + required this.providerBranchUrl, + }); + + factory Deployment.fromMap(Map map) { + return Deployment( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + type: map['type'].toString(), + resourceId: map['resourceId'].toString(), + resourceType: map['resourceType'].toString(), + entrypoint: map['entrypoint'].toString(), + size: (map['size'] is String) ? + int.tryParse(map['size']) ?? 0:map['size'] ?? 0, + buildSize: (map['buildSize'] is String) ? + int.tryParse(map['buildSize']) ?? 0:map['buildSize'] ?? 0, + buildId: map['buildId'].toString(), + activate: map['activate'], + status: map['status'].toString(), + buildLogs: map['buildLogs'].toString(), + buildTime: (map['buildTime'] is String) ? + int.tryParse(map['buildTime']) ?? 0:map['buildTime'] ?? 0, + providerRepositoryName: map['providerRepositoryName'].toString(), + providerRepositoryOwner: map['providerRepositoryOwner'].toString(), + providerRepositoryUrl: map['providerRepositoryUrl'].toString(), + providerBranch: map['providerBranch'].toString(), + providerCommitHash: map['providerCommitHash'].toString(), + providerCommitAuthorUrl: map['providerCommitAuthorUrl'].toString(), + providerCommitAuthor: map['providerCommitAuthor'].toString(), + providerCommitMessage: map['providerCommitMessage'].toString(), + providerCommitUrl: map['providerCommitUrl'].toString(), + providerBranchUrl: map['providerBranchUrl'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "type": type, + "resourceId": resourceId, + "resourceType": resourceType, + "entrypoint": entrypoint, + "size": size, + "buildSize": buildSize, + "buildId": buildId, + "activate": activate, + "status": status, + "buildLogs": buildLogs, + "buildTime": buildTime, + "providerRepositoryName": providerRepositoryName, + "providerRepositoryOwner": providerRepositoryOwner, + "providerRepositoryUrl": providerRepositoryUrl, + "providerBranch": providerBranch, + "providerCommitHash": providerCommitHash, + "providerCommitAuthorUrl": providerCommitAuthorUrl, + "providerCommitAuthor": providerCommitAuthor, + "providerCommitMessage": providerCommitMessage, + "providerCommitUrl": providerCommitUrl, + "providerBranchUrl": providerBranchUrl, + }; + } } diff --git a/lib/src/models/deployment_list.dart b/lib/src/models/deployment_list.dart index 087d9766..ddc014f9 100644 --- a/lib/src/models/deployment_list.dart +++ b/lib/src/models/deployment_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Deployments List class DeploymentList implements Model { - /// Total number of deployments documents that matched your query. - final int total; + /// Total number of deployments documents that matched your query. + final int total; + /// List of deployments. + final List deployments; - /// List of deployments. - final List deployments; + DeploymentList({ + required this.total, + required this.deployments, + }); - DeploymentList({ - required this.total, - required this.deployments, - }); + factory DeploymentList.fromMap(Map map) { + return DeploymentList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + deployments: List.from(map['deployments'].map((p) => Deployment.fromMap(p))), + ); + } - factory DeploymentList.fromMap(Map map) { - return DeploymentList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - deployments: List.from( - map['deployments'].map((p) => Deployment.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "deployments": deployments.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "deployments": deployments.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/document.dart b/lib/src/models/document.dart index 6406f06a..d5b8c77e 100644 --- a/lib/src/models/document.dart +++ b/lib/src/models/document.dart @@ -2,58 +2,53 @@ part of '../../models.dart'; /// Document class Document implements Model { - /// Document ID. - final String $id; - - /// Collection ID. - final String $collectionId; - - /// Database ID. - final String $databaseId; - - /// Document creation date in ISO 8601 format. - final String $createdAt; - - /// Document update date in ISO 8601 format. - final String $updatedAt; - - /// Document permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List $permissions; - final Map data; - - Document({ - required this.$id, - required this.$collectionId, - required this.$databaseId, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.data, - }); - - factory Document.fromMap(Map map) { - return Document( - $id: map['\$id'].toString(), - $collectionId: map['\$collectionId'].toString(), - $databaseId: map['\$databaseId'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - data: map, - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$collectionId": $collectionId, - "\$databaseId": $databaseId, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "data": data, - }; - } - - T convertTo(T Function(Map) fromJson) => fromJson(data); + /// Document ID. + final String $id; + /// Collection ID. + final String $collectionId; + /// Database ID. + final String $databaseId; + /// Document creation date in ISO 8601 format. + final String $createdAt; + /// Document update date in ISO 8601 format. + final String $updatedAt; + /// Document permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List $permissions; + final Map data; + + Document({ + required this.$id, + required this.$collectionId, + required this.$databaseId, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.data, + }); + + factory Document.fromMap(Map map) { + return Document( + $id: map['\$id'].toString(), + $collectionId: map['\$collectionId'].toString(), + $databaseId: map['\$databaseId'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + data: map, + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$collectionId": $collectionId, + "\$databaseId": $databaseId, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "data": data, + }; + } + + T convertTo(T Function(Map) fromJson) => fromJson(data); } diff --git a/lib/src/models/document_list.dart b/lib/src/models/document_list.dart index 1e25b09e..c418b48e 100644 --- a/lib/src/models/document_list.dart +++ b/lib/src/models/document_list.dart @@ -2,34 +2,31 @@ part of '../../models.dart'; /// Documents List class DocumentList implements Model { - /// Total number of documents documents that matched your query. - final int total; + /// Total number of documents documents that matched your query. + final int total; + /// List of documents. + final List documents; - /// List of documents. - final List documents; + DocumentList({ + required this.total, + required this.documents, + }); - DocumentList({ - required this.total, - required this.documents, - }); + factory DocumentList.fromMap(Map map) { + return DocumentList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + documents: List.from(map['documents'].map((p) => Document.fromMap(p))), + ); + } - factory DocumentList.fromMap(Map map) { - return DocumentList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - documents: - List.from(map['documents'].map((p) => Document.fromMap(p))), - ); - } + Map toMap() { + return { + "total": total, + "documents": documents.map((p) => p.toMap()).toList(), + }; + } - Map toMap() { - return { - "total": total, - "documents": documents.map((p) => p.toMap()).toList(), - }; - } - - List convertTo(T Function(Map) fromJson) => - documents.map((d) => d.convertTo(fromJson)).toList(); + List convertTo(T Function(Map) fromJson) => + documents.map((d) => d.convertTo(fromJson)).toList(); } diff --git a/lib/src/models/execution.dart b/lib/src/models/execution.dart index ad277e42..b873ed91 100644 --- a/lib/src/models/execution.dart +++ b/lib/src/models/execution.dart @@ -2,122 +2,103 @@ part of '../../models.dart'; /// Execution class Execution implements Model { - /// Execution ID. - final String $id; - - /// Execution creation date in ISO 8601 format. - final String $createdAt; - - /// Execution upate date in ISO 8601 format. - final String $updatedAt; - - /// Execution roles. - final List $permissions; - - /// Function ID. - final String functionId; - - /// The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`. - final String trigger; - - /// The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`. - final String status; - - /// HTTP request method type. - final String requestMethod; - - /// HTTP request path and query. - final String requestPath; - - /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. - final List requestHeaders; - - /// HTTP response status code. - final int responseStatusCode; - - /// HTTP response body. This will return empty unless execution is created as synchronous. - final String responseBody; - - /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. - final List responseHeaders; - - /// Function logs. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. - final String logs; - - /// Function errors. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. - final String errors; - - /// Function execution duration in seconds. - final double duration; - - /// The scheduled time for execution. If left empty, execution will be queued immediately. - final String? scheduledAt; - - Execution({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.functionId, - required this.trigger, - required this.status, - required this.requestMethod, - required this.requestPath, - required this.requestHeaders, - required this.responseStatusCode, - required this.responseBody, - required this.responseHeaders, - required this.logs, - required this.errors, - required this.duration, - this.scheduledAt, - }); - - factory Execution.fromMap(Map map) { - return Execution( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - functionId: map['functionId'].toString(), - trigger: map['trigger'].toString(), - status: map['status'].toString(), - requestMethod: map['requestMethod'].toString(), - requestPath: map['requestPath'].toString(), - requestHeaders: List.from( - map['requestHeaders'].map((p) => Headers.fromMap(p))), - responseStatusCode: (map['responseStatusCode'] is String) - ? int.tryParse(map['responseStatusCode']) ?? 0 - : map['responseStatusCode'] ?? 0, - responseBody: map['responseBody'].toString(), - responseHeaders: List.from( - map['responseHeaders'].map((p) => Headers.fromMap(p))), - logs: map['logs'].toString(), - errors: map['errors'].toString(), - duration: map['duration'].toDouble(), - scheduledAt: map['scheduledAt']?.toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "functionId": functionId, - "trigger": trigger, - "status": status, - "requestMethod": requestMethod, - "requestPath": requestPath, - "requestHeaders": requestHeaders.map((p) => p.toMap()).toList(), - "responseStatusCode": responseStatusCode, - "responseBody": responseBody, - "responseHeaders": responseHeaders.map((p) => p.toMap()).toList(), - "logs": logs, - "errors": errors, - "duration": duration, - "scheduledAt": scheduledAt, - }; - } + /// Execution ID. + final String $id; + /// Execution creation date in ISO 8601 format. + final String $createdAt; + /// Execution upate date in ISO 8601 format. + final String $updatedAt; + /// Execution roles. + final List $permissions; + /// Function ID. + final String functionId; + /// The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`. + final String trigger; + /// The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`. + final String status; + /// HTTP request method type. + final String requestMethod; + /// HTTP request path and query. + final String requestPath; + /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. + final List requestHeaders; + /// HTTP response status code. + final int responseStatusCode; + /// HTTP response body. This will return empty unless execution is created as synchronous. + final Payload responseBody; + /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. + final List responseHeaders; + /// Function logs. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. + final String logs; + /// Function errors. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. + final String errors; + /// Function execution duration in seconds. + final double duration; + /// The scheduled time for execution. If left empty, execution will be queued immediately. + final String? scheduledAt; + + Execution({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.functionId, + required this.trigger, + required this.status, + required this.requestMethod, + required this.requestPath, + required this.requestHeaders, + required this.responseStatusCode, + required this.responseBody, + required this.responseHeaders, + required this.logs, + required this.errors, + required this.duration, + this.scheduledAt, + }); + + factory Execution.fromMap(Map map) { + return Execution( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + functionId: map['functionId'].toString(), + trigger: map['trigger'].toString(), + status: map['status'].toString(), + requestMethod: map['requestMethod'].toString(), + requestPath: map['requestPath'].toString(), + requestHeaders: List.from(map['requestHeaders'].map((p) => Headers.fromMap(p))), + responseStatusCode: (map['responseStatusCode'] is String) ? + int.tryParse(map['responseStatusCode']) ?? 0:map['responseStatusCode'] ?? 0, + responseBody: map['responseBody'], + responseHeaders: List.from(map['responseHeaders'].map((p) => Headers.fromMap(p))), + logs: map['logs'].toString(), + errors: map['errors'].toString(), + duration: map['duration'].toDouble(), + scheduledAt: map['scheduledAt']?.toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "functionId": functionId, + "trigger": trigger, + "status": status, + "requestMethod": requestMethod, + "requestPath": requestPath, + "requestHeaders": requestHeaders.map((p) => p.toMap()).toList(), + "responseStatusCode": responseStatusCode, + "responseBody": responseBody, + "responseHeaders": responseHeaders.map((p) => p.toMap()).toList(), + "logs": logs, + "errors": errors, + "duration": duration, + "scheduledAt": scheduledAt, + }; + } } diff --git a/lib/src/models/execution_list.dart b/lib/src/models/execution_list.dart index 0a54b2a8..ba66f150 100644 --- a/lib/src/models/execution_list.dart +++ b/lib/src/models/execution_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Executions List class ExecutionList implements Model { - /// Total number of executions documents that matched your query. - final int total; + /// Total number of executions documents that matched your query. + final int total; + /// List of executions. + final List executions; - /// List of executions. - final List executions; + ExecutionList({ + required this.total, + required this.executions, + }); - ExecutionList({ - required this.total, - required this.executions, - }); + factory ExecutionList.fromMap(Map map) { + return ExecutionList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + executions: List.from(map['executions'].map((p) => Execution.fromMap(p))), + ); + } - factory ExecutionList.fromMap(Map map) { - return ExecutionList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - executions: List.from( - map['executions'].map((p) => Execution.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "executions": executions.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "executions": executions.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/file.dart b/lib/src/models/file.dart index db31bf49..34b9e6cf 100644 --- a/lib/src/models/file.dart +++ b/lib/src/models/file.dart @@ -2,88 +2,75 @@ part of '../../models.dart'; /// File class File implements Model { - /// File ID. - final String $id; + /// File ID. + final String $id; + /// Bucket ID. + final String bucketId; + /// File creation date in ISO 8601 format. + final String $createdAt; + /// File update date in ISO 8601 format. + final String $updatedAt; + /// File permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List $permissions; + /// File name. + final String name; + /// File MD5 signature. + final String signature; + /// File mime type. + final String mimeType; + /// File original size in bytes. + final int sizeOriginal; + /// Total number of chunks available + final int chunksTotal; + /// Total number of chunks uploaded + final int chunksUploaded; - /// Bucket ID. - final String bucketId; + File({ + required this.$id, + required this.bucketId, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.name, + required this.signature, + required this.mimeType, + required this.sizeOriginal, + required this.chunksTotal, + required this.chunksUploaded, + }); - /// File creation date in ISO 8601 format. - final String $createdAt; + factory File.fromMap(Map map) { + return File( + $id: map['\$id'].toString(), + bucketId: map['bucketId'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + name: map['name'].toString(), + signature: map['signature'].toString(), + mimeType: map['mimeType'].toString(), + sizeOriginal: (map['sizeOriginal'] is String) ? + int.tryParse(map['sizeOriginal']) ?? 0:map['sizeOriginal'] ?? 0, + chunksTotal: (map['chunksTotal'] is String) ? + int.tryParse(map['chunksTotal']) ?? 0:map['chunksTotal'] ?? 0, + chunksUploaded: (map['chunksUploaded'] is String) ? + int.tryParse(map['chunksUploaded']) ?? 0:map['chunksUploaded'] ?? 0, + ); + } - /// File update date in ISO 8601 format. - final String $updatedAt; - - /// File permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List $permissions; - - /// File name. - final String name; - - /// File MD5 signature. - final String signature; - - /// File mime type. - final String mimeType; - - /// File original size in bytes. - final int sizeOriginal; - - /// Total number of chunks available - final int chunksTotal; - - /// Total number of chunks uploaded - final int chunksUploaded; - - File({ - required this.$id, - required this.bucketId, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.name, - required this.signature, - required this.mimeType, - required this.sizeOriginal, - required this.chunksTotal, - required this.chunksUploaded, - }); - - factory File.fromMap(Map map) { - return File( - $id: map['\$id'].toString(), - bucketId: map['bucketId'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - name: map['name'].toString(), - signature: map['signature'].toString(), - mimeType: map['mimeType'].toString(), - sizeOriginal: (map['sizeOriginal'] is String) - ? int.tryParse(map['sizeOriginal']) ?? 0 - : map['sizeOriginal'] ?? 0, - chunksTotal: (map['chunksTotal'] is String) - ? int.tryParse(map['chunksTotal']) ?? 0 - : map['chunksTotal'] ?? 0, - chunksUploaded: (map['chunksUploaded'] is String) - ? int.tryParse(map['chunksUploaded']) ?? 0 - : map['chunksUploaded'] ?? 0, - ); - } - - Map toMap() { - return { - "\$id": $id, - "bucketId": bucketId, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "name": name, - "signature": signature, - "mimeType": mimeType, - "sizeOriginal": sizeOriginal, - "chunksTotal": chunksTotal, - "chunksUploaded": chunksUploaded, - }; - } + Map toMap() { + return { + "\$id": $id, + "bucketId": bucketId, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "name": name, + "signature": signature, + "mimeType": mimeType, + "sizeOriginal": sizeOriginal, + "chunksTotal": chunksTotal, + "chunksUploaded": chunksUploaded, + }; + } } diff --git a/lib/src/models/file_list.dart b/lib/src/models/file_list.dart index 3d4451f6..cf7a0ced 100644 --- a/lib/src/models/file_list.dart +++ b/lib/src/models/file_list.dart @@ -2,30 +2,28 @@ part of '../../models.dart'; /// Files List class FileList implements Model { - /// Total number of files documents that matched your query. - final int total; + /// Total number of files documents that matched your query. + final int total; + /// List of files. + final List files; - /// List of files. - final List files; + FileList({ + required this.total, + required this.files, + }); - FileList({ - required this.total, - required this.files, - }); + factory FileList.fromMap(Map map) { + return FileList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + files: List.from(map['files'].map((p) => File.fromMap(p))), + ); + } - factory FileList.fromMap(Map map) { - return FileList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - files: List.from(map['files'].map((p) => File.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "files": files.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "files": files.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/function.dart b/lib/src/models/function.dart index f509b009..870bd5df 100644 --- a/lib/src/models/function.dart +++ b/lib/src/models/function.dart @@ -2,162 +2,138 @@ part of '../../models.dart'; /// Function class Func implements Model { - /// Function ID. - final String $id; - - /// Function creation date in ISO 8601 format. - final String $createdAt; - - /// Function update date in ISO 8601 format. - final String $updatedAt; - - /// Execution permissions. - final List execute; - - /// Function name. - final String name; - - /// Function enabled. - final bool enabled; - - /// Is the function deployed with the latest configuration? This is set to false if you've changed an environment variables, entrypoint, commands, or other settings that needs redeploy to be applied. When the value is false, redeploy the function to update it with the latest configuration. - final bool live; - - /// Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project. - final bool logging; - - /// Function execution runtime. - final String runtime; - - /// Function's active deployment ID. - final String deployment; - - /// Allowed permission scopes. - final List scopes; - - /// Function variables. - final List vars; - - /// Function trigger events. - final List events; - - /// Function execution schedult in CRON format. - final String schedule; - - /// Function execution timeout in seconds. - final int timeout; - - /// The entrypoint file used to execute the deployment. - final String entrypoint; - - /// The build command used to build the deployment. - final String commands; - - /// Version of Open Runtimes used for the function. - final String version; - - /// Function VCS (Version Control System) installation id. - final String installationId; - - /// VCS (Version Control System) Repository ID - final String providerRepositoryId; - - /// VCS (Version Control System) branch name - final String providerBranch; - - /// Path to function in VCS (Version Control System) repository - final String providerRootDirectory; - - /// Is VCS (Version Control System) connection is in silent mode? When in silence mode, no comments will be posted on the repository pull or merge requests - final bool providerSilentMode; - - /// Machine specification for builds and executions. - final String specification; - - Func({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.execute, - required this.name, - required this.enabled, - required this.live, - required this.logging, - required this.runtime, - required this.deployment, - required this.scopes, - required this.vars, - required this.events, - required this.schedule, - required this.timeout, - required this.entrypoint, - required this.commands, - required this.version, - required this.installationId, - required this.providerRepositoryId, - required this.providerBranch, - required this.providerRootDirectory, - required this.providerSilentMode, - required this.specification, - }); - - factory Func.fromMap(Map map) { - return Func( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - execute: map['execute'] ?? [], - name: map['name'].toString(), - enabled: map['enabled'], - live: map['live'], - logging: map['logging'], - runtime: map['runtime'].toString(), - deployment: map['deployment'].toString(), - scopes: map['scopes'] ?? [], - vars: List.from(map['vars'].map((p) => Variable.fromMap(p))), - events: map['events'] ?? [], - schedule: map['schedule'].toString(), - timeout: (map['timeout'] is String) - ? int.tryParse(map['timeout']) ?? 0 - : map['timeout'] ?? 0, - entrypoint: map['entrypoint'].toString(), - commands: map['commands'].toString(), - version: map['version'].toString(), - installationId: map['installationId'].toString(), - providerRepositoryId: map['providerRepositoryId'].toString(), - providerBranch: map['providerBranch'].toString(), - providerRootDirectory: map['providerRootDirectory'].toString(), - providerSilentMode: map['providerSilentMode'], - specification: map['specification'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "execute": execute, - "name": name, - "enabled": enabled, - "live": live, - "logging": logging, - "runtime": runtime, - "deployment": deployment, - "scopes": scopes, - "vars": vars.map((p) => p.toMap()).toList(), - "events": events, - "schedule": schedule, - "timeout": timeout, - "entrypoint": entrypoint, - "commands": commands, - "version": version, - "installationId": installationId, - "providerRepositoryId": providerRepositoryId, - "providerBranch": providerBranch, - "providerRootDirectory": providerRootDirectory, - "providerSilentMode": providerSilentMode, - "specification": specification, - }; - } + /// Function ID. + final String $id; + /// Function creation date in ISO 8601 format. + final String $createdAt; + /// Function update date in ISO 8601 format. + final String $updatedAt; + /// Execution permissions. + final List execute; + /// Function name. + final String name; + /// Function enabled. + final bool enabled; + /// Is the function deployed with the latest configuration? This is set to false if you've changed an environment variables, entrypoint, commands, or other settings that needs redeploy to be applied. When the value is false, redeploy the function to update it with the latest configuration. + final bool live; + /// Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project. + final bool logging; + /// Function execution runtime. + final String runtime; + /// Function's active deployment ID. + final String deployment; + /// Allowed permission scopes. + final List scopes; + /// Function variables. + final List vars; + /// Function trigger events. + final List events; + /// Function execution schedult in CRON format. + final String schedule; + /// Function execution timeout in seconds. + final int timeout; + /// The entrypoint file used to execute the deployment. + final String entrypoint; + /// The build command used to build the deployment. + final String commands; + /// Version of Open Runtimes used for the function. + final String version; + /// Function VCS (Version Control System) installation id. + final String installationId; + /// VCS (Version Control System) Repository ID + final String providerRepositoryId; + /// VCS (Version Control System) branch name + final String providerBranch; + /// Path to function in VCS (Version Control System) repository + final String providerRootDirectory; + /// Is VCS (Version Control System) connection is in silent mode? When in silence mode, no comments will be posted on the repository pull or merge requests + final bool providerSilentMode; + /// Machine specification for builds and executions. + final String specification; + + Func({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.execute, + required this.name, + required this.enabled, + required this.live, + required this.logging, + required this.runtime, + required this.deployment, + required this.scopes, + required this.vars, + required this.events, + required this.schedule, + required this.timeout, + required this.entrypoint, + required this.commands, + required this.version, + required this.installationId, + required this.providerRepositoryId, + required this.providerBranch, + required this.providerRootDirectory, + required this.providerSilentMode, + required this.specification, + }); + + factory Func.fromMap(Map map) { + return Func( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + execute: map['execute'] ?? [], + name: map['name'].toString(), + enabled: map['enabled'], + live: map['live'], + logging: map['logging'], + runtime: map['runtime'].toString(), + deployment: map['deployment'].toString(), + scopes: map['scopes'] ?? [], + vars: List.from(map['vars'].map((p) => Variable.fromMap(p))), + events: map['events'] ?? [], + schedule: map['schedule'].toString(), + timeout: (map['timeout'] is String) ? + int.tryParse(map['timeout']) ?? 0:map['timeout'] ?? 0, + entrypoint: map['entrypoint'].toString(), + commands: map['commands'].toString(), + version: map['version'].toString(), + installationId: map['installationId'].toString(), + providerRepositoryId: map['providerRepositoryId'].toString(), + providerBranch: map['providerBranch'].toString(), + providerRootDirectory: map['providerRootDirectory'].toString(), + providerSilentMode: map['providerSilentMode'], + specification: map['specification'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "execute": execute, + "name": name, + "enabled": enabled, + "live": live, + "logging": logging, + "runtime": runtime, + "deployment": deployment, + "scopes": scopes, + "vars": vars.map((p) => p.toMap()).toList(), + "events": events, + "schedule": schedule, + "timeout": timeout, + "entrypoint": entrypoint, + "commands": commands, + "version": version, + "installationId": installationId, + "providerRepositoryId": providerRepositoryId, + "providerBranch": providerBranch, + "providerRootDirectory": providerRootDirectory, + "providerSilentMode": providerSilentMode, + "specification": specification, + }; + } } diff --git a/lib/src/models/function_list.dart b/lib/src/models/function_list.dart index 989e4264..712e459e 100644 --- a/lib/src/models/function_list.dart +++ b/lib/src/models/function_list.dart @@ -2,30 +2,28 @@ part of '../../models.dart'; /// Functions List class FunctionList implements Model { - /// Total number of functions documents that matched your query. - final int total; + /// Total number of functions documents that matched your query. + final int total; + /// List of functions. + final List functions; - /// List of functions. - final List functions; + FunctionList({ + required this.total, + required this.functions, + }); - FunctionList({ - required this.total, - required this.functions, - }); + factory FunctionList.fromMap(Map map) { + return FunctionList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + functions: List.from(map['functions'].map((p) => Func.fromMap(p))), + ); + } - factory FunctionList.fromMap(Map map) { - return FunctionList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - functions: List.from(map['functions'].map((p) => Func.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "functions": functions.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "functions": functions.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/headers.dart b/lib/src/models/headers.dart index 22494998..f03c5ce4 100644 --- a/lib/src/models/headers.dart +++ b/lib/src/models/headers.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Headers class Headers implements Model { - /// Header name. - final String name; + /// Header name. + final String name; + /// Header value. + final String value; - /// Header value. - final String value; + Headers({ + required this.name, + required this.value, + }); - Headers({ - required this.name, - required this.value, - }); + factory Headers.fromMap(Map map) { + return Headers( + name: map['name'].toString(), + value: map['value'].toString(), + ); + } - factory Headers.fromMap(Map map) { - return Headers( - name: map['name'].toString(), - value: map['value'].toString(), - ); - } - - Map toMap() { - return { - "name": name, - "value": value, - }; - } + Map toMap() { + return { + "name": name, + "value": value, + }; + } } diff --git a/lib/src/models/health_antivirus.dart b/lib/src/models/health_antivirus.dart index aabc7d85..48b8ad32 100644 --- a/lib/src/models/health_antivirus.dart +++ b/lib/src/models/health_antivirus.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Health Antivirus class HealthAntivirus implements Model { - /// Antivirus version. - final String version; + /// Antivirus version. + final String version; + /// Antivirus status. Possible values can are: `disabled`, `offline`, `online` + final String status; - /// Antivirus status. Possible values can are: `disabled`, `offline`, `online` - final String status; + HealthAntivirus({ + required this.version, + required this.status, + }); - HealthAntivirus({ - required this.version, - required this.status, - }); + factory HealthAntivirus.fromMap(Map map) { + return HealthAntivirus( + version: map['version'].toString(), + status: map['status'].toString(), + ); + } - factory HealthAntivirus.fromMap(Map map) { - return HealthAntivirus( - version: map['version'].toString(), - status: map['status'].toString(), - ); - } - - Map toMap() { - return { - "version": version, - "status": status, - }; - } + Map toMap() { + return { + "version": version, + "status": status, + }; + } } diff --git a/lib/src/models/health_certificate.dart b/lib/src/models/health_certificate.dart index d412eba9..3409d8e7 100644 --- a/lib/src/models/health_certificate.dart +++ b/lib/src/models/health_certificate.dart @@ -2,52 +2,47 @@ part of '../../models.dart'; /// Health Certificate class HealthCertificate implements Model { - /// Certificate name - final String name; - - /// Subject SN - final String subjectSN; - - /// Issuer organisation - final String issuerOrganisation; - - /// Valid from - final String validFrom; - - /// Valid to - final String validTo; - - /// Signature type SN - final String signatureTypeSN; - - HealthCertificate({ - required this.name, - required this.subjectSN, - required this.issuerOrganisation, - required this.validFrom, - required this.validTo, - required this.signatureTypeSN, - }); - - factory HealthCertificate.fromMap(Map map) { - return HealthCertificate( - name: map['name'].toString(), - subjectSN: map['subjectSN'].toString(), - issuerOrganisation: map['issuerOrganisation'].toString(), - validFrom: map['validFrom'].toString(), - validTo: map['validTo'].toString(), - signatureTypeSN: map['signatureTypeSN'].toString(), - ); - } - - Map toMap() { - return { - "name": name, - "subjectSN": subjectSN, - "issuerOrganisation": issuerOrganisation, - "validFrom": validFrom, - "validTo": validTo, - "signatureTypeSN": signatureTypeSN, - }; - } + /// Certificate name + final String name; + /// Subject SN + final String subjectSN; + /// Issuer organisation + final String issuerOrganisation; + /// Valid from + final String validFrom; + /// Valid to + final String validTo; + /// Signature type SN + final String signatureTypeSN; + + HealthCertificate({ + required this.name, + required this.subjectSN, + required this.issuerOrganisation, + required this.validFrom, + required this.validTo, + required this.signatureTypeSN, + }); + + factory HealthCertificate.fromMap(Map map) { + return HealthCertificate( + name: map['name'].toString(), + subjectSN: map['subjectSN'].toString(), + issuerOrganisation: map['issuerOrganisation'].toString(), + validFrom: map['validFrom'].toString(), + validTo: map['validTo'].toString(), + signatureTypeSN: map['signatureTypeSN'].toString(), + ); + } + + Map toMap() { + return { + "name": name, + "subjectSN": subjectSN, + "issuerOrganisation": issuerOrganisation, + "validFrom": validFrom, + "validTo": validTo, + "signatureTypeSN": signatureTypeSN, + }; + } } diff --git a/lib/src/models/health_queue.dart b/lib/src/models/health_queue.dart index fdb1f433..8267e5bc 100644 --- a/lib/src/models/health_queue.dart +++ b/lib/src/models/health_queue.dart @@ -2,24 +2,23 @@ part of '../../models.dart'; /// Health Queue class HealthQueue implements Model { - /// Amount of actions in the queue. - final int size; + /// Amount of actions in the queue. + final int size; - HealthQueue({ - required this.size, - }); + HealthQueue({ + required this.size, + }); - factory HealthQueue.fromMap(Map map) { - return HealthQueue( - size: (map['size'] is String) - ? int.tryParse(map['size']) ?? 0 - : map['size'] ?? 0, - ); - } + factory HealthQueue.fromMap(Map map) { + return HealthQueue( + size: (map['size'] is String) ? + int.tryParse(map['size']) ?? 0:map['size'] ?? 0, + ); + } - Map toMap() { - return { - "size": size, - }; - } + Map toMap() { + return { + "size": size, + }; + } } diff --git a/lib/src/models/health_status.dart b/lib/src/models/health_status.dart index 9469eb40..dbbcfef8 100644 --- a/lib/src/models/health_status.dart +++ b/lib/src/models/health_status.dart @@ -2,36 +2,33 @@ part of '../../models.dart'; /// Health Status class HealthStatus implements Model { - /// Name of the service. - final String name; + /// Name of the service. + final String name; + /// Duration in milliseconds how long the health check took. + final int ping; + /// Service status. Possible values can are: `pass`, `fail` + final String status; - /// Duration in milliseconds how long the health check took. - final int ping; + HealthStatus({ + required this.name, + required this.ping, + required this.status, + }); - /// Service status. Possible values can are: `pass`, `fail` - final String status; + factory HealthStatus.fromMap(Map map) { + return HealthStatus( + name: map['name'].toString(), + ping: (map['ping'] is String) ? + int.tryParse(map['ping']) ?? 0:map['ping'] ?? 0, + status: map['status'].toString(), + ); + } - HealthStatus({ - required this.name, - required this.ping, - required this.status, - }); - - factory HealthStatus.fromMap(Map map) { - return HealthStatus( - name: map['name'].toString(), - ping: (map['ping'] is String) - ? int.tryParse(map['ping']) ?? 0 - : map['ping'] ?? 0, - status: map['status'].toString(), - ); - } - - Map toMap() { - return { - "name": name, - "ping": ping, - "status": status, - }; - } + Map toMap() { + return { + "name": name, + "ping": ping, + "status": status, + }; + } } diff --git a/lib/src/models/health_time.dart b/lib/src/models/health_time.dart index 284ab848..49b00a9d 100644 --- a/lib/src/models/health_time.dart +++ b/lib/src/models/health_time.dart @@ -2,40 +2,35 @@ part of '../../models.dart'; /// Health Time class HealthTime implements Model { - /// Current unix timestamp on trustful remote server. - final int remoteTime; + /// Current unix timestamp on trustful remote server. + final int remoteTime; + /// Current unix timestamp of local server where Appwrite runs. + final int localTime; + /// Difference of unix remote and local timestamps in milliseconds. + final int diff; - /// Current unix timestamp of local server where Appwrite runs. - final int localTime; + HealthTime({ + required this.remoteTime, + required this.localTime, + required this.diff, + }); - /// Difference of unix remote and local timestamps in milliseconds. - final int diff; + factory HealthTime.fromMap(Map map) { + return HealthTime( + remoteTime: (map['remoteTime'] is String) ? + int.tryParse(map['remoteTime']) ?? 0:map['remoteTime'] ?? 0, + localTime: (map['localTime'] is String) ? + int.tryParse(map['localTime']) ?? 0:map['localTime'] ?? 0, + diff: (map['diff'] is String) ? + int.tryParse(map['diff']) ?? 0:map['diff'] ?? 0, + ); + } - HealthTime({ - required this.remoteTime, - required this.localTime, - required this.diff, - }); - - factory HealthTime.fromMap(Map map) { - return HealthTime( - remoteTime: (map['remoteTime'] is String) - ? int.tryParse(map['remoteTime']) ?? 0 - : map['remoteTime'] ?? 0, - localTime: (map['localTime'] is String) - ? int.tryParse(map['localTime']) ?? 0 - : map['localTime'] ?? 0, - diff: (map['diff'] is String) - ? int.tryParse(map['diff']) ?? 0 - : map['diff'] ?? 0, - ); - } - - Map toMap() { - return { - "remoteTime": remoteTime, - "localTime": localTime, - "diff": diff, - }; - } + Map toMap() { + return { + "remoteTime": remoteTime, + "localTime": localTime, + "diff": diff, + }; + } } diff --git a/lib/src/models/identity.dart b/lib/src/models/identity.dart index 807bdfd0..632dc3db 100644 --- a/lib/src/models/identity.dart +++ b/lib/src/models/identity.dart @@ -2,76 +2,67 @@ part of '../../models.dart'; /// Identity class Identity implements Model { - /// Identity ID. - final String $id; + /// Identity ID. + final String $id; + /// Identity creation date in ISO 8601 format. + final String $createdAt; + /// Identity update date in ISO 8601 format. + final String $updatedAt; + /// User ID. + final String userId; + /// Identity Provider. + final String provider; + /// ID of the User in the Identity Provider. + final String providerUid; + /// Email of the User in the Identity Provider. + final String providerEmail; + /// Identity Provider Access Token. + final String providerAccessToken; + /// The date of when the access token expires in ISO 8601 format. + final String providerAccessTokenExpiry; + /// Identity Provider Refresh Token. + final String providerRefreshToken; - /// Identity creation date in ISO 8601 format. - final String $createdAt; + Identity({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.userId, + required this.provider, + required this.providerUid, + required this.providerEmail, + required this.providerAccessToken, + required this.providerAccessTokenExpiry, + required this.providerRefreshToken, + }); - /// Identity update date in ISO 8601 format. - final String $updatedAt; + factory Identity.fromMap(Map map) { + return Identity( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + userId: map['userId'].toString(), + provider: map['provider'].toString(), + providerUid: map['providerUid'].toString(), + providerEmail: map['providerEmail'].toString(), + providerAccessToken: map['providerAccessToken'].toString(), + providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), + providerRefreshToken: map['providerRefreshToken'].toString(), + ); + } - /// User ID. - final String userId; - - /// Identity Provider. - final String provider; - - /// ID of the User in the Identity Provider. - final String providerUid; - - /// Email of the User in the Identity Provider. - final String providerEmail; - - /// Identity Provider Access Token. - final String providerAccessToken; - - /// The date of when the access token expires in ISO 8601 format. - final String providerAccessTokenExpiry; - - /// Identity Provider Refresh Token. - final String providerRefreshToken; - - Identity({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.userId, - required this.provider, - required this.providerUid, - required this.providerEmail, - required this.providerAccessToken, - required this.providerAccessTokenExpiry, - required this.providerRefreshToken, - }); - - factory Identity.fromMap(Map map) { - return Identity( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - userId: map['userId'].toString(), - provider: map['provider'].toString(), - providerUid: map['providerUid'].toString(), - providerEmail: map['providerEmail'].toString(), - providerAccessToken: map['providerAccessToken'].toString(), - providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), - providerRefreshToken: map['providerRefreshToken'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "userId": userId, - "provider": provider, - "providerUid": providerUid, - "providerEmail": providerEmail, - "providerAccessToken": providerAccessToken, - "providerAccessTokenExpiry": providerAccessTokenExpiry, - "providerRefreshToken": providerRefreshToken, - }; - } + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "userId": userId, + "provider": provider, + "providerUid": providerUid, + "providerEmail": providerEmail, + "providerAccessToken": providerAccessToken, + "providerAccessTokenExpiry": providerAccessTokenExpiry, + "providerRefreshToken": providerRefreshToken, + }; + } } diff --git a/lib/src/models/identity_list.dart b/lib/src/models/identity_list.dart index 3d546f5e..77b9d8c7 100644 --- a/lib/src/models/identity_list.dart +++ b/lib/src/models/identity_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Identities List class IdentityList implements Model { - /// Total number of identities documents that matched your query. - final int total; + /// Total number of identities documents that matched your query. + final int total; + /// List of identities. + final List identities; - /// List of identities. - final List identities; + IdentityList({ + required this.total, + required this.identities, + }); - IdentityList({ - required this.total, - required this.identities, - }); + factory IdentityList.fromMap(Map map) { + return IdentityList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + identities: List.from(map['identities'].map((p) => Identity.fromMap(p))), + ); + } - factory IdentityList.fromMap(Map map) { - return IdentityList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - identities: List.from( - map['identities'].map((p) => Identity.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "identities": identities.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "identities": identities.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/index.dart b/lib/src/models/index.dart index deb2f92e..9a4a1f9f 100644 --- a/lib/src/models/index.dart +++ b/lib/src/models/index.dart @@ -2,52 +2,47 @@ part of '../../models.dart'; /// Index class Index implements Model { - /// Index Key. - final String key; - - /// Index type. - final String type; - - /// Index status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an index. - final String error; - - /// Index attributes. - final List attributes; - - /// Index orders. - final List? orders; - - Index({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.attributes, - this.orders, - }); - - factory Index.fromMap(Map map) { - return Index( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - attributes: map['attributes'] ?? [], - orders: map['orders'], - ); - } - - Map toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "attributes": attributes, - "orders": orders, - }; - } + /// Index Key. + final String key; + /// Index type. + final String type; + /// Index status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an index. + final String error; + /// Index attributes. + final List attributes; + /// Index orders. + final List? orders; + + Index({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.attributes, + this.orders, + }); + + factory Index.fromMap(Map map) { + return Index( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + attributes: map['attributes'] ?? [], + orders: map['orders'], + ); + } + + Map toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "attributes": attributes, + "orders": orders, + }; + } } diff --git a/lib/src/models/index_list.dart b/lib/src/models/index_list.dart index 9927e08d..dbf66137 100644 --- a/lib/src/models/index_list.dart +++ b/lib/src/models/index_list.dart @@ -2,30 +2,28 @@ part of '../../models.dart'; /// Indexes List class IndexList implements Model { - /// Total number of indexes documents that matched your query. - final int total; + /// Total number of indexes documents that matched your query. + final int total; + /// List of indexes. + final List indexes; - /// List of indexes. - final List indexes; + IndexList({ + required this.total, + required this.indexes, + }); - IndexList({ - required this.total, - required this.indexes, - }); + factory IndexList.fromMap(Map map) { + return IndexList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + indexes: List.from(map['indexes'].map((p) => Index.fromMap(p))), + ); + } - factory IndexList.fromMap(Map map) { - return IndexList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - indexes: List.from(map['indexes'].map((p) => Index.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "indexes": indexes.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "indexes": indexes.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/jwt.dart b/lib/src/models/jwt.dart index e2e31bd2..1b4ff7de 100644 --- a/lib/src/models/jwt.dart +++ b/lib/src/models/jwt.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// JWT class Jwt implements Model { - /// JWT encoded string. - final String jwt; + /// JWT encoded string. + final String jwt; - Jwt({ - required this.jwt, - }); + Jwt({ + required this.jwt, + }); - factory Jwt.fromMap(Map map) { - return Jwt( - jwt: map['jwt'].toString(), - ); - } + factory Jwt.fromMap(Map map) { + return Jwt( + jwt: map['jwt'].toString(), + ); + } - Map toMap() { - return { - "jwt": jwt, - }; - } + Map toMap() { + return { + "jwt": jwt, + }; + } } diff --git a/lib/src/models/language.dart b/lib/src/models/language.dart index b6ec6121..6d26c461 100644 --- a/lib/src/models/language.dart +++ b/lib/src/models/language.dart @@ -2,34 +2,32 @@ part of '../../models.dart'; /// Language class Language implements Model { - /// Language name. - final String name; + /// Language name. + final String name; + /// Language two-character ISO 639-1 codes. + final String code; + /// Language native name. + final String nativeName; - /// Language two-character ISO 639-1 codes. - final String code; + Language({ + required this.name, + required this.code, + required this.nativeName, + }); - /// Language native name. - final String nativeName; + factory Language.fromMap(Map map) { + return Language( + name: map['name'].toString(), + code: map['code'].toString(), + nativeName: map['nativeName'].toString(), + ); + } - Language({ - required this.name, - required this.code, - required this.nativeName, - }); - - factory Language.fromMap(Map map) { - return Language( - name: map['name'].toString(), - code: map['code'].toString(), - nativeName: map['nativeName'].toString(), - ); - } - - Map toMap() { - return { - "name": name, - "code": code, - "nativeName": nativeName, - }; - } + Map toMap() { + return { + "name": name, + "code": code, + "nativeName": nativeName, + }; + } } diff --git a/lib/src/models/language_list.dart b/lib/src/models/language_list.dart index b0cfcc49..fd4824fb 100644 --- a/lib/src/models/language_list.dart +++ b/lib/src/models/language_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Languages List class LanguageList implements Model { - /// Total number of languages documents that matched your query. - final int total; + /// Total number of languages documents that matched your query. + final int total; + /// List of languages. + final List languages; - /// List of languages. - final List languages; + LanguageList({ + required this.total, + required this.languages, + }); - LanguageList({ - required this.total, - required this.languages, - }); + factory LanguageList.fromMap(Map map) { + return LanguageList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + languages: List.from(map['languages'].map((p) => Language.fromMap(p))), + ); + } - factory LanguageList.fromMap(Map map) { - return LanguageList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - languages: - List.from(map['languages'].map((p) => Language.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "languages": languages.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "languages": languages.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/locale.dart b/lib/src/models/locale.dart index 084475bf..0f0fd7f2 100644 --- a/lib/src/models/locale.dart +++ b/lib/src/models/locale.dart @@ -2,58 +2,52 @@ part of '../../models.dart'; /// Locale class Locale implements Model { - /// User IP address. - final String ip; - - /// Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format - final String countryCode; - - /// Country name. This field support localization. - final String country; - - /// Continent code. A two character continent code "AF" for Africa, "AN" for Antarctica, "AS" for Asia, "EU" for Europe, "NA" for North America, "OC" for Oceania, and "SA" for South America. - final String continentCode; - - /// Continent name. This field support localization. - final String continent; - - /// True if country is part of the European Union. - final bool eu; - - /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format - final String currency; - - Locale({ - required this.ip, - required this.countryCode, - required this.country, - required this.continentCode, - required this.continent, - required this.eu, - required this.currency, - }); - - factory Locale.fromMap(Map map) { - return Locale( - ip: map['ip'].toString(), - countryCode: map['countryCode'].toString(), - country: map['country'].toString(), - continentCode: map['continentCode'].toString(), - continent: map['continent'].toString(), - eu: map['eu'], - currency: map['currency'].toString(), - ); - } - - Map toMap() { - return { - "ip": ip, - "countryCode": countryCode, - "country": country, - "continentCode": continentCode, - "continent": continent, - "eu": eu, - "currency": currency, - }; - } + /// User IP address. + final String ip; + /// Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format + final String countryCode; + /// Country name. This field support localization. + final String country; + /// Continent code. A two character continent code "AF" for Africa, "AN" for Antarctica, "AS" for Asia, "EU" for Europe, "NA" for North America, "OC" for Oceania, and "SA" for South America. + final String continentCode; + /// Continent name. This field support localization. + final String continent; + /// True if country is part of the European Union. + final bool eu; + /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format + final String currency; + + Locale({ + required this.ip, + required this.countryCode, + required this.country, + required this.continentCode, + required this.continent, + required this.eu, + required this.currency, + }); + + factory Locale.fromMap(Map map) { + return Locale( + ip: map['ip'].toString(), + countryCode: map['countryCode'].toString(), + country: map['country'].toString(), + continentCode: map['continentCode'].toString(), + continent: map['continent'].toString(), + eu: map['eu'], + currency: map['currency'].toString(), + ); + } + + Map toMap() { + return { + "ip": ip, + "countryCode": countryCode, + "country": country, + "continentCode": continentCode, + "continent": continent, + "eu": eu, + "currency": currency, + }; + } } diff --git a/lib/src/models/locale_code.dart b/lib/src/models/locale_code.dart index 678e40c4..eebce199 100644 --- a/lib/src/models/locale_code.dart +++ b/lib/src/models/locale_code.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// LocaleCode class LocaleCode implements Model { - /// Locale codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) - final String code; + /// Locale codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) + final String code; + /// Locale name + final String name; - /// Locale name - final String name; + LocaleCode({ + required this.code, + required this.name, + }); - LocaleCode({ - required this.code, - required this.name, - }); + factory LocaleCode.fromMap(Map map) { + return LocaleCode( + code: map['code'].toString(), + name: map['name'].toString(), + ); + } - factory LocaleCode.fromMap(Map map) { - return LocaleCode( - code: map['code'].toString(), - name: map['name'].toString(), - ); - } - - Map toMap() { - return { - "code": code, - "name": name, - }; - } + Map toMap() { + return { + "code": code, + "name": name, + }; + } } diff --git a/lib/src/models/locale_code_list.dart b/lib/src/models/locale_code_list.dart index 9bd97f78..9ed7f657 100644 --- a/lib/src/models/locale_code_list.dart +++ b/lib/src/models/locale_code_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Locale codes list class LocaleCodeList implements Model { - /// Total number of localeCodes documents that matched your query. - final int total; + /// Total number of localeCodes documents that matched your query. + final int total; + /// List of localeCodes. + final List localeCodes; - /// List of localeCodes. - final List localeCodes; + LocaleCodeList({ + required this.total, + required this.localeCodes, + }); - LocaleCodeList({ - required this.total, - required this.localeCodes, - }); + factory LocaleCodeList.fromMap(Map map) { + return LocaleCodeList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + localeCodes: List.from(map['localeCodes'].map((p) => LocaleCode.fromMap(p))), + ); + } - factory LocaleCodeList.fromMap(Map map) { - return LocaleCodeList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - localeCodes: List.from( - map['localeCodes'].map((p) => LocaleCode.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "localeCodes": localeCodes.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "localeCodes": localeCodes.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/log.dart b/lib/src/models/log.dart index 7fb3f364..41cda2ca 100644 --- a/lib/src/models/log.dart +++ b/lib/src/models/log.dart @@ -2,142 +2,122 @@ part of '../../models.dart'; /// Log class Log implements Model { - /// Event name. - final String event; - - /// User ID. - final String userId; - - /// User Email. - final String userEmail; - - /// User Name. - final String userName; - - /// API mode when event triggered. - final String mode; - - /// IP session in use when the session was created. - final String ip; - - /// Log creation date in ISO 8601 format. - final String time; - - /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). - final String osCode; - - /// Operating system name. - final String osName; - - /// Operating system version. - final String osVersion; - - /// Client type. - final String clientType; - - /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). - final String clientCode; - - /// Client name. - final String clientName; - - /// Client version. - final String clientVersion; - - /// Client engine name. - final String clientEngine; - - /// Client engine name. - final String clientEngineVersion; - - /// Device name. - final String deviceName; - - /// Device brand name. - final String deviceBrand; - - /// Device model name. - final String deviceModel; - - /// Country two-character ISO 3166-1 alpha code. - final String countryCode; - - /// Country name. - final String countryName; - - Log({ - required this.event, - required this.userId, - required this.userEmail, - required this.userName, - required this.mode, - required this.ip, - required this.time, - required this.osCode, - required this.osName, - required this.osVersion, - required this.clientType, - required this.clientCode, - required this.clientName, - required this.clientVersion, - required this.clientEngine, - required this.clientEngineVersion, - required this.deviceName, - required this.deviceBrand, - required this.deviceModel, - required this.countryCode, - required this.countryName, - }); - - factory Log.fromMap(Map map) { - return Log( - event: map['event'].toString(), - userId: map['userId'].toString(), - userEmail: map['userEmail'].toString(), - userName: map['userName'].toString(), - mode: map['mode'].toString(), - ip: map['ip'].toString(), - time: map['time'].toString(), - osCode: map['osCode'].toString(), - osName: map['osName'].toString(), - osVersion: map['osVersion'].toString(), - clientType: map['clientType'].toString(), - clientCode: map['clientCode'].toString(), - clientName: map['clientName'].toString(), - clientVersion: map['clientVersion'].toString(), - clientEngine: map['clientEngine'].toString(), - clientEngineVersion: map['clientEngineVersion'].toString(), - deviceName: map['deviceName'].toString(), - deviceBrand: map['deviceBrand'].toString(), - deviceModel: map['deviceModel'].toString(), - countryCode: map['countryCode'].toString(), - countryName: map['countryName'].toString(), - ); - } - - Map toMap() { - return { - "event": event, - "userId": userId, - "userEmail": userEmail, - "userName": userName, - "mode": mode, - "ip": ip, - "time": time, - "osCode": osCode, - "osName": osName, - "osVersion": osVersion, - "clientType": clientType, - "clientCode": clientCode, - "clientName": clientName, - "clientVersion": clientVersion, - "clientEngine": clientEngine, - "clientEngineVersion": clientEngineVersion, - "deviceName": deviceName, - "deviceBrand": deviceBrand, - "deviceModel": deviceModel, - "countryCode": countryCode, - "countryName": countryName, - }; - } + /// Event name. + final String event; + /// User ID. + final String userId; + /// User Email. + final String userEmail; + /// User Name. + final String userName; + /// API mode when event triggered. + final String mode; + /// IP session in use when the session was created. + final String ip; + /// Log creation date in ISO 8601 format. + final String time; + /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). + final String osCode; + /// Operating system name. + final String osName; + /// Operating system version. + final String osVersion; + /// Client type. + final String clientType; + /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). + final String clientCode; + /// Client name. + final String clientName; + /// Client version. + final String clientVersion; + /// Client engine name. + final String clientEngine; + /// Client engine name. + final String clientEngineVersion; + /// Device name. + final String deviceName; + /// Device brand name. + final String deviceBrand; + /// Device model name. + final String deviceModel; + /// Country two-character ISO 3166-1 alpha code. + final String countryCode; + /// Country name. + final String countryName; + + Log({ + required this.event, + required this.userId, + required this.userEmail, + required this.userName, + required this.mode, + required this.ip, + required this.time, + required this.osCode, + required this.osName, + required this.osVersion, + required this.clientType, + required this.clientCode, + required this.clientName, + required this.clientVersion, + required this.clientEngine, + required this.clientEngineVersion, + required this.deviceName, + required this.deviceBrand, + required this.deviceModel, + required this.countryCode, + required this.countryName, + }); + + factory Log.fromMap(Map map) { + return Log( + event: map['event'].toString(), + userId: map['userId'].toString(), + userEmail: map['userEmail'].toString(), + userName: map['userName'].toString(), + mode: map['mode'].toString(), + ip: map['ip'].toString(), + time: map['time'].toString(), + osCode: map['osCode'].toString(), + osName: map['osName'].toString(), + osVersion: map['osVersion'].toString(), + clientType: map['clientType'].toString(), + clientCode: map['clientCode'].toString(), + clientName: map['clientName'].toString(), + clientVersion: map['clientVersion'].toString(), + clientEngine: map['clientEngine'].toString(), + clientEngineVersion: map['clientEngineVersion'].toString(), + deviceName: map['deviceName'].toString(), + deviceBrand: map['deviceBrand'].toString(), + deviceModel: map['deviceModel'].toString(), + countryCode: map['countryCode'].toString(), + countryName: map['countryName'].toString(), + ); + } + + Map toMap() { + return { + "event": event, + "userId": userId, + "userEmail": userEmail, + "userName": userName, + "mode": mode, + "ip": ip, + "time": time, + "osCode": osCode, + "osName": osName, + "osVersion": osVersion, + "clientType": clientType, + "clientCode": clientCode, + "clientName": clientName, + "clientVersion": clientVersion, + "clientEngine": clientEngine, + "clientEngineVersion": clientEngineVersion, + "deviceName": deviceName, + "deviceBrand": deviceBrand, + "deviceModel": deviceModel, + "countryCode": countryCode, + "countryName": countryName, + }; + } } diff --git a/lib/src/models/log_list.dart b/lib/src/models/log_list.dart index 2c06cc50..c7d6000c 100644 --- a/lib/src/models/log_list.dart +++ b/lib/src/models/log_list.dart @@ -2,30 +2,28 @@ part of '../../models.dart'; /// Logs List class LogList implements Model { - /// Total number of logs documents that matched your query. - final int total; + /// Total number of logs documents that matched your query. + final int total; + /// List of logs. + final List logs; - /// List of logs. - final List logs; + LogList({ + required this.total, + required this.logs, + }); - LogList({ - required this.total, - required this.logs, - }); + factory LogList.fromMap(Map map) { + return LogList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + logs: List.from(map['logs'].map((p) => Log.fromMap(p))), + ); + } - factory LogList.fromMap(Map map) { - return LogList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - logs: List.from(map['logs'].map((p) => Log.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "logs": logs.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "logs": logs.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/membership.dart b/lib/src/models/membership.dart index fb3fb523..283f4ee5 100644 --- a/lib/src/models/membership.dart +++ b/lib/src/models/membership.dart @@ -2,94 +2,82 @@ part of '../../models.dart'; /// Membership class Membership implements Model { - /// Membership ID. - final String $id; - - /// Membership creation date in ISO 8601 format. - final String $createdAt; - - /// Membership update date in ISO 8601 format. - final String $updatedAt; - - /// User ID. - final String userId; - - /// User name. - final String userName; - - /// User email address. - final String userEmail; - - /// Team ID. - final String teamId; - - /// Team name. - final String teamName; - - /// Date, the user has been invited to join the team in ISO 8601 format. - final String invited; - - /// Date, the user has accepted the invitation to join the team in ISO 8601 format. - final String joined; - - /// User confirmation status, true if the user has joined the team or false otherwise. - final bool confirm; - - /// Multi factor authentication status, true if the user has MFA enabled or false otherwise. - final bool mfa; - - /// User list of roles - final List roles; - - Membership({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.userId, - required this.userName, - required this.userEmail, - required this.teamId, - required this.teamName, - required this.invited, - required this.joined, - required this.confirm, - required this.mfa, - required this.roles, - }); - - factory Membership.fromMap(Map map) { - return Membership( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - userId: map['userId'].toString(), - userName: map['userName'].toString(), - userEmail: map['userEmail'].toString(), - teamId: map['teamId'].toString(), - teamName: map['teamName'].toString(), - invited: map['invited'].toString(), - joined: map['joined'].toString(), - confirm: map['confirm'], - mfa: map['mfa'], - roles: map['roles'] ?? [], - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "userId": userId, - "userName": userName, - "userEmail": userEmail, - "teamId": teamId, - "teamName": teamName, - "invited": invited, - "joined": joined, - "confirm": confirm, - "mfa": mfa, - "roles": roles, - }; - } + /// Membership ID. + final String $id; + /// Membership creation date in ISO 8601 format. + final String $createdAt; + /// Membership update date in ISO 8601 format. + final String $updatedAt; + /// User ID. + final String userId; + /// User name. + final String userName; + /// User email address. + final String userEmail; + /// Team ID. + final String teamId; + /// Team name. + final String teamName; + /// Date, the user has been invited to join the team in ISO 8601 format. + final String invited; + /// Date, the user has accepted the invitation to join the team in ISO 8601 format. + final String joined; + /// User confirmation status, true if the user has joined the team or false otherwise. + final bool confirm; + /// Multi factor authentication status, true if the user has MFA enabled or false otherwise. + final bool mfa; + /// User list of roles + final List roles; + + Membership({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.userId, + required this.userName, + required this.userEmail, + required this.teamId, + required this.teamName, + required this.invited, + required this.joined, + required this.confirm, + required this.mfa, + required this.roles, + }); + + factory Membership.fromMap(Map map) { + return Membership( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + userId: map['userId'].toString(), + userName: map['userName'].toString(), + userEmail: map['userEmail'].toString(), + teamId: map['teamId'].toString(), + teamName: map['teamName'].toString(), + invited: map['invited'].toString(), + joined: map['joined'].toString(), + confirm: map['confirm'], + mfa: map['mfa'], + roles: map['roles'] ?? [], + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "userId": userId, + "userName": userName, + "userEmail": userEmail, + "teamId": teamId, + "teamName": teamName, + "invited": invited, + "joined": joined, + "confirm": confirm, + "mfa": mfa, + "roles": roles, + }; + } } diff --git a/lib/src/models/membership_list.dart b/lib/src/models/membership_list.dart index 880c1d20..f5302cbf 100644 --- a/lib/src/models/membership_list.dart +++ b/lib/src/models/membership_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Memberships List class MembershipList implements Model { - /// Total number of memberships documents that matched your query. - final int total; + /// Total number of memberships documents that matched your query. + final int total; + /// List of memberships. + final List memberships; - /// List of memberships. - final List memberships; + MembershipList({ + required this.total, + required this.memberships, + }); - MembershipList({ - required this.total, - required this.memberships, - }); + factory MembershipList.fromMap(Map map) { + return MembershipList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + memberships: List.from(map['memberships'].map((p) => Membership.fromMap(p))), + ); + } - factory MembershipList.fromMap(Map map) { - return MembershipList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - memberships: List.from( - map['memberships'].map((p) => Membership.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "memberships": memberships.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "memberships": memberships.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/message.dart b/lib/src/models/message.dart index fe2a53ab..381ab216 100644 --- a/lib/src/models/message.dart +++ b/lib/src/models/message.dart @@ -2,96 +2,83 @@ part of '../../models.dart'; /// Message class Message implements Model { - /// Message ID. - final String $id; - - /// Message creation time in ISO 8601 format. - final String $createdAt; - - /// Message update date in ISO 8601 format. - final String $updatedAt; - - /// Message provider type. - final String providerType; - - /// Topic IDs set as recipients. - final List topics; - - /// User IDs set as recipients. - final List users; - - /// Target IDs set as recipients. - final List targets; - - /// The scheduled time for message. - final String? scheduledAt; - - /// The time when the message was delivered. - final String? deliveredAt; - - /// Delivery errors if any. - final List? deliveryErrors; - - /// Number of recipients the message was delivered to. - final int deliveredTotal; - - /// Data of the message. - final Map data; - - /// Status of delivery. - final String status; - - Message({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.providerType, - required this.topics, - required this.users, - required this.targets, - this.scheduledAt, - this.deliveredAt, - this.deliveryErrors, - required this.deliveredTotal, - required this.data, - required this.status, - }); - - factory Message.fromMap(Map map) { - return Message( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - providerType: map['providerType'].toString(), - topics: map['topics'] ?? [], - users: map['users'] ?? [], - targets: map['targets'] ?? [], - scheduledAt: map['scheduledAt']?.toString(), - deliveredAt: map['deliveredAt']?.toString(), - deliveryErrors: map['deliveryErrors'], - deliveredTotal: (map['deliveredTotal'] is String) - ? int.tryParse(map['deliveredTotal']) ?? 0 - : map['deliveredTotal'] ?? 0, - data: map['data'], - status: map['status'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "providerType": providerType, - "topics": topics, - "users": users, - "targets": targets, - "scheduledAt": scheduledAt, - "deliveredAt": deliveredAt, - "deliveryErrors": deliveryErrors, - "deliveredTotal": deliveredTotal, - "data": data, - "status": status, - }; - } + /// Message ID. + final String $id; + /// Message creation time in ISO 8601 format. + final String $createdAt; + /// Message update date in ISO 8601 format. + final String $updatedAt; + /// Message provider type. + final String providerType; + /// Topic IDs set as recipients. + final List topics; + /// User IDs set as recipients. + final List users; + /// Target IDs set as recipients. + final List targets; + /// The scheduled time for message. + final String? scheduledAt; + /// The time when the message was delivered. + final String? deliveredAt; + /// Delivery errors if any. + final List? deliveryErrors; + /// Number of recipients the message was delivered to. + final int deliveredTotal; + /// Data of the message. + final Map data; + /// Status of delivery. + final String status; + + Message({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.providerType, + required this.topics, + required this.users, + required this.targets, + this.scheduledAt, + this.deliveredAt, + this.deliveryErrors, + required this.deliveredTotal, + required this.data, + required this.status, + }); + + factory Message.fromMap(Map map) { + return Message( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + providerType: map['providerType'].toString(), + topics: map['topics'] ?? [], + users: map['users'] ?? [], + targets: map['targets'] ?? [], + scheduledAt: map['scheduledAt']?.toString(), + deliveredAt: map['deliveredAt']?.toString(), + deliveryErrors: map['deliveryErrors'], + deliveredTotal: (map['deliveredTotal'] is String) ? + int.tryParse(map['deliveredTotal']) ?? 0:map['deliveredTotal'] ?? 0, + data: map['data'], + status: map['status'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "providerType": providerType, + "topics": topics, + "users": users, + "targets": targets, + "scheduledAt": scheduledAt, + "deliveredAt": deliveredAt, + "deliveryErrors": deliveryErrors, + "deliveredTotal": deliveredTotal, + "data": data, + "status": status, + }; + } } diff --git a/lib/src/models/message_list.dart b/lib/src/models/message_list.dart index 1c128731..220d3c52 100644 --- a/lib/src/models/message_list.dart +++ b/lib/src/models/message_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Message list class MessageList implements Model { - /// Total number of messages documents that matched your query. - final int total; + /// Total number of messages documents that matched your query. + final int total; + /// List of messages. + final List messages; - /// List of messages. - final List messages; + MessageList({ + required this.total, + required this.messages, + }); - MessageList({ - required this.total, - required this.messages, - }); + factory MessageList.fromMap(Map map) { + return MessageList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + messages: List.from(map['messages'].map((p) => Message.fromMap(p))), + ); + } - factory MessageList.fromMap(Map map) { - return MessageList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - messages: - List.from(map['messages'].map((p) => Message.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "messages": messages.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "messages": messages.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/mfa_challenge.dart b/lib/src/models/mfa_challenge.dart index 96bf3c65..043ff286 100644 --- a/lib/src/models/mfa_challenge.dart +++ b/lib/src/models/mfa_challenge.dart @@ -2,40 +2,37 @@ part of '../../models.dart'; /// MFA Challenge class MfaChallenge implements Model { - /// Token ID. - final String $id; + /// Token ID. + final String $id; + /// Token creation date in ISO 8601 format. + final String $createdAt; + /// User ID. + final String userId; + /// Token expiration date in ISO 8601 format. + final String expire; - /// Token creation date in ISO 8601 format. - final String $createdAt; + MfaChallenge({ + required this.$id, + required this.$createdAt, + required this.userId, + required this.expire, + }); - /// User ID. - final String userId; + factory MfaChallenge.fromMap(Map map) { + return MfaChallenge( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + userId: map['userId'].toString(), + expire: map['expire'].toString(), + ); + } - /// Token expiration date in ISO 8601 format. - final String expire; - - MfaChallenge({ - required this.$id, - required this.$createdAt, - required this.userId, - required this.expire, - }); - - factory MfaChallenge.fromMap(Map map) { - return MfaChallenge( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - userId: map['userId'].toString(), - expire: map['expire'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "userId": userId, - "expire": expire, - }; - } + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "userId": userId, + "expire": expire, + }; + } } diff --git a/lib/src/models/mfa_factors.dart b/lib/src/models/mfa_factors.dart index c930a23e..f453e870 100644 --- a/lib/src/models/mfa_factors.dart +++ b/lib/src/models/mfa_factors.dart @@ -2,40 +2,37 @@ part of '../../models.dart'; /// MFAFactors class MfaFactors implements Model { - /// Can TOTP be used for MFA challenge for this account. - final bool totp; + /// Can TOTP be used for MFA challenge for this account. + final bool totp; + /// Can phone (SMS) be used for MFA challenge for this account. + final bool phone; + /// Can email be used for MFA challenge for this account. + final bool email; + /// Can recovery code be used for MFA challenge for this account. + final bool recoveryCode; - /// Can phone (SMS) be used for MFA challenge for this account. - final bool phone; + MfaFactors({ + required this.totp, + required this.phone, + required this.email, + required this.recoveryCode, + }); - /// Can email be used for MFA challenge for this account. - final bool email; + factory MfaFactors.fromMap(Map map) { + return MfaFactors( + totp: map['totp'], + phone: map['phone'], + email: map['email'], + recoveryCode: map['recoveryCode'], + ); + } - /// Can recovery code be used for MFA challenge for this account. - final bool recoveryCode; - - MfaFactors({ - required this.totp, - required this.phone, - required this.email, - required this.recoveryCode, - }); - - factory MfaFactors.fromMap(Map map) { - return MfaFactors( - totp: map['totp'], - phone: map['phone'], - email: map['email'], - recoveryCode: map['recoveryCode'], - ); - } - - Map toMap() { - return { - "totp": totp, - "phone": phone, - "email": email, - "recoveryCode": recoveryCode, - }; - } + Map toMap() { + return { + "totp": totp, + "phone": phone, + "email": email, + "recoveryCode": recoveryCode, + }; + } } diff --git a/lib/src/models/mfa_recovery_codes.dart b/lib/src/models/mfa_recovery_codes.dart index 83483901..68402443 100644 --- a/lib/src/models/mfa_recovery_codes.dart +++ b/lib/src/models/mfa_recovery_codes.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// MFA Recovery Codes class MfaRecoveryCodes implements Model { - /// Recovery codes. - final List recoveryCodes; + /// Recovery codes. + final List recoveryCodes; - MfaRecoveryCodes({ - required this.recoveryCodes, - }); + MfaRecoveryCodes({ + required this.recoveryCodes, + }); - factory MfaRecoveryCodes.fromMap(Map map) { - return MfaRecoveryCodes( - recoveryCodes: map['recoveryCodes'] ?? [], - ); - } + factory MfaRecoveryCodes.fromMap(Map map) { + return MfaRecoveryCodes( + recoveryCodes: map['recoveryCodes'] ?? [], + ); + } - Map toMap() { - return { - "recoveryCodes": recoveryCodes, - }; - } + Map toMap() { + return { + "recoveryCodes": recoveryCodes, + }; + } } diff --git a/lib/src/models/mfa_type.dart b/lib/src/models/mfa_type.dart index 0573166e..87064007 100644 --- a/lib/src/models/mfa_type.dart +++ b/lib/src/models/mfa_type.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// MFAType class MfaType implements Model { - /// Secret token used for TOTP factor. - final String secret; + /// Secret token used for TOTP factor. + final String secret; + /// URI for authenticator apps. + final String uri; - /// URI for authenticator apps. - final String uri; + MfaType({ + required this.secret, + required this.uri, + }); - MfaType({ - required this.secret, - required this.uri, - }); + factory MfaType.fromMap(Map map) { + return MfaType( + secret: map['secret'].toString(), + uri: map['uri'].toString(), + ); + } - factory MfaType.fromMap(Map map) { - return MfaType( - secret: map['secret'].toString(), - uri: map['uri'].toString(), - ); - } - - Map toMap() { - return { - "secret": secret, - "uri": uri, - }; - } + Map toMap() { + return { + "secret": secret, + "uri": uri, + }; + } } diff --git a/lib/src/models/model.dart b/lib/src/models/model.dart index f810a35b..48e5b84a 100644 --- a/lib/src/models/model.dart +++ b/lib/src/models/model.dart @@ -2,4 +2,4 @@ part of '../../models.dart'; abstract class Model { Map toMap(); -} +} \ No newline at end of file diff --git a/lib/src/models/phone.dart b/lib/src/models/phone.dart index 40f7bcd2..24f7260d 100644 --- a/lib/src/models/phone.dart +++ b/lib/src/models/phone.dart @@ -2,34 +2,32 @@ part of '../../models.dart'; /// Phone class Phone implements Model { - /// Phone code. - final String code; + /// Phone code. + final String code; + /// Country two-character ISO 3166-1 alpha code. + final String countryCode; + /// Country name. + final String countryName; - /// Country two-character ISO 3166-1 alpha code. - final String countryCode; + Phone({ + required this.code, + required this.countryCode, + required this.countryName, + }); - /// Country name. - final String countryName; + factory Phone.fromMap(Map map) { + return Phone( + code: map['code'].toString(), + countryCode: map['countryCode'].toString(), + countryName: map['countryName'].toString(), + ); + } - Phone({ - required this.code, - required this.countryCode, - required this.countryName, - }); - - factory Phone.fromMap(Map map) { - return Phone( - code: map['code'].toString(), - countryCode: map['countryCode'].toString(), - countryName: map['countryName'].toString(), - ); - } - - Map toMap() { - return { - "code": code, - "countryCode": countryCode, - "countryName": countryName, - }; - } + Map toMap() { + return { + "code": code, + "countryCode": countryCode, + "countryName": countryName, + }; + } } diff --git a/lib/src/models/phone_list.dart b/lib/src/models/phone_list.dart index f2cb989b..f00a91d3 100644 --- a/lib/src/models/phone_list.dart +++ b/lib/src/models/phone_list.dart @@ -2,30 +2,28 @@ part of '../../models.dart'; /// Phones List class PhoneList implements Model { - /// Total number of phones documents that matched your query. - final int total; + /// Total number of phones documents that matched your query. + final int total; + /// List of phones. + final List phones; - /// List of phones. - final List phones; + PhoneList({ + required this.total, + required this.phones, + }); - PhoneList({ - required this.total, - required this.phones, - }); + factory PhoneList.fromMap(Map map) { + return PhoneList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + phones: List.from(map['phones'].map((p) => Phone.fromMap(p))), + ); + } - factory PhoneList.fromMap(Map map) { - return PhoneList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - phones: List.from(map['phones'].map((p) => Phone.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "phones": phones.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "phones": phones.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/preferences.dart b/lib/src/models/preferences.dart index 3549cff0..3c62f86d 100644 --- a/lib/src/models/preferences.dart +++ b/lib/src/models/preferences.dart @@ -2,23 +2,23 @@ part of '../../models.dart'; /// Preferences class Preferences implements Model { - final Map data; + final Map data; - Preferences({ - required this.data, - }); + Preferences({ + required this.data, + }); - factory Preferences.fromMap(Map map) { - return Preferences( - data: map, - ); - } + factory Preferences.fromMap(Map map) { + return Preferences( + data: map, + ); + } - Map toMap() { - return { - "data": data, - }; - } + Map toMap() { + return { + "data": data, + }; + } - T convertTo(T Function(Map) fromJson) => fromJson(data); + T convertTo(T Function(Map) fromJson) => fromJson(data); } diff --git a/lib/src/models/provider.dart b/lib/src/models/provider.dart index 1a762f85..ba0855de 100644 --- a/lib/src/models/provider.dart +++ b/lib/src/models/provider.dart @@ -2,70 +2,62 @@ part of '../../models.dart'; /// Provider class Provider implements Model { - /// Provider ID. - final String $id; - - /// Provider creation time in ISO 8601 format. - final String $createdAt; - - /// Provider update date in ISO 8601 format. - final String $updatedAt; - - /// The name for the provider instance. - final String name; - - /// The name of the provider service. - final String provider; - - /// Is provider enabled? - final bool enabled; - - /// Type of provider. - final String type; - - /// Provider credentials. - final Map credentials; - - /// Provider options. - final Map? options; - - Provider({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.provider, - required this.enabled, - required this.type, - required this.credentials, - this.options, - }); - - factory Provider.fromMap(Map map) { - return Provider( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - provider: map['provider'].toString(), - enabled: map['enabled'], - type: map['type'].toString(), - credentials: map['credentials'], - options: map['options'], - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "provider": provider, - "enabled": enabled, - "type": type, - "credentials": credentials, - "options": options, - }; - } + /// Provider ID. + final String $id; + /// Provider creation time in ISO 8601 format. + final String $createdAt; + /// Provider update date in ISO 8601 format. + final String $updatedAt; + /// The name for the provider instance. + final String name; + /// The name of the provider service. + final String provider; + /// Is provider enabled? + final bool enabled; + /// Type of provider. + final String type; + /// Provider credentials. + final Map credentials; + /// Provider options. + final Map? options; + + Provider({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.provider, + required this.enabled, + required this.type, + required this.credentials, + this.options, + }); + + factory Provider.fromMap(Map map) { + return Provider( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + provider: map['provider'].toString(), + enabled: map['enabled'], + type: map['type'].toString(), + credentials: map['credentials'], + options: map['options'], + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "provider": provider, + "enabled": enabled, + "type": type, + "credentials": credentials, + "options": options, + }; + } } diff --git a/lib/src/models/provider_list.dart b/lib/src/models/provider_list.dart index 415f0d9b..fe6d41d0 100644 --- a/lib/src/models/provider_list.dart +++ b/lib/src/models/provider_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Provider list class ProviderList implements Model { - /// Total number of providers documents that matched your query. - final int total; + /// Total number of providers documents that matched your query. + final int total; + /// List of providers. + final List providers; - /// List of providers. - final List providers; + ProviderList({ + required this.total, + required this.providers, + }); - ProviderList({ - required this.total, - required this.providers, - }); + factory ProviderList.fromMap(Map map) { + return ProviderList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + providers: List.from(map['providers'].map((p) => Provider.fromMap(p))), + ); + } - factory ProviderList.fromMap(Map map) { - return ProviderList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - providers: - List.from(map['providers'].map((p) => Provider.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "providers": providers.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "providers": providers.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/runtime.dart b/lib/src/models/runtime.dart index c99f3541..acda5a4f 100644 --- a/lib/src/models/runtime.dart +++ b/lib/src/models/runtime.dart @@ -2,64 +2,57 @@ part of '../../models.dart'; /// Runtime class Runtime implements Model { - /// Runtime ID. - final String $id; - - /// Parent runtime key. - final String key; - - /// Runtime Name. - final String name; - - /// Runtime version. - final String version; - - /// Base Docker image used to build the runtime. - final String base; - - /// Image name of Docker Hub. - final String image; - - /// Name of the logo image. - final String logo; - - /// List of supported architectures. - final List supports; - - Runtime({ - required this.$id, - required this.key, - required this.name, - required this.version, - required this.base, - required this.image, - required this.logo, - required this.supports, - }); - - factory Runtime.fromMap(Map map) { - return Runtime( - $id: map['\$id'].toString(), - key: map['key'].toString(), - name: map['name'].toString(), - version: map['version'].toString(), - base: map['base'].toString(), - image: map['image'].toString(), - logo: map['logo'].toString(), - supports: map['supports'] ?? [], - ); - } - - Map toMap() { - return { - "\$id": $id, - "key": key, - "name": name, - "version": version, - "base": base, - "image": image, - "logo": logo, - "supports": supports, - }; - } + /// Runtime ID. + final String $id; + /// Parent runtime key. + final String key; + /// Runtime Name. + final String name; + /// Runtime version. + final String version; + /// Base Docker image used to build the runtime. + final String base; + /// Image name of Docker Hub. + final String image; + /// Name of the logo image. + final String logo; + /// List of supported architectures. + final List supports; + + Runtime({ + required this.$id, + required this.key, + required this.name, + required this.version, + required this.base, + required this.image, + required this.logo, + required this.supports, + }); + + factory Runtime.fromMap(Map map) { + return Runtime( + $id: map['\$id'].toString(), + key: map['key'].toString(), + name: map['name'].toString(), + version: map['version'].toString(), + base: map['base'].toString(), + image: map['image'].toString(), + logo: map['logo'].toString(), + supports: map['supports'] ?? [], + ); + } + + Map toMap() { + return { + "\$id": $id, + "key": key, + "name": name, + "version": version, + "base": base, + "image": image, + "logo": logo, + "supports": supports, + }; + } } diff --git a/lib/src/models/runtime_list.dart b/lib/src/models/runtime_list.dart index 386ef56f..8ee86986 100644 --- a/lib/src/models/runtime_list.dart +++ b/lib/src/models/runtime_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Runtimes List class RuntimeList implements Model { - /// Total number of runtimes documents that matched your query. - final int total; + /// Total number of runtimes documents that matched your query. + final int total; + /// List of runtimes. + final List runtimes; - /// List of runtimes. - final List runtimes; + RuntimeList({ + required this.total, + required this.runtimes, + }); - RuntimeList({ - required this.total, - required this.runtimes, - }); + factory RuntimeList.fromMap(Map map) { + return RuntimeList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + runtimes: List.from(map['runtimes'].map((p) => Runtime.fromMap(p))), + ); + } - factory RuntimeList.fromMap(Map map) { - return RuntimeList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - runtimes: - List.from(map['runtimes'].map((p) => Runtime.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "runtimes": runtimes.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "runtimes": runtimes.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/session.dart b/lib/src/models/session.dart index 1f55d400..10566f44 100644 --- a/lib/src/models/session.dart +++ b/lib/src/models/session.dart @@ -2,190 +2,162 @@ part of '../../models.dart'; /// Session class Session implements Model { - /// Session ID. - final String $id; - - /// Session creation date in ISO 8601 format. - final String $createdAt; - - /// Session update date in ISO 8601 format. - final String $updatedAt; - - /// User ID. - final String userId; - - /// Session expiration date in ISO 8601 format. - final String expire; - - /// Session Provider. - final String provider; - - /// Session Provider User ID. - final String providerUid; - - /// Session Provider Access Token. - final String providerAccessToken; - - /// The date of when the access token expires in ISO 8601 format. - final String providerAccessTokenExpiry; - - /// Session Provider Refresh Token. - final String providerRefreshToken; - - /// IP in use when the session was created. - final String ip; - - /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). - final String osCode; - - /// Operating system name. - final String osName; - - /// Operating system version. - final String osVersion; - - /// Client type. - final String clientType; - - /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). - final String clientCode; - - /// Client name. - final String clientName; - - /// Client version. - final String clientVersion; - - /// Client engine name. - final String clientEngine; - - /// Client engine name. - final String clientEngineVersion; - - /// Device name. - final String deviceName; - - /// Device brand name. - final String deviceBrand; - - /// Device model name. - final String deviceModel; - - /// Country two-character ISO 3166-1 alpha code. - final String countryCode; - - /// Country name. - final String countryName; - - /// Returns true if this the current user session. - final bool current; - - /// Returns a list of active session factors. - final List factors; - - /// Secret used to authenticate the user. Only included if the request was made with an API key - final String secret; - - /// Most recent date in ISO 8601 format when the session successfully passed MFA challenge. - final String mfaUpdatedAt; - - Session({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.userId, - required this.expire, - required this.provider, - required this.providerUid, - required this.providerAccessToken, - required this.providerAccessTokenExpiry, - required this.providerRefreshToken, - required this.ip, - required this.osCode, - required this.osName, - required this.osVersion, - required this.clientType, - required this.clientCode, - required this.clientName, - required this.clientVersion, - required this.clientEngine, - required this.clientEngineVersion, - required this.deviceName, - required this.deviceBrand, - required this.deviceModel, - required this.countryCode, - required this.countryName, - required this.current, - required this.factors, - required this.secret, - required this.mfaUpdatedAt, - }); - - factory Session.fromMap(Map map) { - return Session( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - userId: map['userId'].toString(), - expire: map['expire'].toString(), - provider: map['provider'].toString(), - providerUid: map['providerUid'].toString(), - providerAccessToken: map['providerAccessToken'].toString(), - providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), - providerRefreshToken: map['providerRefreshToken'].toString(), - ip: map['ip'].toString(), - osCode: map['osCode'].toString(), - osName: map['osName'].toString(), - osVersion: map['osVersion'].toString(), - clientType: map['clientType'].toString(), - clientCode: map['clientCode'].toString(), - clientName: map['clientName'].toString(), - clientVersion: map['clientVersion'].toString(), - clientEngine: map['clientEngine'].toString(), - clientEngineVersion: map['clientEngineVersion'].toString(), - deviceName: map['deviceName'].toString(), - deviceBrand: map['deviceBrand'].toString(), - deviceModel: map['deviceModel'].toString(), - countryCode: map['countryCode'].toString(), - countryName: map['countryName'].toString(), - current: map['current'], - factors: map['factors'] ?? [], - secret: map['secret'].toString(), - mfaUpdatedAt: map['mfaUpdatedAt'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "userId": userId, - "expire": expire, - "provider": provider, - "providerUid": providerUid, - "providerAccessToken": providerAccessToken, - "providerAccessTokenExpiry": providerAccessTokenExpiry, - "providerRefreshToken": providerRefreshToken, - "ip": ip, - "osCode": osCode, - "osName": osName, - "osVersion": osVersion, - "clientType": clientType, - "clientCode": clientCode, - "clientName": clientName, - "clientVersion": clientVersion, - "clientEngine": clientEngine, - "clientEngineVersion": clientEngineVersion, - "deviceName": deviceName, - "deviceBrand": deviceBrand, - "deviceModel": deviceModel, - "countryCode": countryCode, - "countryName": countryName, - "current": current, - "factors": factors, - "secret": secret, - "mfaUpdatedAt": mfaUpdatedAt, - }; - } + /// Session ID. + final String $id; + /// Session creation date in ISO 8601 format. + final String $createdAt; + /// Session update date in ISO 8601 format. + final String $updatedAt; + /// User ID. + final String userId; + /// Session expiration date in ISO 8601 format. + final String expire; + /// Session Provider. + final String provider; + /// Session Provider User ID. + final String providerUid; + /// Session Provider Access Token. + final String providerAccessToken; + /// The date of when the access token expires in ISO 8601 format. + final String providerAccessTokenExpiry; + /// Session Provider Refresh Token. + final String providerRefreshToken; + /// IP in use when the session was created. + final String ip; + /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). + final String osCode; + /// Operating system name. + final String osName; + /// Operating system version. + final String osVersion; + /// Client type. + final String clientType; + /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). + final String clientCode; + /// Client name. + final String clientName; + /// Client version. + final String clientVersion; + /// Client engine name. + final String clientEngine; + /// Client engine name. + final String clientEngineVersion; + /// Device name. + final String deviceName; + /// Device brand name. + final String deviceBrand; + /// Device model name. + final String deviceModel; + /// Country two-character ISO 3166-1 alpha code. + final String countryCode; + /// Country name. + final String countryName; + /// Returns true if this the current user session. + final bool current; + /// Returns a list of active session factors. + final List factors; + /// Secret used to authenticate the user. Only included if the request was made with an API key + final String secret; + /// Most recent date in ISO 8601 format when the session successfully passed MFA challenge. + final String mfaUpdatedAt; + + Session({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.userId, + required this.expire, + required this.provider, + required this.providerUid, + required this.providerAccessToken, + required this.providerAccessTokenExpiry, + required this.providerRefreshToken, + required this.ip, + required this.osCode, + required this.osName, + required this.osVersion, + required this.clientType, + required this.clientCode, + required this.clientName, + required this.clientVersion, + required this.clientEngine, + required this.clientEngineVersion, + required this.deviceName, + required this.deviceBrand, + required this.deviceModel, + required this.countryCode, + required this.countryName, + required this.current, + required this.factors, + required this.secret, + required this.mfaUpdatedAt, + }); + + factory Session.fromMap(Map map) { + return Session( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + userId: map['userId'].toString(), + expire: map['expire'].toString(), + provider: map['provider'].toString(), + providerUid: map['providerUid'].toString(), + providerAccessToken: map['providerAccessToken'].toString(), + providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), + providerRefreshToken: map['providerRefreshToken'].toString(), + ip: map['ip'].toString(), + osCode: map['osCode'].toString(), + osName: map['osName'].toString(), + osVersion: map['osVersion'].toString(), + clientType: map['clientType'].toString(), + clientCode: map['clientCode'].toString(), + clientName: map['clientName'].toString(), + clientVersion: map['clientVersion'].toString(), + clientEngine: map['clientEngine'].toString(), + clientEngineVersion: map['clientEngineVersion'].toString(), + deviceName: map['deviceName'].toString(), + deviceBrand: map['deviceBrand'].toString(), + deviceModel: map['deviceModel'].toString(), + countryCode: map['countryCode'].toString(), + countryName: map['countryName'].toString(), + current: map['current'], + factors: map['factors'] ?? [], + secret: map['secret'].toString(), + mfaUpdatedAt: map['mfaUpdatedAt'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "userId": userId, + "expire": expire, + "provider": provider, + "providerUid": providerUid, + "providerAccessToken": providerAccessToken, + "providerAccessTokenExpiry": providerAccessTokenExpiry, + "providerRefreshToken": providerRefreshToken, + "ip": ip, + "osCode": osCode, + "osName": osName, + "osVersion": osVersion, + "clientType": clientType, + "clientCode": clientCode, + "clientName": clientName, + "clientVersion": clientVersion, + "clientEngine": clientEngine, + "clientEngineVersion": clientEngineVersion, + "deviceName": deviceName, + "deviceBrand": deviceBrand, + "deviceModel": deviceModel, + "countryCode": countryCode, + "countryName": countryName, + "current": current, + "factors": factors, + "secret": secret, + "mfaUpdatedAt": mfaUpdatedAt, + }; + } } diff --git a/lib/src/models/session_list.dart b/lib/src/models/session_list.dart index cc1ed114..f17b963d 100644 --- a/lib/src/models/session_list.dart +++ b/lib/src/models/session_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Sessions List class SessionList implements Model { - /// Total number of sessions documents that matched your query. - final int total; + /// Total number of sessions documents that matched your query. + final int total; + /// List of sessions. + final List sessions; - /// List of sessions. - final List sessions; + SessionList({ + required this.total, + required this.sessions, + }); - SessionList({ - required this.total, - required this.sessions, - }); + factory SessionList.fromMap(Map map) { + return SessionList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + sessions: List.from(map['sessions'].map((p) => Session.fromMap(p))), + ); + } - factory SessionList.fromMap(Map map) { - return SessionList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - sessions: - List.from(map['sessions'].map((p) => Session.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "sessions": sessions.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "sessions": sessions.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/specification.dart b/lib/src/models/specification.dart index 97e030ee..97b359f2 100644 --- a/lib/src/models/specification.dart +++ b/lib/src/models/specification.dart @@ -2,42 +2,38 @@ part of '../../models.dart'; /// Specification class Specification implements Model { - /// Memory size in MB. - final int memory; + /// Memory size in MB. + final int memory; + /// Number of CPUs. + final double cpus; + /// Is size enabled. + final bool enabled; + /// Size slug. + final String slug; - /// Number of CPUs. - final double cpus; + Specification({ + required this.memory, + required this.cpus, + required this.enabled, + required this.slug, + }); - /// Is size enabled. - final bool enabled; + factory Specification.fromMap(Map map) { + return Specification( + memory: (map['memory'] is String) ? + int.tryParse(map['memory']) ?? 0:map['memory'] ?? 0, + cpus: map['cpus'].toDouble(), + enabled: map['enabled'], + slug: map['slug'].toString(), + ); + } - /// Size slug. - final String slug; - - Specification({ - required this.memory, - required this.cpus, - required this.enabled, - required this.slug, - }); - - factory Specification.fromMap(Map map) { - return Specification( - memory: (map['memory'] is String) - ? int.tryParse(map['memory']) ?? 0 - : map['memory'] ?? 0, - cpus: map['cpus'].toDouble(), - enabled: map['enabled'], - slug: map['slug'].toString(), - ); - } - - Map toMap() { - return { - "memory": memory, - "cpus": cpus, - "enabled": enabled, - "slug": slug, - }; - } + Map toMap() { + return { + "memory": memory, + "cpus": cpus, + "enabled": enabled, + "slug": slug, + }; + } } diff --git a/lib/src/models/specification_list.dart b/lib/src/models/specification_list.dart index 9413334e..1b7d3a69 100644 --- a/lib/src/models/specification_list.dart +++ b/lib/src/models/specification_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Specifications List class SpecificationList implements Model { - /// Total number of specifications documents that matched your query. - final int total; + /// Total number of specifications documents that matched your query. + final int total; + /// List of specifications. + final List specifications; - /// List of specifications. - final List specifications; + SpecificationList({ + required this.total, + required this.specifications, + }); - SpecificationList({ - required this.total, - required this.specifications, - }); + factory SpecificationList.fromMap(Map map) { + return SpecificationList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + specifications: List.from(map['specifications'].map((p) => Specification.fromMap(p))), + ); + } - factory SpecificationList.fromMap(Map map) { - return SpecificationList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - specifications: List.from( - map['specifications'].map((p) => Specification.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "specifications": specifications.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "specifications": specifications.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/subscriber.dart b/lib/src/models/subscriber.dart index 0c926297..97bdb018 100644 --- a/lib/src/models/subscriber.dart +++ b/lib/src/models/subscriber.dart @@ -2,70 +2,62 @@ part of '../../models.dart'; /// Subscriber class Subscriber implements Model { - /// Subscriber ID. - final String $id; - - /// Subscriber creation time in ISO 8601 format. - final String $createdAt; - - /// Subscriber update date in ISO 8601 format. - final String $updatedAt; - - /// Target ID. - final String targetId; - - /// Target. - final Target target; - - /// Topic ID. - final String userId; - - /// User Name. - final String userName; - - /// Topic ID. - final String topicId; - - /// The target provider type. Can be one of the following: `email`, `sms` or `push`. - final String providerType; - - Subscriber({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.targetId, - required this.target, - required this.userId, - required this.userName, - required this.topicId, - required this.providerType, - }); - - factory Subscriber.fromMap(Map map) { - return Subscriber( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - targetId: map['targetId'].toString(), - target: Target.fromMap(map['target']), - userId: map['userId'].toString(), - userName: map['userName'].toString(), - topicId: map['topicId'].toString(), - providerType: map['providerType'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "targetId": targetId, - "target": target.toMap(), - "userId": userId, - "userName": userName, - "topicId": topicId, - "providerType": providerType, - }; - } + /// Subscriber ID. + final String $id; + /// Subscriber creation time in ISO 8601 format. + final String $createdAt; + /// Subscriber update date in ISO 8601 format. + final String $updatedAt; + /// Target ID. + final String targetId; + /// Target. + final Target target; + /// Topic ID. + final String userId; + /// User Name. + final String userName; + /// Topic ID. + final String topicId; + /// The target provider type. Can be one of the following: `email`, `sms` or `push`. + final String providerType; + + Subscriber({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.targetId, + required this.target, + required this.userId, + required this.userName, + required this.topicId, + required this.providerType, + }); + + factory Subscriber.fromMap(Map map) { + return Subscriber( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + targetId: map['targetId'].toString(), + target: Target.fromMap(map['target']), + userId: map['userId'].toString(), + userName: map['userName'].toString(), + topicId: map['topicId'].toString(), + providerType: map['providerType'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "targetId": targetId, + "target": target.toMap(), + "userId": userId, + "userName": userName, + "topicId": topicId, + "providerType": providerType, + }; + } } diff --git a/lib/src/models/subscriber_list.dart b/lib/src/models/subscriber_list.dart index eaed257c..dc6724cf 100644 --- a/lib/src/models/subscriber_list.dart +++ b/lib/src/models/subscriber_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Subscriber list class SubscriberList implements Model { - /// Total number of subscribers documents that matched your query. - final int total; + /// Total number of subscribers documents that matched your query. + final int total; + /// List of subscribers. + final List subscribers; - /// List of subscribers. - final List subscribers; + SubscriberList({ + required this.total, + required this.subscribers, + }); - SubscriberList({ - required this.total, - required this.subscribers, - }); + factory SubscriberList.fromMap(Map map) { + return SubscriberList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + subscribers: List.from(map['subscribers'].map((p) => Subscriber.fromMap(p))), + ); + } - factory SubscriberList.fromMap(Map map) { - return SubscriberList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - subscribers: List.from( - map['subscribers'].map((p) => Subscriber.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "subscribers": subscribers.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "subscribers": subscribers.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/target.dart b/lib/src/models/target.dart index 68460126..50134304 100644 --- a/lib/src/models/target.dart +++ b/lib/src/models/target.dart @@ -2,64 +2,57 @@ part of '../../models.dart'; /// Target class Target implements Model { - /// Target ID. - final String $id; - - /// Target creation time in ISO 8601 format. - final String $createdAt; - - /// Target update date in ISO 8601 format. - final String $updatedAt; - - /// Target Name. - final String name; - - /// User ID. - final String userId; - - /// Provider ID. - final String? providerId; - - /// The target provider type. Can be one of the following: `email`, `sms` or `push`. - final String providerType; - - /// The target identifier. - final String identifier; - - Target({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.userId, - this.providerId, - required this.providerType, - required this.identifier, - }); - - factory Target.fromMap(Map map) { - return Target( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - userId: map['userId'].toString(), - providerId: map['providerId']?.toString(), - providerType: map['providerType'].toString(), - identifier: map['identifier'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "userId": userId, - "providerId": providerId, - "providerType": providerType, - "identifier": identifier, - }; - } + /// Target ID. + final String $id; + /// Target creation time in ISO 8601 format. + final String $createdAt; + /// Target update date in ISO 8601 format. + final String $updatedAt; + /// Target Name. + final String name; + /// User ID. + final String userId; + /// Provider ID. + final String? providerId; + /// The target provider type. Can be one of the following: `email`, `sms` or `push`. + final String providerType; + /// The target identifier. + final String identifier; + + Target({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.userId, + this.providerId, + required this.providerType, + required this.identifier, + }); + + factory Target.fromMap(Map map) { + return Target( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + userId: map['userId'].toString(), + providerId: map['providerId']?.toString(), + providerType: map['providerType'].toString(), + identifier: map['identifier'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "userId": userId, + "providerId": providerId, + "providerType": providerType, + "identifier": identifier, + }; + } } diff --git a/lib/src/models/target_list.dart b/lib/src/models/target_list.dart index 4cdcf666..bc859bee 100644 --- a/lib/src/models/target_list.dart +++ b/lib/src/models/target_list.dart @@ -2,30 +2,28 @@ part of '../../models.dart'; /// Target list class TargetList implements Model { - /// Total number of targets documents that matched your query. - final int total; + /// Total number of targets documents that matched your query. + final int total; + /// List of targets. + final List targets; - /// List of targets. - final List targets; + TargetList({ + required this.total, + required this.targets, + }); - TargetList({ - required this.total, - required this.targets, - }); + factory TargetList.fromMap(Map map) { + return TargetList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + targets: List.from(map['targets'].map((p) => Target.fromMap(p))), + ); + } - factory TargetList.fromMap(Map map) { - return TargetList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - targets: List.from(map['targets'].map((p) => Target.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "targets": targets.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "targets": targets.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/team.dart b/lib/src/models/team.dart index 8f9bece6..118be8dd 100644 --- a/lib/src/models/team.dart +++ b/lib/src/models/team.dart @@ -2,54 +2,48 @@ part of '../../models.dart'; /// Team class Team implements Model { - /// Team ID. - final String $id; - - /// Team creation date in ISO 8601 format. - final String $createdAt; - - /// Team update date in ISO 8601 format. - final String $updatedAt; - - /// Team name. - final String name; - - /// Total number of team members. - final int total; - - /// Team preferences as a key-value object - final Preferences prefs; - - Team({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.total, - required this.prefs, - }); - - factory Team.fromMap(Map map) { - return Team( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - prefs: Preferences.fromMap(map['prefs']), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "total": total, - "prefs": prefs.toMap(), - }; - } + /// Team ID. + final String $id; + /// Team creation date in ISO 8601 format. + final String $createdAt; + /// Team update date in ISO 8601 format. + final String $updatedAt; + /// Team name. + final String name; + /// Total number of team members. + final int total; + /// Team preferences as a key-value object + final Preferences prefs; + + Team({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.total, + required this.prefs, + }); + + factory Team.fromMap(Map map) { + return Team( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + prefs: Preferences.fromMap(map['prefs']), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "total": total, + "prefs": prefs.toMap(), + }; + } } diff --git a/lib/src/models/team_list.dart b/lib/src/models/team_list.dart index a4dfe204..f011ce95 100644 --- a/lib/src/models/team_list.dart +++ b/lib/src/models/team_list.dart @@ -2,30 +2,28 @@ part of '../../models.dart'; /// Teams List class TeamList implements Model { - /// Total number of teams documents that matched your query. - final int total; + /// Total number of teams documents that matched your query. + final int total; + /// List of teams. + final List teams; - /// List of teams. - final List teams; + TeamList({ + required this.total, + required this.teams, + }); - TeamList({ - required this.total, - required this.teams, - }); + factory TeamList.fromMap(Map map) { + return TeamList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + teams: List.from(map['teams'].map((p) => Team.fromMap(p))), + ); + } - factory TeamList.fromMap(Map map) { - return TeamList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - teams: List.from(map['teams'].map((p) => Team.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "teams": teams.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "teams": teams.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/token.dart b/lib/src/models/token.dart index 35115467..217006c0 100644 --- a/lib/src/models/token.dart +++ b/lib/src/models/token.dart @@ -2,52 +2,47 @@ part of '../../models.dart'; /// Token class Token implements Model { - /// Token ID. - final String $id; - - /// Token creation date in ISO 8601 format. - final String $createdAt; - - /// User ID. - final String userId; - - /// Token secret key. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. - final String secret; - - /// Token expiration date in ISO 8601 format. - final String expire; - - /// Security phrase of a token. Empty if security phrase was not requested when creating a token. It includes randomly generated phrase which is also sent in the external resource such as email. - final String phrase; - - Token({ - required this.$id, - required this.$createdAt, - required this.userId, - required this.secret, - required this.expire, - required this.phrase, - }); - - factory Token.fromMap(Map map) { - return Token( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - userId: map['userId'].toString(), - secret: map['secret'].toString(), - expire: map['expire'].toString(), - phrase: map['phrase'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "userId": userId, - "secret": secret, - "expire": expire, - "phrase": phrase, - }; - } + /// Token ID. + final String $id; + /// Token creation date in ISO 8601 format. + final String $createdAt; + /// User ID. + final String userId; + /// Token secret key. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. + final String secret; + /// Token expiration date in ISO 8601 format. + final String expire; + /// Security phrase of a token. Empty if security phrase was not requested when creating a token. It includes randomly generated phrase which is also sent in the external resource such as email. + final String phrase; + + Token({ + required this.$id, + required this.$createdAt, + required this.userId, + required this.secret, + required this.expire, + required this.phrase, + }); + + factory Token.fromMap(Map map) { + return Token( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + userId: map['userId'].toString(), + secret: map['secret'].toString(), + expire: map['expire'].toString(), + phrase: map['phrase'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "userId": userId, + "secret": secret, + "expire": expire, + "phrase": phrase, + }; + } } diff --git a/lib/src/models/topic.dart b/lib/src/models/topic.dart index 8410de02..bb9ddc3f 100644 --- a/lib/src/models/topic.dart +++ b/lib/src/models/topic.dart @@ -2,70 +2,60 @@ part of '../../models.dart'; /// Topic class Topic implements Model { - /// Topic ID. - final String $id; - - /// Topic creation time in ISO 8601 format. - final String $createdAt; - - /// Topic update date in ISO 8601 format. - final String $updatedAt; - - /// The name of the topic. - final String name; - - /// Total count of email subscribers subscribed to the topic. - final int emailTotal; - - /// Total count of SMS subscribers subscribed to the topic. - final int smsTotal; - - /// Total count of push subscribers subscribed to the topic. - final int pushTotal; - - /// Subscribe permissions. - final List subscribe; - - Topic({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.emailTotal, - required this.smsTotal, - required this.pushTotal, - required this.subscribe, - }); - - factory Topic.fromMap(Map map) { - return Topic( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - emailTotal: (map['emailTotal'] is String) - ? int.tryParse(map['emailTotal']) ?? 0 - : map['emailTotal'] ?? 0, - smsTotal: (map['smsTotal'] is String) - ? int.tryParse(map['smsTotal']) ?? 0 - : map['smsTotal'] ?? 0, - pushTotal: (map['pushTotal'] is String) - ? int.tryParse(map['pushTotal']) ?? 0 - : map['pushTotal'] ?? 0, - subscribe: map['subscribe'] ?? [], - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "emailTotal": emailTotal, - "smsTotal": smsTotal, - "pushTotal": pushTotal, - "subscribe": subscribe, - }; - } + /// Topic ID. + final String $id; + /// Topic creation time in ISO 8601 format. + final String $createdAt; + /// Topic update date in ISO 8601 format. + final String $updatedAt; + /// The name of the topic. + final String name; + /// Total count of email subscribers subscribed to the topic. + final int emailTotal; + /// Total count of SMS subscribers subscribed to the topic. + final int smsTotal; + /// Total count of push subscribers subscribed to the topic. + final int pushTotal; + /// Subscribe permissions. + final List subscribe; + + Topic({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.emailTotal, + required this.smsTotal, + required this.pushTotal, + required this.subscribe, + }); + + factory Topic.fromMap(Map map) { + return Topic( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + emailTotal: (map['emailTotal'] is String) ? + int.tryParse(map['emailTotal']) ?? 0:map['emailTotal'] ?? 0, + smsTotal: (map['smsTotal'] is String) ? + int.tryParse(map['smsTotal']) ?? 0:map['smsTotal'] ?? 0, + pushTotal: (map['pushTotal'] is String) ? + int.tryParse(map['pushTotal']) ?? 0:map['pushTotal'] ?? 0, + subscribe: map['subscribe'] ?? [], + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "emailTotal": emailTotal, + "smsTotal": smsTotal, + "pushTotal": pushTotal, + "subscribe": subscribe, + }; + } } diff --git a/lib/src/models/topic_list.dart b/lib/src/models/topic_list.dart index bc474b61..64e6598f 100644 --- a/lib/src/models/topic_list.dart +++ b/lib/src/models/topic_list.dart @@ -2,30 +2,28 @@ part of '../../models.dart'; /// Topic list class TopicList implements Model { - /// Total number of topics documents that matched your query. - final int total; + /// Total number of topics documents that matched your query. + final int total; + /// List of topics. + final List topics; - /// List of topics. - final List topics; + TopicList({ + required this.total, + required this.topics, + }); - TopicList({ - required this.total, - required this.topics, - }); + factory TopicList.fromMap(Map map) { + return TopicList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + topics: List.from(map['topics'].map((p) => Topic.fromMap(p))), + ); + } - factory TopicList.fromMap(Map map) { - return TopicList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - topics: List.from(map['topics'].map((p) => Topic.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "topics": topics.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "topics": topics.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/user.dart b/lib/src/models/user.dart index 889005cf..5937ff55 100644 --- a/lib/src/models/user.dart +++ b/lib/src/models/user.dart @@ -2,130 +2,112 @@ part of '../../models.dart'; /// User class User implements Model { - /// User ID. - final String $id; - - /// User creation date in ISO 8601 format. - final String $createdAt; - - /// User update date in ISO 8601 format. - final String $updatedAt; - - /// User name. - final String name; - - /// Hashed user password. - final String? password; - - /// Password hashing algorithm. - final String? hash; - - /// Password hashing algorithm configuration. - final Map? hashOptions; - - /// User registration date in ISO 8601 format. - final String registration; - - /// User status. Pass `true` for enabled and `false` for disabled. - final bool status; - - /// Labels for the user. - final List labels; - - /// Password update time in ISO 8601 format. - final String passwordUpdate; - - /// User email address. - final String email; - - /// User phone number in E.164 format. - final String phone; - - /// Email verification status. - final bool emailVerification; - - /// Phone verification status. - final bool phoneVerification; - - /// Multi factor authentication status. - final bool mfa; - - /// User preferences as a key-value object - final Preferences prefs; - - /// A user-owned message receiver. A single user may have multiple e.g. emails, phones, and a browser. Each target is registered with a single provider. - final List targets; - - /// Most recent access date in ISO 8601 format. This attribute is only updated again after 24 hours. - final String accessedAt; - - User({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - this.password, - this.hash, - this.hashOptions, - required this.registration, - required this.status, - required this.labels, - required this.passwordUpdate, - required this.email, - required this.phone, - required this.emailVerification, - required this.phoneVerification, - required this.mfa, - required this.prefs, - required this.targets, - required this.accessedAt, - }); - - factory User.fromMap(Map map) { - return User( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - password: map['password']?.toString(), - hash: map['hash']?.toString(), - hashOptions: map['hashOptions'], - registration: map['registration'].toString(), - status: map['status'], - labels: map['labels'] ?? [], - passwordUpdate: map['passwordUpdate'].toString(), - email: map['email'].toString(), - phone: map['phone'].toString(), - emailVerification: map['emailVerification'], - phoneVerification: map['phoneVerification'], - mfa: map['mfa'], - prefs: Preferences.fromMap(map['prefs']), - targets: List.from(map['targets'].map((p) => Target.fromMap(p))), - accessedAt: map['accessedAt'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "password": password, - "hash": hash, - "hashOptions": hashOptions, - "registration": registration, - "status": status, - "labels": labels, - "passwordUpdate": passwordUpdate, - "email": email, - "phone": phone, - "emailVerification": emailVerification, - "phoneVerification": phoneVerification, - "mfa": mfa, - "prefs": prefs.toMap(), - "targets": targets.map((p) => p.toMap()).toList(), - "accessedAt": accessedAt, - }; - } + /// User ID. + final String $id; + /// User creation date in ISO 8601 format. + final String $createdAt; + /// User update date in ISO 8601 format. + final String $updatedAt; + /// User name. + final String name; + /// Hashed user password. + final String? password; + /// Password hashing algorithm. + final String? hash; + /// Password hashing algorithm configuration. + final Map? hashOptions; + /// User registration date in ISO 8601 format. + final String registration; + /// User status. Pass `true` for enabled and `false` for disabled. + final bool status; + /// Labels for the user. + final List labels; + /// Password update time in ISO 8601 format. + final String passwordUpdate; + /// User email address. + final String email; + /// User phone number in E.164 format. + final String phone; + /// Email verification status. + final bool emailVerification; + /// Phone verification status. + final bool phoneVerification; + /// Multi factor authentication status. + final bool mfa; + /// User preferences as a key-value object + final Preferences prefs; + /// A user-owned message receiver. A single user may have multiple e.g. emails, phones, and a browser. Each target is registered with a single provider. + final List targets; + /// Most recent access date in ISO 8601 format. This attribute is only updated again after 24 hours. + final String accessedAt; + + User({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + this.password, + this.hash, + this.hashOptions, + required this.registration, + required this.status, + required this.labels, + required this.passwordUpdate, + required this.email, + required this.phone, + required this.emailVerification, + required this.phoneVerification, + required this.mfa, + required this.prefs, + required this.targets, + required this.accessedAt, + }); + + factory User.fromMap(Map map) { + return User( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + password: map['password']?.toString(), + hash: map['hash']?.toString(), + hashOptions: map['hashOptions'], + registration: map['registration'].toString(), + status: map['status'], + labels: map['labels'] ?? [], + passwordUpdate: map['passwordUpdate'].toString(), + email: map['email'].toString(), + phone: map['phone'].toString(), + emailVerification: map['emailVerification'], + phoneVerification: map['phoneVerification'], + mfa: map['mfa'], + prefs: Preferences.fromMap(map['prefs']), + targets: List.from(map['targets'].map((p) => Target.fromMap(p))), + accessedAt: map['accessedAt'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "password": password, + "hash": hash, + "hashOptions": hashOptions, + "registration": registration, + "status": status, + "labels": labels, + "passwordUpdate": passwordUpdate, + "email": email, + "phone": phone, + "emailVerification": emailVerification, + "phoneVerification": phoneVerification, + "mfa": mfa, + "prefs": prefs.toMap(), + "targets": targets.map((p) => p.toMap()).toList(), + "accessedAt": accessedAt, + }; + } } diff --git a/lib/src/models/user_list.dart b/lib/src/models/user_list.dart index c6d26cfe..92d926b0 100644 --- a/lib/src/models/user_list.dart +++ b/lib/src/models/user_list.dart @@ -2,30 +2,28 @@ part of '../../models.dart'; /// Users List class UserList implements Model { - /// Total number of users documents that matched your query. - final int total; + /// Total number of users documents that matched your query. + final int total; + /// List of users. + final List users; - /// List of users. - final List users; + UserList({ + required this.total, + required this.users, + }); - UserList({ - required this.total, - required this.users, - }); + factory UserList.fromMap(Map map) { + return UserList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + users: List.from(map['users'].map((p) => User.fromMap(p))), + ); + } - factory UserList.fromMap(Map map) { - return UserList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - users: List.from(map['users'].map((p) => User.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "users": users.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "users": users.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/variable.dart b/lib/src/models/variable.dart index a233010a..83526877 100644 --- a/lib/src/models/variable.dart +++ b/lib/src/models/variable.dart @@ -2,58 +2,52 @@ part of '../../models.dart'; /// Variable class Variable implements Model { - /// Variable ID. - final String $id; - - /// Variable creation date in ISO 8601 format. - final String $createdAt; - - /// Variable creation date in ISO 8601 format. - final String $updatedAt; - - /// Variable key. - final String key; - - /// Variable value. - final String value; - - /// Service to which the variable belongs. Possible values are "project", "function" - final String resourceType; - - /// ID of resource to which the variable belongs. If resourceType is "project", it is empty. If resourceType is "function", it is ID of the function. - final String resourceId; - - Variable({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.key, - required this.value, - required this.resourceType, - required this.resourceId, - }); - - factory Variable.fromMap(Map map) { - return Variable( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - key: map['key'].toString(), - value: map['value'].toString(), - resourceType: map['resourceType'].toString(), - resourceId: map['resourceId'].toString(), - ); - } - - Map toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "key": key, - "value": value, - "resourceType": resourceType, - "resourceId": resourceId, - }; - } + /// Variable ID. + final String $id; + /// Variable creation date in ISO 8601 format. + final String $createdAt; + /// Variable creation date in ISO 8601 format. + final String $updatedAt; + /// Variable key. + final String key; + /// Variable value. + final String value; + /// Service to which the variable belongs. Possible values are "project", "function" + final String resourceType; + /// ID of resource to which the variable belongs. If resourceType is "project", it is empty. If resourceType is "function", it is ID of the function. + final String resourceId; + + Variable({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.key, + required this.value, + required this.resourceType, + required this.resourceId, + }); + + factory Variable.fromMap(Map map) { + return Variable( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + key: map['key'].toString(), + value: map['value'].toString(), + resourceType: map['resourceType'].toString(), + resourceId: map['resourceId'].toString(), + ); + } + + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "key": key, + "value": value, + "resourceType": resourceType, + "resourceId": resourceId, + }; + } } diff --git a/lib/src/models/variable_list.dart b/lib/src/models/variable_list.dart index 07f2b2c4..6883a928 100644 --- a/lib/src/models/variable_list.dart +++ b/lib/src/models/variable_list.dart @@ -2,31 +2,28 @@ part of '../../models.dart'; /// Variables List class VariableList implements Model { - /// Total number of variables documents that matched your query. - final int total; + /// Total number of variables documents that matched your query. + final int total; + /// List of variables. + final List variables; - /// List of variables. - final List variables; + VariableList({ + required this.total, + required this.variables, + }); - VariableList({ - required this.total, - required this.variables, - }); + factory VariableList.fromMap(Map map) { + return VariableList( + total: (map['total'] is String) ? + int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + variables: List.from(map['variables'].map((p) => Variable.fromMap(p))), + ); + } - factory VariableList.fromMap(Map map) { - return VariableList( - total: (map['total'] is String) - ? int.tryParse(map['total']) ?? 0 - : map['total'] ?? 0, - variables: - List.from(map['variables'].map((p) => Variable.fromMap(p))), - ); - } - - Map toMap() { - return { - "total": total, - "variables": variables.map((p) => p.toMap()).toList(), - }; - } + Map toMap() { + return { + "total": total, + "variables": variables.map((p) => p.toMap()).toList(), + }; + } } diff --git a/pubspec.yaml b/pubspec.yaml index 67617bac..62da2c85 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: dart_appwrite -version: 13.0.0-rc1 +version: 13.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-dart diff --git a/test/services/functions_test.dart b/test/services/functions_test.dart index 3eccc76a..2cfbbf95 100644 --- a/test/services/functions_test.dart +++ b/test/services/functions_test.dart @@ -487,7 +487,7 @@ void main() { 'requestPath': '/articles?id=5', 'requestHeaders': [], 'responseStatusCode': 200, - 'responseBody': 'Developers are awesome.', + 'responseBody': , 'responseHeaders': [], 'logs': '', 'errors': '', @@ -523,7 +523,7 @@ void main() { 'requestPath': '/articles?id=5', 'requestHeaders': [], 'responseStatusCode': 200, - 'responseBody': 'Developers are awesome.', + 'responseBody': , 'responseHeaders': [], 'logs': '', 'errors': '', diff --git a/test/src/models/execution_test.dart b/test/src/models/execution_test.dart index fcb244a8..e0468292 100644 --- a/test/src/models/execution_test.dart +++ b/test/src/models/execution_test.dart @@ -17,7 +17,7 @@ void main() { requestPath: '/articles?id=5', requestHeaders: [], responseStatusCode: 200, - responseBody: 'Developers are awesome.', + responseBody: , responseHeaders: [], logs: '', errors: '', @@ -38,7 +38,7 @@ void main() { expect(result.requestPath, '/articles?id=5'); expect(result.requestHeaders, []); expect(result.responseStatusCode, 200); - expect(result.responseBody, 'Developers are awesome.'); + expect(result.responseBody, ); expect(result.responseHeaders, []); expect(result.logs, ''); expect(result.errors, ''); From adf2a25fcf4721b2414384a269761dae82b39cd7 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 8 Oct 2024 16:22:29 +0100 Subject: [PATCH 4/7] feat: multipart --- lib/src/enums/image_format.dart | 3 +- lib/src/models/attribute_boolean.dart | 10 ++++ lib/src/models/attribute_datetime.dart | 10 ++++ lib/src/models/attribute_email.dart | 10 ++++ lib/src/models/attribute_enum.dart | 10 ++++ lib/src/models/attribute_float.dart | 10 ++++ lib/src/models/attribute_integer.dart | 10 ++++ lib/src/models/attribute_ip.dart | 10 ++++ lib/src/models/attribute_relationship.dart | 10 ++++ lib/src/models/attribute_string.dart | 10 ++++ lib/src/models/attribute_url.dart | 10 ++++ lib/src/models/index.dart | 10 ++++ test/services/databases_test.dart | 60 ++++++++++++++++--- test/src/models/attribute_boolean_test.dart | 4 ++ test/src/models/attribute_datetime_test.dart | 4 ++ test/src/models/attribute_email_test.dart | 4 ++ test/src/models/attribute_enum_test.dart | 4 ++ test/src/models/attribute_float_test.dart | 4 ++ test/src/models/attribute_integer_test.dart | 4 ++ test/src/models/attribute_ip_test.dart | 4 ++ .../models/attribute_relationship_test.dart | 4 ++ test/src/models/attribute_string_test.dart | 4 ++ test/src/models/attribute_url_test.dart | 4 ++ test/src/models/index_test.dart | 4 ++ 24 files changed, 208 insertions(+), 9 deletions(-) diff --git a/lib/src/enums/image_format.dart b/lib/src/enums/image_format.dart index 66527dfa..cff37f49 100644 --- a/lib/src/enums/image_format.dart +++ b/lib/src/enums/image_format.dart @@ -5,7 +5,8 @@ enum ImageFormat { jpeg(value: 'jpeg'), gif(value: 'gif'), png(value: 'png'), - webp(value: 'webp'); + webp(value: 'webp'), + avif(value: 'avif'); const ImageFormat({ required this.value diff --git a/lib/src/models/attribute_boolean.dart b/lib/src/models/attribute_boolean.dart index 480c2042..453f3332 100644 --- a/lib/src/models/attribute_boolean.dart +++ b/lib/src/models/attribute_boolean.dart @@ -14,6 +14,10 @@ class AttributeBoolean implements Model { final bool xrequired; /// Is attribute an array? final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; /// Default value for attribute when not provided. Cannot be set when attribute is required. final bool? xdefault; @@ -24,6 +28,8 @@ class AttributeBoolean implements Model { required this.error, required this.xrequired, this.array, + required this.$createdAt, + required this.$updatedAt, this.xdefault, }); @@ -35,6 +41,8 @@ class AttributeBoolean implements Model { error: map['error'].toString(), xrequired: map['required'], array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), xdefault: map['default'], ); } @@ -47,6 +55,8 @@ class AttributeBoolean implements Model { "error": error, "required": xrequired, "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, "default": xdefault, }; } diff --git a/lib/src/models/attribute_datetime.dart b/lib/src/models/attribute_datetime.dart index 078a0723..bf35fcda 100644 --- a/lib/src/models/attribute_datetime.dart +++ b/lib/src/models/attribute_datetime.dart @@ -14,6 +14,10 @@ class AttributeDatetime implements Model { final bool xrequired; /// Is attribute an array? final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; /// ISO 8601 format. final String format; /// Default value for attribute when not provided. Only null is optional @@ -26,6 +30,8 @@ class AttributeDatetime implements Model { required this.error, required this.xrequired, this.array, + required this.$createdAt, + required this.$updatedAt, required this.format, this.xdefault, }); @@ -38,6 +44,8 @@ class AttributeDatetime implements Model { error: map['error'].toString(), xrequired: map['required'], array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), format: map['format'].toString(), xdefault: map['default']?.toString(), ); @@ -51,6 +59,8 @@ class AttributeDatetime implements Model { "error": error, "required": xrequired, "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, "format": format, "default": xdefault, }; diff --git a/lib/src/models/attribute_email.dart b/lib/src/models/attribute_email.dart index 08a67934..041ca68f 100644 --- a/lib/src/models/attribute_email.dart +++ b/lib/src/models/attribute_email.dart @@ -14,6 +14,10 @@ class AttributeEmail implements Model { final bool xrequired; /// Is attribute an array? final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; /// String format. final String format; /// Default value for attribute when not provided. Cannot be set when attribute is required. @@ -26,6 +30,8 @@ class AttributeEmail implements Model { required this.error, required this.xrequired, this.array, + required this.$createdAt, + required this.$updatedAt, required this.format, this.xdefault, }); @@ -38,6 +44,8 @@ class AttributeEmail implements Model { error: map['error'].toString(), xrequired: map['required'], array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), format: map['format'].toString(), xdefault: map['default']?.toString(), ); @@ -51,6 +59,8 @@ class AttributeEmail implements Model { "error": error, "required": xrequired, "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, "format": format, "default": xdefault, }; diff --git a/lib/src/models/attribute_enum.dart b/lib/src/models/attribute_enum.dart index d461ecf4..0e407e3d 100644 --- a/lib/src/models/attribute_enum.dart +++ b/lib/src/models/attribute_enum.dart @@ -14,6 +14,10 @@ class AttributeEnum implements Model { final bool xrequired; /// Is attribute an array? final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; /// Array of elements in enumerated type. final List elements; /// String format. @@ -28,6 +32,8 @@ class AttributeEnum implements Model { required this.error, required this.xrequired, this.array, + required this.$createdAt, + required this.$updatedAt, required this.elements, required this.format, this.xdefault, @@ -41,6 +47,8 @@ class AttributeEnum implements Model { error: map['error'].toString(), xrequired: map['required'], array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), elements: map['elements'] ?? [], format: map['format'].toString(), xdefault: map['default']?.toString(), @@ -55,6 +63,8 @@ class AttributeEnum implements Model { "error": error, "required": xrequired, "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, "elements": elements, "format": format, "default": xdefault, diff --git a/lib/src/models/attribute_float.dart b/lib/src/models/attribute_float.dart index 6d085aa4..f109bf3c 100644 --- a/lib/src/models/attribute_float.dart +++ b/lib/src/models/attribute_float.dart @@ -14,6 +14,10 @@ class AttributeFloat implements Model { final bool xrequired; /// Is attribute an array? final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; /// Minimum value to enforce for new documents. final double? min; /// Maximum value to enforce for new documents. @@ -28,6 +32,8 @@ class AttributeFloat implements Model { required this.error, required this.xrequired, this.array, + required this.$createdAt, + required this.$updatedAt, this.min, this.max, this.xdefault, @@ -41,6 +47,8 @@ class AttributeFloat implements Model { error: map['error'].toString(), xrequired: map['required'], array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), min: map['min']?.toDouble(), max: map['max']?.toDouble(), xdefault: map['default']?.toDouble(), @@ -55,6 +63,8 @@ class AttributeFloat implements Model { "error": error, "required": xrequired, "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, "min": min, "max": max, "default": xdefault, diff --git a/lib/src/models/attribute_integer.dart b/lib/src/models/attribute_integer.dart index 83e36858..eff96e7d 100644 --- a/lib/src/models/attribute_integer.dart +++ b/lib/src/models/attribute_integer.dart @@ -14,6 +14,10 @@ class AttributeInteger implements Model { final bool xrequired; /// Is attribute an array? final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; /// Minimum value to enforce for new documents. final int? min; /// Maximum value to enforce for new documents. @@ -28,6 +32,8 @@ class AttributeInteger implements Model { required this.error, required this.xrequired, this.array, + required this.$createdAt, + required this.$updatedAt, this.min, this.max, this.xdefault, @@ -41,6 +47,8 @@ class AttributeInteger implements Model { error: map['error'].toString(), xrequired: map['required'], array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), min: (map['min'] is String) ? int.tryParse(map['min']):map['min'], max: (map['max'] is String) ? @@ -58,6 +66,8 @@ class AttributeInteger implements Model { "error": error, "required": xrequired, "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, "min": min, "max": max, "default": xdefault, diff --git a/lib/src/models/attribute_ip.dart b/lib/src/models/attribute_ip.dart index 960f7064..cc2a0499 100644 --- a/lib/src/models/attribute_ip.dart +++ b/lib/src/models/attribute_ip.dart @@ -14,6 +14,10 @@ class AttributeIp implements Model { final bool xrequired; /// Is attribute an array? final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; /// String format. final String format; /// Default value for attribute when not provided. Cannot be set when attribute is required. @@ -26,6 +30,8 @@ class AttributeIp implements Model { required this.error, required this.xrequired, this.array, + required this.$createdAt, + required this.$updatedAt, required this.format, this.xdefault, }); @@ -38,6 +44,8 @@ class AttributeIp implements Model { error: map['error'].toString(), xrequired: map['required'], array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), format: map['format'].toString(), xdefault: map['default']?.toString(), ); @@ -51,6 +59,8 @@ class AttributeIp implements Model { "error": error, "required": xrequired, "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, "format": format, "default": xdefault, }; diff --git a/lib/src/models/attribute_relationship.dart b/lib/src/models/attribute_relationship.dart index d22c30d4..4b129c6e 100644 --- a/lib/src/models/attribute_relationship.dart +++ b/lib/src/models/attribute_relationship.dart @@ -14,6 +14,10 @@ class AttributeRelationship implements Model { final bool xrequired; /// Is attribute an array? final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; /// The ID of the related collection. final String relatedCollection; /// The type of the relationship. @@ -34,6 +38,8 @@ class AttributeRelationship implements Model { required this.error, required this.xrequired, this.array, + required this.$createdAt, + required this.$updatedAt, required this.relatedCollection, required this.relationType, required this.twoWay, @@ -50,6 +56,8 @@ class AttributeRelationship implements Model { error: map['error'].toString(), xrequired: map['required'], array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), relatedCollection: map['relatedCollection'].toString(), relationType: map['relationType'].toString(), twoWay: map['twoWay'], @@ -67,6 +75,8 @@ class AttributeRelationship implements Model { "error": error, "required": xrequired, "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, "relatedCollection": relatedCollection, "relationType": relationType, "twoWay": twoWay, diff --git a/lib/src/models/attribute_string.dart b/lib/src/models/attribute_string.dart index c483317c..974d0b4a 100644 --- a/lib/src/models/attribute_string.dart +++ b/lib/src/models/attribute_string.dart @@ -14,6 +14,10 @@ class AttributeString implements Model { final bool xrequired; /// Is attribute an array? final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; /// Attribute size. final int size; /// Default value for attribute when not provided. Cannot be set when attribute is required. @@ -26,6 +30,8 @@ class AttributeString implements Model { required this.error, required this.xrequired, this.array, + required this.$createdAt, + required this.$updatedAt, required this.size, this.xdefault, }); @@ -38,6 +44,8 @@ class AttributeString implements Model { error: map['error'].toString(), xrequired: map['required'], array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), size: (map['size'] is String) ? int.tryParse(map['size']) ?? 0:map['size'] ?? 0, xdefault: map['default']?.toString(), @@ -52,6 +60,8 @@ class AttributeString implements Model { "error": error, "required": xrequired, "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, "size": size, "default": xdefault, }; diff --git a/lib/src/models/attribute_url.dart b/lib/src/models/attribute_url.dart index 691cfcf6..aaac9202 100644 --- a/lib/src/models/attribute_url.dart +++ b/lib/src/models/attribute_url.dart @@ -14,6 +14,10 @@ class AttributeUrl implements Model { final bool xrequired; /// Is attribute an array? final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; /// String format. final String format; /// Default value for attribute when not provided. Cannot be set when attribute is required. @@ -26,6 +30,8 @@ class AttributeUrl implements Model { required this.error, required this.xrequired, this.array, + required this.$createdAt, + required this.$updatedAt, required this.format, this.xdefault, }); @@ -38,6 +44,8 @@ class AttributeUrl implements Model { error: map['error'].toString(), xrequired: map['required'], array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), format: map['format'].toString(), xdefault: map['default']?.toString(), ); @@ -51,6 +59,8 @@ class AttributeUrl implements Model { "error": error, "required": xrequired, "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, "format": format, "default": xdefault, }; diff --git a/lib/src/models/index.dart b/lib/src/models/index.dart index 9a4a1f9f..1dfa7921 100644 --- a/lib/src/models/index.dart +++ b/lib/src/models/index.dart @@ -14,6 +14,10 @@ class Index implements Model { final List attributes; /// Index orders. final List? orders; + /// Index creation date in ISO 8601 format. + final String $createdAt; + /// Index update date in ISO 8601 format. + final String $updatedAt; Index({ required this.key, @@ -22,6 +26,8 @@ class Index implements Model { required this.error, required this.attributes, this.orders, + required this.$createdAt, + required this.$updatedAt, }); factory Index.fromMap(Map map) { @@ -32,6 +38,8 @@ class Index implements Model { error: map['error'].toString(), attributes: map['attributes'] ?? [], orders: map['orders'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), ); } @@ -43,6 +51,8 @@ class Index implements Model { "error": error, "attributes": attributes, "orders": orders, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, }; } } diff --git a/test/services/databases_test.dart b/test/services/databases_test.dart index 94369bce..2bbe5170 100644 --- a/test/services/databases_test.dart +++ b/test/services/databases_test.dart @@ -289,7 +289,9 @@ void main() { 'type': 'boolean', 'status': 'available', 'error': 'string', - 'required': true,}; + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; when(client.call( @@ -313,7 +315,9 @@ void main() { 'type': 'boolean', 'status': 'available', 'error': 'string', - 'required': true,}; + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; when(client.call( @@ -339,6 +343,8 @@ void main() { 'status': 'available', 'error': 'string', 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'format': 'datetime',}; @@ -364,6 +370,8 @@ void main() { 'status': 'available', 'error': 'string', 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'format': 'datetime',}; @@ -390,6 +398,8 @@ void main() { 'status': 'available', 'error': 'string', 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'format': 'email',}; @@ -415,6 +425,8 @@ void main() { 'status': 'available', 'error': 'string', 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'format': 'email',}; @@ -441,6 +453,8 @@ void main() { 'status': 'available', 'error': 'string', 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'elements': [], 'format': 'enum',}; @@ -468,6 +482,8 @@ void main() { 'status': 'available', 'error': 'string', 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'elements': [], 'format': 'enum',}; @@ -495,7 +511,9 @@ void main() { 'type': 'double', 'status': 'available', 'error': 'string', - 'required': true,}; + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; when(client.call( @@ -519,7 +537,9 @@ void main() { 'type': 'double', 'status': 'available', 'error': 'string', - 'required': true,}; + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; when(client.call( @@ -546,7 +566,9 @@ void main() { 'type': 'integer', 'status': 'available', 'error': 'string', - 'required': true,}; + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; when(client.call( @@ -570,7 +592,9 @@ void main() { 'type': 'integer', 'status': 'available', 'error': 'string', - 'required': true,}; + 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; when(client.call( @@ -598,6 +622,8 @@ void main() { 'status': 'available', 'error': 'string', 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'format': 'ip',}; @@ -623,6 +649,8 @@ void main() { 'status': 'available', 'error': 'string', 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'format': 'ip',}; @@ -649,6 +677,8 @@ void main() { 'status': 'available', 'error': 'string', 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'relatedCollection': 'collection', 'relationType': 'oneToOne|oneToMany|manyToOne|manyToMany', 'twoWay': true, @@ -679,6 +709,8 @@ void main() { 'status': 'available', 'error': 'string', 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'size': 128,}; @@ -705,6 +737,8 @@ void main() { 'status': 'available', 'error': 'string', 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'size': 128,}; @@ -731,6 +765,8 @@ void main() { 'status': 'available', 'error': 'string', 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'format': 'url',}; @@ -756,6 +792,8 @@ void main() { 'status': 'available', 'error': 'string', 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'format': 'url',}; @@ -812,6 +850,8 @@ void main() { 'status': 'available', 'error': 'string', 'required': true, + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', 'relatedCollection': 'collection', 'relationType': 'oneToOne|oneToMany|manyToOne|manyToMany', 'twoWay': true, @@ -966,7 +1006,9 @@ void main() { 'type': 'primary', 'status': 'available', 'error': 'string', - 'attributes': [],}; + 'attributes': [], + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; when(client.call( @@ -991,7 +1033,9 @@ void main() { 'type': 'primary', 'status': 'available', 'error': 'string', - 'attributes': [],}; + 'attributes': [], + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00',}; when(client.call( diff --git a/test/src/models/attribute_boolean_test.dart b/test/src/models/attribute_boolean_test.dart index 3b9abbad..58c7a3c1 100644 --- a/test/src/models/attribute_boolean_test.dart +++ b/test/src/models/attribute_boolean_test.dart @@ -11,6 +11,8 @@ void main() { status: 'available', error: 'string', xrequired: true, + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', ); final map = model.toMap(); @@ -21,6 +23,8 @@ void main() { expect(result.status, 'available'); expect(result.error, 'string'); expect(result.xrequired, true); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); }); }); } diff --git a/test/src/models/attribute_datetime_test.dart b/test/src/models/attribute_datetime_test.dart index 609b9eb6..c5e91ad7 100644 --- a/test/src/models/attribute_datetime_test.dart +++ b/test/src/models/attribute_datetime_test.dart @@ -11,6 +11,8 @@ void main() { status: 'available', error: 'string', xrequired: true, + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', format: 'datetime', ); @@ -22,6 +24,8 @@ void main() { expect(result.status, 'available'); expect(result.error, 'string'); expect(result.xrequired, true); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); expect(result.format, 'datetime'); }); }); diff --git a/test/src/models/attribute_email_test.dart b/test/src/models/attribute_email_test.dart index a02c858a..b13a4f56 100644 --- a/test/src/models/attribute_email_test.dart +++ b/test/src/models/attribute_email_test.dart @@ -11,6 +11,8 @@ void main() { status: 'available', error: 'string', xrequired: true, + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', format: 'email', ); @@ -22,6 +24,8 @@ void main() { expect(result.status, 'available'); expect(result.error, 'string'); expect(result.xrequired, true); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); expect(result.format, 'email'); }); }); diff --git a/test/src/models/attribute_enum_test.dart b/test/src/models/attribute_enum_test.dart index ff30d9e6..b7952fb6 100644 --- a/test/src/models/attribute_enum_test.dart +++ b/test/src/models/attribute_enum_test.dart @@ -11,6 +11,8 @@ void main() { status: 'available', error: 'string', xrequired: true, + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', elements: [], format: 'enum', ); @@ -23,6 +25,8 @@ void main() { expect(result.status, 'available'); expect(result.error, 'string'); expect(result.xrequired, true); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); expect(result.elements, []); expect(result.format, 'enum'); }); diff --git a/test/src/models/attribute_float_test.dart b/test/src/models/attribute_float_test.dart index dfb7b648..359784b7 100644 --- a/test/src/models/attribute_float_test.dart +++ b/test/src/models/attribute_float_test.dart @@ -11,6 +11,8 @@ void main() { status: 'available', error: 'string', xrequired: true, + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', ); final map = model.toMap(); @@ -21,6 +23,8 @@ void main() { expect(result.status, 'available'); expect(result.error, 'string'); expect(result.xrequired, true); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); }); }); } diff --git a/test/src/models/attribute_integer_test.dart b/test/src/models/attribute_integer_test.dart index 0970a7f7..4ccb94f0 100644 --- a/test/src/models/attribute_integer_test.dart +++ b/test/src/models/attribute_integer_test.dart @@ -11,6 +11,8 @@ void main() { status: 'available', error: 'string', xrequired: true, + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', ); final map = model.toMap(); @@ -21,6 +23,8 @@ void main() { expect(result.status, 'available'); expect(result.error, 'string'); expect(result.xrequired, true); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); }); }); } diff --git a/test/src/models/attribute_ip_test.dart b/test/src/models/attribute_ip_test.dart index 307985df..42a23d9f 100644 --- a/test/src/models/attribute_ip_test.dart +++ b/test/src/models/attribute_ip_test.dart @@ -11,6 +11,8 @@ void main() { status: 'available', error: 'string', xrequired: true, + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', format: 'ip', ); @@ -22,6 +24,8 @@ void main() { expect(result.status, 'available'); expect(result.error, 'string'); expect(result.xrequired, true); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); expect(result.format, 'ip'); }); }); diff --git a/test/src/models/attribute_relationship_test.dart b/test/src/models/attribute_relationship_test.dart index e31a3286..1a75dbdd 100644 --- a/test/src/models/attribute_relationship_test.dart +++ b/test/src/models/attribute_relationship_test.dart @@ -11,6 +11,8 @@ void main() { status: 'available', error: 'string', xrequired: true, + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', relatedCollection: 'collection', relationType: 'oneToOne|oneToMany|manyToOne|manyToMany', twoWay: true, @@ -27,6 +29,8 @@ void main() { expect(result.status, 'available'); expect(result.error, 'string'); expect(result.xrequired, true); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); expect(result.relatedCollection, 'collection'); expect(result.relationType, 'oneToOne|oneToMany|manyToOne|manyToMany'); expect(result.twoWay, true); diff --git a/test/src/models/attribute_string_test.dart b/test/src/models/attribute_string_test.dart index 5934243a..ca1008ac 100644 --- a/test/src/models/attribute_string_test.dart +++ b/test/src/models/attribute_string_test.dart @@ -11,6 +11,8 @@ void main() { status: 'available', error: 'string', xrequired: true, + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', size: 128, ); @@ -22,6 +24,8 @@ void main() { expect(result.status, 'available'); expect(result.error, 'string'); expect(result.xrequired, true); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); expect(result.size, 128); }); }); diff --git a/test/src/models/attribute_url_test.dart b/test/src/models/attribute_url_test.dart index 39e6e709..3ef3e40a 100644 --- a/test/src/models/attribute_url_test.dart +++ b/test/src/models/attribute_url_test.dart @@ -11,6 +11,8 @@ void main() { status: 'available', error: 'string', xrequired: true, + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', format: 'url', ); @@ -22,6 +24,8 @@ void main() { expect(result.status, 'available'); expect(result.error, 'string'); expect(result.xrequired, true); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); expect(result.format, 'url'); }); }); diff --git a/test/src/models/index_test.dart b/test/src/models/index_test.dart index 2db0ef12..8c45dee4 100644 --- a/test/src/models/index_test.dart +++ b/test/src/models/index_test.dart @@ -11,6 +11,8 @@ void main() { status: 'available', error: 'string', attributes: [], + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', ); final map = model.toMap(); @@ -21,6 +23,8 @@ void main() { expect(result.status, 'available'); expect(result.error, 'string'); expect(result.attributes, []); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); }); }); } From 52db482387eb16f6b2fda69ae8e16c0cedd12611 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 11 Dec 2024 00:36:24 +1300 Subject: [PATCH 5/7] Add new push message parameters --- README.md | 2 +- .../databases/update-string-attribute.md | 2 +- docs/examples/functions/create-deployment.md | 2 +- docs/examples/functions/create-execution.md | 2 +- docs/examples/messaging/create-push.md | 9 +- docs/examples/messaging/update-push.md | 3 + docs/examples/storage/create-file.md | 2 +- lib/dart_appwrite.dart | 4 +- lib/enums.dart | 1 + lib/models.dart | 2 - lib/payload.dart | 84 ----------- lib/services/account.dart | 4 +- lib/services/functions.dart | 6 +- lib/services/messaging.dart | 10 +- lib/services/storage.dart | 2 +- lib/services/teams.dart | 6 +- lib/src/client_browser.dart | 16 +-- lib/src/client_io.dart | 24 ++-- lib/src/client_mixin.dart | 132 +----------------- lib/src/client_stub.dart | 2 +- lib/src/enums/credit_card.dart | 4 +- lib/src/enums/execution_method.dart | 12 +- lib/src/enums/message_priority.dart | 14 ++ lib/src/enums/runtime.dart | 14 +- lib/src/input_file.dart | 48 +++++++ lib/src/models/algo_argon2.dart | 9 +- lib/src/models/algo_scrypt.dart | 12 +- lib/src/models/attribute_enum.dart | 2 +- lib/src/models/attribute_integer.dart | 9 +- lib/src/models/attribute_list.dart | 3 +- lib/src/models/attribute_string.dart | 3 +- lib/src/models/bucket.dart | 7 +- lib/src/models/bucket_list.dart | 3 +- lib/src/models/build.dart | 6 +- lib/src/models/collection.dart | 2 +- lib/src/models/collection_list.dart | 3 +- lib/src/models/continent_list.dart | 3 +- lib/src/models/country_list.dart | 3 +- lib/src/models/currency.dart | 3 +- lib/src/models/currency_list.dart | 3 +- lib/src/models/database_list.dart | 3 +- lib/src/models/deployment.dart | 9 +- lib/src/models/deployment_list.dart | 3 +- lib/src/models/document.dart | 2 +- lib/src/models/document_list.dart | 3 +- lib/src/models/execution.dart | 9 +- lib/src/models/execution_list.dart | 3 +- lib/src/models/file.dart | 11 +- lib/src/models/file_list.dart | 3 +- lib/src/models/function.dart | 11 +- lib/src/models/function_list.dart | 3 +- lib/src/models/health_queue.dart | 3 +- lib/src/models/health_status.dart | 3 +- lib/src/models/health_time.dart | 9 +- lib/src/models/identity_list.dart | 3 +- lib/src/models/index.dart | 4 +- lib/src/models/index_list.dart | 3 +- lib/src/models/language_list.dart | 3 +- lib/src/models/locale_code_list.dart | 3 +- lib/src/models/log_list.dart | 3 +- lib/src/models/membership.dart | 8 +- lib/src/models/membership_list.dart | 3 +- lib/src/models/message.dart | 11 +- lib/src/models/message_list.dart | 3 +- lib/src/models/mfa_recovery_codes.dart | 2 +- lib/src/models/phone_list.dart | 3 +- lib/src/models/provider_list.dart | 3 +- lib/src/models/runtime.dart | 2 +- lib/src/models/runtime_list.dart | 3 +- lib/src/models/session.dart | 2 +- lib/src/models/session_list.dart | 3 +- lib/src/models/specification.dart | 3 +- lib/src/models/specification_list.dart | 3 +- lib/src/models/subscriber_list.dart | 3 +- lib/src/models/target.dart | 5 + lib/src/models/target_list.dart | 3 +- lib/src/models/team.dart | 3 +- lib/src/models/team_list.dart | 3 +- lib/src/models/topic.dart | 11 +- lib/src/models/topic_list.dart | 3 +- lib/src/models/user.dart | 2 +- lib/src/models/user_list.dart | 3 +- lib/src/models/variable_list.dart | 3 +- pubspec.yaml | 7 +- test/services/functions_test.dart | 22 ++- test/services/messaging_test.dart | 2 - test/services/storage_test.dart | 2 +- test/services/users_test.dart | 15 +- test/src/input_file_test.dart | 47 +++++++ test/src/models/execution_test.dart | 4 +- test/src/models/function_test.dart | 4 +- test/src/models/specification_test.dart | 4 +- test/src/models/target_test.dart | 6 +- test/src/payload_test.dart | 23 --- 94 files changed, 314 insertions(+), 482 deletions(-) delete mode 100644 lib/payload.dart create mode 100644 lib/src/enums/message_priority.dart create mode 100644 lib/src/input_file.dart create mode 100644 test/src/input_file_test.dart delete mode 100644 test/src/payload_test.dart diff --git a/README.md b/README.md index c1ab7d9f..117a0265 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Add this to your package's `pubspec.yaml` file: ```yml dependencies: - dart_appwrite: ^13.0.0 + dart_appwrite: ^12.2.0 ``` You can install packages from the command line: diff --git a/docs/examples/databases/update-string-attribute.md b/docs/examples/databases/update-string-attribute.md index c2f3804c..f9498aa3 100644 --- a/docs/examples/databases/update-string-attribute.md +++ b/docs/examples/databases/update-string-attribute.md @@ -13,6 +13,6 @@ AttributeString result = await databases.updateStringAttribute( key: '', xrequired: false, xdefault: '', - size: 0, // (optional) + size: 1, // (optional) newKey: '', // (optional) ); diff --git a/docs/examples/functions/create-deployment.md b/docs/examples/functions/create-deployment.md index 80f14165..297bdc61 100644 --- a/docs/examples/functions/create-deployment.md +++ b/docs/examples/functions/create-deployment.md @@ -10,7 +10,7 @@ Functions functions = Functions(client); Deployment result = await functions.createDeployment( functionId: '', - code: Payload.fromFile(path: '/path/to/file.png'), + code: InputFile(path: './path-to-files/image.jpg', filename: 'image.jpg'), activate: false, entrypoint: '', // (optional) commands: '', // (optional) diff --git a/docs/examples/functions/create-execution.md b/docs/examples/functions/create-execution.md index 3246f98d..2bf146e2 100644 --- a/docs/examples/functions/create-execution.md +++ b/docs/examples/functions/create-execution.md @@ -9,7 +9,7 @@ Functions functions = Functions(client); Execution result = await functions.createExecution( functionId: '', - body: Payload.fromJson({ 'x': 'y' }), // (optional) + body: '', // (optional) xasync: false, // (optional) path: '', // (optional) method: ExecutionMethod.gET, // (optional) diff --git a/docs/examples/messaging/create-push.md b/docs/examples/messaging/create-push.md index c3c7d2ff..e496de9d 100644 --- a/docs/examples/messaging/create-push.md +++ b/docs/examples/messaging/create-push.md @@ -9,8 +9,8 @@ Messaging messaging = Messaging(client); Message result = await messaging.createPush( messageId: '', - title: '', - body: '<BODY>', + title: '<TITLE>', // (optional) + body: '<BODY>', // (optional) topics: [], // (optional) users: [], // (optional) targets: [], // (optional) @@ -21,7 +21,10 @@ Message result = await messaging.createPush( sound: '<SOUND>', // (optional) color: '<COLOR>', // (optional) tag: '<TAG>', // (optional) - badge: '<BADGE>', // (optional) + badge: 0, // (optional) draft: false, // (optional) scheduledAt: '', // (optional) + contentAvailable: false, // (optional) + critical: false, // (optional) + priority: MessagePriority.normal, // (optional) ); diff --git a/docs/examples/messaging/update-push.md b/docs/examples/messaging/update-push.md index dcec9b24..f5d75332 100644 --- a/docs/examples/messaging/update-push.md +++ b/docs/examples/messaging/update-push.md @@ -24,4 +24,7 @@ Message result = await messaging.updatePush( badge: 0, // (optional) draft: false, // (optional) scheduledAt: '', // (optional) + contentAvailable: false, // (optional) + critical: false, // (optional) + priority: MessagePriority.normal, // (optional) ); diff --git a/docs/examples/storage/create-file.md b/docs/examples/storage/create-file.md index 0378a5c8..0e06f422 100644 --- a/docs/examples/storage/create-file.md +++ b/docs/examples/storage/create-file.md @@ -11,6 +11,6 @@ Storage storage = Storage(client); File result = await storage.createFile( bucketId: '<BUCKET_ID>', fileId: '<FILE_ID>', - file: Payload.fromFile(path: '/path/to/file.png'), + file: InputFile(path: './path-to-files/image.jpg', filename: 'image.jpg'), permissions: ["read("any")"], // (optional) ); diff --git a/lib/dart_appwrite.dart b/lib/dart_appwrite.dart index 659eb962..21865e2e 100644 --- a/lib/dart_appwrite.dart +++ b/lib/dart_appwrite.dart @@ -12,16 +12,16 @@ import 'dart:convert'; import 'src/enums.dart'; import 'src/service.dart'; +import 'src/input_file.dart'; import 'src/upload_progress.dart'; import 'models.dart' as models; import 'enums.dart' as enums; -import 'payload.dart'; export 'src/response.dart'; export 'src/client.dart'; export 'src/exception.dart'; +export 'src/input_file.dart'; export 'src/upload_progress.dart'; -export 'payload.dart'; part 'query.dart'; part 'permission.dart'; diff --git a/lib/enums.dart b/lib/enums.dart index 1e858220..313d70c2 100644 --- a/lib/enums.dart +++ b/lib/enums.dart @@ -13,6 +13,7 @@ part 'src/enums/index_type.dart'; part 'src/enums/runtime.dart'; part 'src/enums/execution_method.dart'; part 'src/enums/name.dart'; +part 'src/enums/message_priority.dart'; part 'src/enums/smtp_encryption.dart'; part 'src/enums/compression.dart'; part 'src/enums/image_gravity.dart'; diff --git a/lib/models.dart b/lib/models.dart index 7338435e..98fd7d19 100644 --- a/lib/models.dart +++ b/lib/models.dart @@ -1,8 +1,6 @@ /// Appwrite Models library dart_appwrite.models; -import 'payload.dart'; - part 'src/models/model.dart'; part 'src/models/document_list.dart'; part 'src/models/collection_list.dart'; diff --git a/lib/payload.dart b/lib/payload.dart deleted file mode 100644 index 7afcd2a8..00000000 --- a/lib/payload.dart +++ /dev/null @@ -1,84 +0,0 @@ -import 'dart:convert'; -import 'src/exception.dart'; -import 'dart:io'; - -class Payload { - late final String? path; - late final List<int>? data; - final String? filename; - - Payload._({this.path, this.filename, this.data}) { - if (path == null && data == null) { - throw AppwriteException('One of `path` or `data` is required'); - } - } - - /// Convert to binary, with optional offset and length - List<int> toBinary({int offset = 0, int? length}) { - if(data == null) { - throw AppwriteException('`data` is not defined.'); - } - if(offset == 0 && length == null) { - return data!; - } else if (length == null) { - return data!.sublist(offset); - } else { - return data!.sublist(offset, offset + length); - } - } - - /// Convert binary data to string (utf8) - @override - String toString() { - if(data == null) { - return ''; - } - return utf8.decode(data!); - } - - /// Convert binary data to JSON object - Map<String, dynamic> toJson() { - try { - return jsonDecode(toString()); // Decode the string to JSON - } catch (e) { - throw FormatException('Failed to parse JSON: ${e.toString()}'); - } - } - - /// Create a file from the payload - void toFile(String path) { - if(data == null) { - throw AppwriteException('`data` is not defined.'); - } - final file = File(path); - file.writeAsBytesSync(data!); - } - - /// Create a Payload from binary data - factory Payload.fromBinary({ - required List<int> data, - String? filename, - }) { - return Payload._(data: data, filename: filename); - } - - /// Create a Payload from a file - factory Payload.fromFile({required String path, String? filename}) { - return Payload._(path: path, filename: filename); - } - - /// Create a Payload from a JSON object - factory Payload.fromJson({ - required Map<String, dynamic> data, - String? filename, - }) { - final jsonString = jsonEncode(data); - return Payload.fromString(string: jsonString, filename: filename); - } - - /// Create a Payload from a string - factory Payload.fromString({required String string, String? filename}) { - final data = utf8.encode(string); - return Payload._(data: data, filename: filename); - } -} diff --git a/lib/services/account.dart b/lib/services/account.dart index a6e5d6a6..d1e830e5 100644 --- a/lib/services/account.dart +++ b/lib/services/account.dart @@ -941,9 +941,7 @@ class Account extends Service { /// [POST /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) /// endpoint to complete the login process. The link sent to the user's email - /// address is valid for 1 hour. If you are on a mobile device you can leave - /// the URL parameter empty, so that the login completion will be handled by - /// your Appwrite instance by default. + /// address is valid for 1 hour. /// /// A user is limited to 10 active sessions at a time by default. [Learn more /// about session diff --git a/lib/services/functions.dart b/lib/services/functions.dart index 2bc323e9..374fd507 100644 --- a/lib/services/functions.dart +++ b/lib/services/functions.dart @@ -242,7 +242,7 @@ class Functions extends Service { /// tutorial](https://appwrite.io/docs/functions). /// /// Use the "command" param to set the entrypoint used to execute your code. - Future<models.Deployment> createDeployment({required String functionId, required Payload code, required bool activate, String? entrypoint, String? commands, Function(UploadProgress)? onProgress}) async { + Future<models.Deployment> createDeployment({required String functionId, required InputFile code, required bool activate, String? entrypoint, String? commands, Function(UploadProgress)? onProgress}) async { final String apiPath = '/functions/{functionId}/deployments'.replaceAll('{functionId}', functionId); final Map<String, dynamic> apiParams = { @@ -434,7 +434,7 @@ class Functions extends Service { /// current execution status. You can ping the `Get Execution` endpoint to get /// updates on the current execution status. Once this endpoint is called, your /// function execution process will start asynchronously. - Future<models.Execution> createExecution({required String functionId, Payload? body, bool? xasync, String? path, enums.ExecutionMethod? method, Map? headers, String? scheduledAt, Function(UploadProgress)? onProgress}) async { + Future<models.Execution> createExecution({required String functionId, String? body, bool? xasync, String? path, enums.ExecutionMethod? method, Map? headers, String? scheduledAt}) async { final String apiPath = '/functions/{functionId}/executions'.replaceAll('{functionId}', functionId); final Map<String, dynamic> apiParams = { @@ -449,7 +449,7 @@ class Functions extends Service { }; final Map<String, String> apiHeaders = { - 'content-type': 'multipart/form-data', + 'content-type': 'application/json', }; diff --git a/lib/services/messaging.dart b/lib/services/messaging.dart index e88b18f5..c138f93c 100644 --- a/lib/services/messaging.dart +++ b/lib/services/messaging.dart @@ -100,7 +100,7 @@ class Messaging extends Service { /// Create push notification /// /// Create a new push notification. - Future<models.Message> createPush({required String messageId, required String title, required String body, List<String>? topics, List<String>? users, List<String>? targets, Map? data, String? action, String? image, String? icon, String? sound, String? color, String? tag, String? badge, bool? draft, String? scheduledAt}) async { + Future<models.Message> createPush({required String messageId, String? title, String? body, List<String>? topics, List<String>? users, List<String>? targets, Map? data, String? action, String? image, String? icon, String? sound, String? color, String? tag, int? badge, bool? draft, String? scheduledAt, bool? contentAvailable, bool? critical, enums.MessagePriority? priority}) async { final String apiPath = '/messaging/messages/push'; final Map<String, dynamic> apiParams = { @@ -121,6 +121,9 @@ class Messaging extends Service { 'badge': badge, 'draft': draft, 'scheduledAt': scheduledAt, +'contentAvailable': contentAvailable, +'critical': critical, +'priority': priority?.value, }; @@ -139,7 +142,7 @@ class Messaging extends Service { /// /// Update a push notification by its unique ID. /// - Future<models.Message> updatePush({required String messageId, List<String>? topics, List<String>? users, List<String>? targets, String? title, String? body, Map? data, String? action, String? image, String? icon, String? sound, String? color, String? tag, int? badge, bool? draft, String? scheduledAt}) async { + Future<models.Message> updatePush({required String messageId, List<String>? topics, List<String>? users, List<String>? targets, String? title, String? body, Map? data, String? action, String? image, String? icon, String? sound, String? color, String? tag, int? badge, bool? draft, String? scheduledAt, bool? contentAvailable, bool? critical, enums.MessagePriority? priority}) async { final String apiPath = '/messaging/messages/push/{messageId}'.replaceAll('{messageId}', messageId); final Map<String, dynamic> apiParams = { @@ -159,6 +162,9 @@ class Messaging extends Service { 'badge': badge, 'draft': draft, 'scheduledAt': scheduledAt, +'contentAvailable': contentAvailable, +'critical': critical, +'priority': priority?.value, }; diff --git a/lib/services/storage.dart b/lib/services/storage.dart index 1b2048e0..a6f987bc 100644 --- a/lib/services/storage.dart +++ b/lib/services/storage.dart @@ -182,7 +182,7 @@ class Storage extends Service { /// 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<models.File> createFile({required String bucketId, required String fileId, required Payload file, List<String>? permissions, Function(UploadProgress)? onProgress}) async { + Future<models.File> createFile({required String bucketId, required String fileId, required InputFile file, List<String>? permissions, Function(UploadProgress)? onProgress}) async { final String apiPath = '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); final Map<String, dynamic> apiParams = { diff --git a/lib/services/teams.dart b/lib/services/teams.dart index 4d7ee475..699608fb 100644 --- a/lib/services/teams.dart +++ b/lib/services/teams.dart @@ -128,7 +128,8 @@ class Teams extends Service { /// List 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. + /// members have read access to this endpoint. Hide sensitive attributes from + /// the response by toggling membership privacy in the Console. Future<models.MembershipList> listMemberships({required String teamId, List<String>? queries, String? search}) async { final String apiPath = '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); @@ -201,7 +202,8 @@ class Teams extends Service { /// Get team membership /// /// Get a team member by the membership unique id. All team members have read - /// access for this resource. + /// access for this resource. Hide sensitive attributes from the response by + /// toggling membership privacy in the Console. Future<models.Membership> getMembership({required String teamId, required String membershipId}) async { final String apiPath = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); diff --git a/lib/src/client_browser.dart b/lib/src/client_browser.dart index c7789db2..009a8454 100644 --- a/lib/src/client_browser.dart +++ b/lib/src/client_browser.dart @@ -6,7 +6,7 @@ import 'enums.dart'; import 'exception.dart'; import 'client_base.dart'; import 'response.dart'; -import '../payload.dart'; +import 'input_file.dart'; import 'upload_progress.dart'; ClientBase createClient({ @@ -33,7 +33,7 @@ class ClientBrowser extends ClientBase with ClientMixin { 'x-sdk-name': 'Dart', 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', - 'x-sdk-version': '13.0.0', + 'x-sdk-version': '12.2.0', 'X-Appwrite-Response-Format' : '1.6.0', }; @@ -122,16 +122,16 @@ class ClientBrowser extends ClientBase with ClientMixin { required Map<String, String> headers, Function(UploadProgress)? onProgress, }) async { - Payload file = params[paramName]; - if (file.data == null) { - throw AppwriteException("File data must be provided for Flutter web"); + InputFile file = params[paramName]; + if (file.bytes == null) { + throw AppwriteException("File bytes must be provided for Flutter web"); } - int size = file.data!.length; + int size = file.bytes!.length; late Response res; if (size <= CHUNK_SIZE) { - params[paramName] = http.MultipartFile.fromBytes(paramName, file.data!, filename: file.filename); + params[paramName] = http.MultipartFile.fromBytes(paramName, file.bytes!, filename: file.filename); return call( HttpMethod.post, path: path, @@ -157,7 +157,7 @@ class ClientBrowser extends ClientBase with ClientMixin { while (offset < size) { List<int> chunk = []; final end = min(offset + CHUNK_SIZE, size); - chunk = file.toBinary(length: offset, length: min(CHUNK_SIZE, size - offset)); + chunk = file.bytes!.getRange(offset, end).toList(); params[paramName] = http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename); headers['content-range'] = diff --git a/lib/src/client_io.dart b/lib/src/client_io.dart index e841fdda..41ee49b6 100644 --- a/lib/src/client_io.dart +++ b/lib/src/client_io.dart @@ -2,13 +2,12 @@ import 'dart:io'; import 'dart:math'; import 'package:http/http.dart' as http; import 'package:http/io_client.dart'; - import 'client_mixin.dart'; import 'client_base.dart'; import 'enums.dart'; import 'exception.dart'; import 'response.dart'; -import '../payload.dart'; +import 'input_file.dart'; import 'upload_progress.dart'; ClientBase createClient({ @@ -43,8 +42,8 @@ class ClientIO extends ClientBase with ClientMixin { 'x-sdk-name': 'Dart', 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', - 'x-sdk-version': '13.0.0', - 'user-agent' : 'AppwriteDartSDK/13.0.0 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', + 'x-sdk-version': '12.2.0', + 'user-agent' : 'AppwriteDartSDK/12.2.0 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', 'X-Appwrite-Response-Format' : '1.6.0', }; @@ -127,14 +126,14 @@ class ClientIO extends ClientBase with ClientMixin { required Map<String, String> headers, Function(UploadProgress)? onProgress, }) async { - Payload file = params[paramName]; - if (file.path == null && file.data == null) { - throw AppwriteException("File path or data must be provided"); + InputFile file = params[paramName]; + if (file.path == null && file.bytes == null) { + throw AppwriteException("File path or bytes must be provided"); } int size = 0; - if (file.data != null) { - size = file.data!.length; + if (file.bytes != null) { + size = file.bytes!.length; } File? iofile; @@ -151,7 +150,7 @@ class ClientIO extends ClientBase with ClientMixin { paramName, file.path!, filename: file.filename); } else { - params[paramName] = http.MultipartFile.fromBytes(paramName, file.data!, + params[paramName] = http.MultipartFile.fromBytes(paramName, file.bytes!, filename: file.filename); } return call( @@ -184,8 +183,9 @@ class ClientIO extends ClientBase with ClientMixin { while (offset < size) { List<int> chunk = []; - if (file.data != null) { - chunk = file.toBinary(offset: offset, length: min(CHUNK_SIZE, size - offset)); + if (file.bytes != null) { + final end = min(offset + CHUNK_SIZE, size); + chunk = file.bytes!.getRange(offset, end).toList(); } else { raf!.setPositionSync(offset); chunk = raf.readSync(CHUNK_SIZE); diff --git a/lib/src/client_mixin.dart b/lib/src/client_mixin.dart index f7dd73a7..36bcdbd3 100644 --- a/lib/src/client_mixin.dart +++ b/lib/src/client_mixin.dart @@ -1,21 +1,11 @@ import 'package:http/http.dart' as http; -import 'package:http_parser/http_parser.dart'; -import 'package:mime/mime.dart'; -import 'package:string_scanner/string_scanner.dart'; - import 'exception.dart'; import 'response.dart'; import 'dart:convert'; import 'dart:developer'; import 'enums.dart'; -import '../payload.dart'; - -mixin ClientMixin { - final _token = RegExp(r'[^()<>@,;:"\\/[\]?={} \t\x00-\x1F\x7F]+'); - final _whitespace = RegExp(r'(?:(?:\r\n)?[ \t]+)*'); - final _quotedString = RegExp(r'"(?:[^"\x00-\x1F\x7F]|\\.)*"'); - final _quotedPair = RegExp(r'\\(.)'); +class ClientMixin { http.BaseRequest prepareRequest( HttpMethod method, { required Uri uri, @@ -76,7 +66,7 @@ mixin ClientMixin { return request; } - Future<Response> prepareResponse(http.Response res, {ResponseType? responseType}) async { + Response prepareResponse(http.Response res, {ResponseType? responseType}) { responseType ??= ResponseType.json; String? warnings = res.headers['x-appwrite-warning']; @@ -106,9 +96,6 @@ mixin ClientMixin { } else { data = res.body; } - } else if((res.headers['content-type'] ?? '').contains('multipart/form-data')) { - data = await _parseMultipart(res.headers['content-type']!, Stream.value(res.bodyBytes)); - return Response(data: data); } else { if (responseType == ResponseType.bytes) { data = res.bodyBytes; @@ -133,119 +120,4 @@ mixin ClientMixin { return await http.Response.fromStream(streamedResponse); } } - - Future<List<int>> _decodeMimeMultipart(MimeMultipart part) async { - List<int> result = []; - - await for (var chunk in part) { - result.addAll(chunk); - } - - return result; - } - - /// Parse multipart forma data - Future<Map<String, dynamic>> _parseMultipart( - String header, Stream<List<int>> body) async { - final data = await _parts(header, body) - .map<_FormData?>((part) { - final rawDisposition = part.headers['content-disposition']; - if (rawDisposition == null) return null; - - final formDataParams = - _parseFormDataContentDisposition(rawDisposition); - if (formDataParams == null) return null; - - final name = formDataParams['name']; - if (name == null) return null; - - final filename = formDataParams['filename']; - dynamic value; - if (name == 'responseBody') { - return _FormData._(name, filename, part); - } else if (filename != null) { - value = { - "file": part, - "filename": filename, - "mimeType": part.headers['Content-Type'], - }; - } else { - value = utf8.decodeStream(part); - } - return _FormData._(name, filename, value); - }) - .where((data) => data != null) - .toList(); - final Map<String, dynamic> out = {}; - for (final item in data) { - if (item!.name == 'responseBody') { - out[item.name] = - Payload.fromBinary(data: await _decodeMimeMultipart(item.value), filename: item.filename); - } else { - out[item.name] = await item.value; - } - } - return out; - } - - Stream<MimeMultipart> _parts(String header, Stream<List<int>> body) { - final boundary = _extractBoundary(header); - if (boundary == null) { - throw Exception('Not a multipart request'); - } - return MimeMultipartTransformer(boundary).bind(body!); - } - - String? _extractBoundary(String header) { - final contentType = MediaType.parse(header); - if (contentType.type != 'multipart') return null; - - return contentType.parameters['boundary']; - } - - /// Parses a `content-disposition: form-data; arg1="val1"; ...` header. - Map<String, String>? _parseFormDataContentDisposition(String header) { - final scanner = StringScanner(header); - - scanner - ..scan(_whitespace) - ..expect(_token); - if (scanner.lastMatch![0] != 'form-data') return null; - - final params = <String, String>{}; - - while (scanner.scan(';')) { - scanner - ..scan(_whitespace) - ..scan(_token); - final key = scanner.lastMatch![0]!; - scanner.expect('='); - - String value; - if (scanner.scan(_token)) { - value = scanner.lastMatch![0]!; - } else { - scanner.expect(_quotedString, name: 'quoted string'); - final string = scanner.lastMatch![0]!; - - value = string - .substring(1, string.length - 1) - .replaceAllMapped(_quotedPair, (match) => match[1]!); - } - - scanner.scan(_whitespace); - params[key] = value; - } - - scanner.expectDone(); - return params; - } } - -class _FormData { - final String name; - final dynamic value; - final String? filename; - - _FormData._(this.name, this.filename, this.value); -} \ No newline at end of file diff --git a/lib/src/client_stub.dart b/lib/src/client_stub.dart index 40423b49..95e9d217 100644 --- a/lib/src/client_stub.dart +++ b/lib/src/client_stub.dart @@ -1,6 +1,6 @@ import 'client_base.dart'; -/// Implemented in `client_browser.dart` and `client_io.dart`. +/// Implemented in `browser_client.dart` and `io_client.dart`. ClientBase createClient({required String endPoint, required bool selfSigned}) => throw UnsupportedError( 'Cannot create a client without dart:html or dart:io.'); diff --git a/lib/src/enums/credit_card.dart b/lib/src/enums/credit_card.dart index 878db2f0..7d54fa80 100644 --- a/lib/src/enums/credit_card.dart +++ b/lib/src/enums/credit_card.dart @@ -9,13 +9,13 @@ enum CreditCard { discover(value: 'discover'), elo(value: 'elo'), hipercard(value: 'hipercard'), - jcb(value: 'jcb'), + jCB(value: 'jcb'), mastercard(value: 'mastercard'), naranja(value: 'naranja'), tarjetaShopping(value: 'targeta-shopping'), unionChinaPay(value: 'union-china-pay'), visa(value: 'visa'), - mir(value: 'mir'), + mIR(value: 'mir'), maestro(value: 'maestro'); const CreditCard({ diff --git a/lib/src/enums/execution_method.dart b/lib/src/enums/execution_method.dart index d6f43cf0..7d2d7016 100644 --- a/lib/src/enums/execution_method.dart +++ b/lib/src/enums/execution_method.dart @@ -1,12 +1,12 @@ part of '../../enums.dart'; enum ExecutionMethod { - get(value: 'GET'), - post(value: 'POST'), - put(value: 'PUT'), - patch(value: 'PATCH'), - delete(value: 'DELETE'), - options(value: 'OPTIONS'); + gET(value: 'GET'), + pOST(value: 'POST'), + pUT(value: 'PUT'), + pATCH(value: 'PATCH'), + dELETE(value: 'DELETE'), + oPTIONS(value: 'OPTIONS'); const ExecutionMethod({ required this.value diff --git a/lib/src/enums/message_priority.dart b/lib/src/enums/message_priority.dart new file mode 100644 index 00000000..375913e8 --- /dev/null +++ b/lib/src/enums/message_priority.dart @@ -0,0 +1,14 @@ +part of '../../enums.dart'; + +enum MessagePriority { + normal(value: 'normal'), + high(value: 'high'); + + const MessagePriority({ + required this.value + }); + + final String value; + + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/runtime.dart b/lib/src/enums/runtime.dart index 6a0aec49..b7dbd129 100644 --- a/lib/src/enums/runtime.dart +++ b/lib/src/enums/runtime.dart @@ -7,6 +7,7 @@ enum Runtime { node190(value: 'node-19.0'), node200(value: 'node-20.0'), node210(value: 'node-21.0'), + node22(value: 'node-22'), php80(value: 'php-8.0'), php81(value: 'php-8.1'), php82(value: 'php-8.2'), @@ -25,6 +26,8 @@ enum Runtime { deno124(value: 'deno-1.24'), deno135(value: 'deno-1.35'), deno140(value: 'deno-1.40'), + deno146(value: 'deno-1.46'), + deno20(value: 'deno-2.0'), dart215(value: 'dart-2.15'), dart216(value: 'dart-2.16'), dart217(value: 'dart-2.17'), @@ -32,24 +35,31 @@ enum Runtime { dart30(value: 'dart-3.0'), dart31(value: 'dart-3.1'), dart33(value: 'dart-3.3'), - dotnet31(value: 'dotnet-3.1'), + dart35(value: 'dart-3.5'), dotnet60(value: 'dotnet-6.0'), dotnet70(value: 'dotnet-7.0'), + dotnet80(value: 'dotnet-8.0'), java80(value: 'java-8.0'), java110(value: 'java-11.0'), java170(value: 'java-17.0'), java180(value: 'java-18.0'), java210(value: 'java-21.0'), + java22(value: 'java-22'), swift55(value: 'swift-5.5'), swift58(value: 'swift-5.8'), swift59(value: 'swift-5.9'), + swift510(value: 'swift-5.10'), kotlin16(value: 'kotlin-1.6'), kotlin18(value: 'kotlin-1.8'), kotlin19(value: 'kotlin-1.9'), + kotlin20(value: 'kotlin-2.0'), cpp17(value: 'cpp-17'), cpp20(value: 'cpp-20'), bun10(value: 'bun-1.0'), - go123(value: 'go-1.23'); + bun11(value: 'bun-1.1'), + go123(value: 'go-1.23'), + static1(value: 'static-1'), + flutter324(value: 'flutter-3.24'); const Runtime({ required this.value diff --git a/lib/src/input_file.dart b/lib/src/input_file.dart new file mode 100644 index 00000000..c0be7c04 --- /dev/null +++ b/lib/src/input_file.dart @@ -0,0 +1,48 @@ +import 'exception.dart'; + +/// Helper class to handle files. +class InputFile { + late final String? path; + late final List<int>? bytes; + final String? filename; + final String? contentType; + + @Deprecated('Use `InputFile.fromPath` or `InputFile.fromBytes` instead.') + InputFile({this.path, this.filename, this.contentType, this.bytes}) { + if (path == null && bytes == null) { + throw AppwriteException('One of `path` or `bytes` is required'); + } + } + + InputFile._({this.path, this.filename, this.contentType, this.bytes}) { + if (path == null && bytes == null) { + throw AppwriteException('One of `path` or `bytes` is required'); + } + } + + /// Provide a file using `path` + factory InputFile.fromPath({ + required String path, + String? filename, + String? contentType, + }) { + return InputFile._( + path: path, + filename: filename, + contentType: contentType, + ); + } + + /// Provide a file using `bytes` + factory InputFile.fromBytes({ + required List<int> bytes, + required String filename, + String? contentType, + }) { + return InputFile._( + bytes: bytes, + filename: filename, + contentType: contentType, + ); + } +} diff --git a/lib/src/models/algo_argon2.dart b/lib/src/models/algo_argon2.dart index 92fa2593..759f320d 100644 --- a/lib/src/models/algo_argon2.dart +++ b/lib/src/models/algo_argon2.dart @@ -21,12 +21,9 @@ class AlgoArgon2 implements Model { factory AlgoArgon2.fromMap(Map<String, dynamic> map) { return AlgoArgon2( type: map['type'].toString(), - memoryCost: (map['memoryCost'] is String) ? - int.tryParse(map['memoryCost']) ?? 0:map['memoryCost'] ?? 0, - timeCost: (map['timeCost'] is String) ? - int.tryParse(map['timeCost']) ?? 0:map['timeCost'] ?? 0, - threads: (map['threads'] is String) ? - int.tryParse(map['threads']) ?? 0:map['threads'] ?? 0, + memoryCost: map['memoryCost'], + timeCost: map['timeCost'], + threads: map['threads'], ); } diff --git a/lib/src/models/algo_scrypt.dart b/lib/src/models/algo_scrypt.dart index c3e55453..5c36373d 100644 --- a/lib/src/models/algo_scrypt.dart +++ b/lib/src/models/algo_scrypt.dart @@ -24,14 +24,10 @@ class AlgoScrypt implements Model { factory AlgoScrypt.fromMap(Map<String, dynamic> map) { return AlgoScrypt( type: map['type'].toString(), - costCpu: (map['costCpu'] is String) ? - int.tryParse(map['costCpu']) ?? 0:map['costCpu'] ?? 0, - costMemory: (map['costMemory'] is String) ? - int.tryParse(map['costMemory']) ?? 0:map['costMemory'] ?? 0, - costParallel: (map['costParallel'] is String) ? - int.tryParse(map['costParallel']) ?? 0:map['costParallel'] ?? 0, - length: (map['length'] is String) ? - int.tryParse(map['length']) ?? 0:map['length'] ?? 0, + costCpu: map['costCpu'], + costMemory: map['costMemory'], + costParallel: map['costParallel'], + length: map['length'], ); } diff --git a/lib/src/models/attribute_enum.dart b/lib/src/models/attribute_enum.dart index 0e407e3d..3aeff75a 100644 --- a/lib/src/models/attribute_enum.dart +++ b/lib/src/models/attribute_enum.dart @@ -19,7 +19,7 @@ class AttributeEnum implements Model { /// Attribute update date in ISO 8601 format. final String $updatedAt; /// Array of elements in enumerated type. - final List elements; + final List<String> elements; /// String format. final String format; /// Default value for attribute when not provided. Cannot be set when attribute is required. diff --git a/lib/src/models/attribute_integer.dart b/lib/src/models/attribute_integer.dart index eff96e7d..add418c5 100644 --- a/lib/src/models/attribute_integer.dart +++ b/lib/src/models/attribute_integer.dart @@ -49,12 +49,9 @@ class AttributeInteger implements Model { array: map['array'], $createdAt: map['\$createdAt'].toString(), $updatedAt: map['\$updatedAt'].toString(), - min: (map['min'] is String) ? - int.tryParse(map['min']):map['min'], - max: (map['max'] is String) ? - int.tryParse(map['max']):map['max'], - xdefault: (map['default'] is String) ? - int.tryParse(map['default']):map['default'], + min: map['min'], + max: map['max'], + xdefault: map['default'], ); } diff --git a/lib/src/models/attribute_list.dart b/lib/src/models/attribute_list.dart index e15a0b35..b4a75722 100644 --- a/lib/src/models/attribute_list.dart +++ b/lib/src/models/attribute_list.dart @@ -14,8 +14,7 @@ class AttributeList implements Model { factory AttributeList.fromMap(Map<String, dynamic> map) { return AttributeList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], attributes: map['attributes'] ?? [], ); } diff --git a/lib/src/models/attribute_string.dart b/lib/src/models/attribute_string.dart index 974d0b4a..247708f0 100644 --- a/lib/src/models/attribute_string.dart +++ b/lib/src/models/attribute_string.dart @@ -46,8 +46,7 @@ class AttributeString implements Model { array: map['array'], $createdAt: map['\$createdAt'].toString(), $updatedAt: map['\$updatedAt'].toString(), - size: (map['size'] is String) ? - int.tryParse(map['size']) ?? 0:map['size'] ?? 0, + size: map['size'], xdefault: map['default']?.toString(), ); } diff --git a/lib/src/models/bucket.dart b/lib/src/models/bucket.dart index b72c0392..47279918 100644 --- a/lib/src/models/bucket.dart +++ b/lib/src/models/bucket.dart @@ -9,7 +9,7 @@ class Bucket implements Model { /// Bucket update date in ISO 8601 format. final String $updatedAt; /// Bucket permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List $permissions; + final List<String> $permissions; /// Whether file-level security is enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). final bool fileSecurity; /// Bucket name. @@ -19,7 +19,7 @@ class Bucket implements Model { /// Maximum file size supported. final int maximumFileSize; /// Allowed file extensions. - final List allowedFileExtensions; + final List<String> allowedFileExtensions; /// Compression algorithm choosen for compression. Will be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd). final String compression; /// Bucket is encrypted. @@ -51,8 +51,7 @@ class Bucket implements Model { fileSecurity: map['fileSecurity'], name: map['name'].toString(), enabled: map['enabled'], - maximumFileSize: (map['maximumFileSize'] is String) ? - int.tryParse(map['maximumFileSize']) ?? 0:map['maximumFileSize'] ?? 0, + maximumFileSize: map['maximumFileSize'], allowedFileExtensions: map['allowedFileExtensions'] ?? [], compression: map['compression'].toString(), encryption: map['encryption'], diff --git a/lib/src/models/bucket_list.dart b/lib/src/models/bucket_list.dart index 7687eb6e..3b24973f 100644 --- a/lib/src/models/bucket_list.dart +++ b/lib/src/models/bucket_list.dart @@ -14,8 +14,7 @@ class BucketList implements Model { factory BucketList.fromMap(Map<String, dynamic> map) { return BucketList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], buckets: List<Bucket>.from(map['buckets'].map((p) => Bucket.fromMap(p))), ); } diff --git a/lib/src/models/build.dart b/lib/src/models/build.dart index 4c12e283..64eb21ad 100644 --- a/lib/src/models/build.dart +++ b/lib/src/models/build.dart @@ -42,10 +42,8 @@ class Build implements Model { stderr: map['stderr'].toString(), startTime: map['startTime'].toString(), endTime: map['endTime'].toString(), - duration: (map['duration'] is String) ? - int.tryParse(map['duration']) ?? 0:map['duration'] ?? 0, - size: (map['size'] is String) ? - int.tryParse(map['size']) ?? 0:map['size'] ?? 0, + duration: map['duration'], + size: map['size'], ); } diff --git a/lib/src/models/collection.dart b/lib/src/models/collection.dart index d4649f55..7cd47f7d 100644 --- a/lib/src/models/collection.dart +++ b/lib/src/models/collection.dart @@ -9,7 +9,7 @@ class Collection implements Model { /// Collection update date in ISO 8601 format. final String $updatedAt; /// Collection permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List $permissions; + final List<String> $permissions; /// Database ID. final String databaseId; /// Collection name. diff --git a/lib/src/models/collection_list.dart b/lib/src/models/collection_list.dart index 732bbf89..a354146f 100644 --- a/lib/src/models/collection_list.dart +++ b/lib/src/models/collection_list.dart @@ -14,8 +14,7 @@ class CollectionList implements Model { factory CollectionList.fromMap(Map<String, dynamic> map) { return CollectionList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], collections: List<Collection>.from(map['collections'].map((p) => Collection.fromMap(p))), ); } diff --git a/lib/src/models/continent_list.dart b/lib/src/models/continent_list.dart index d6c60999..d0830aad 100644 --- a/lib/src/models/continent_list.dart +++ b/lib/src/models/continent_list.dart @@ -14,8 +14,7 @@ class ContinentList implements Model { factory ContinentList.fromMap(Map<String, dynamic> map) { return ContinentList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], continents: List<Continent>.from(map['continents'].map((p) => Continent.fromMap(p))), ); } diff --git a/lib/src/models/country_list.dart b/lib/src/models/country_list.dart index 996b6aff..7fa08533 100644 --- a/lib/src/models/country_list.dart +++ b/lib/src/models/country_list.dart @@ -14,8 +14,7 @@ class CountryList implements Model { factory CountryList.fromMap(Map<String, dynamic> map) { return CountryList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], countries: List<Country>.from(map['countries'].map((p) => Country.fromMap(p))), ); } diff --git a/lib/src/models/currency.dart b/lib/src/models/currency.dart index 1d0a3ed5..11aba951 100644 --- a/lib/src/models/currency.dart +++ b/lib/src/models/currency.dart @@ -32,8 +32,7 @@ class Currency implements Model { symbol: map['symbol'].toString(), name: map['name'].toString(), symbolNative: map['symbolNative'].toString(), - decimalDigits: (map['decimalDigits'] is String) ? - int.tryParse(map['decimalDigits']) ?? 0:map['decimalDigits'] ?? 0, + decimalDigits: map['decimalDigits'], rounding: map['rounding'].toDouble(), code: map['code'].toString(), namePlural: map['namePlural'].toString(), diff --git a/lib/src/models/currency_list.dart b/lib/src/models/currency_list.dart index c1cd94e1..cf925bc5 100644 --- a/lib/src/models/currency_list.dart +++ b/lib/src/models/currency_list.dart @@ -14,8 +14,7 @@ class CurrencyList implements Model { factory CurrencyList.fromMap(Map<String, dynamic> map) { return CurrencyList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], currencies: List<Currency>.from(map['currencies'].map((p) => Currency.fromMap(p))), ); } diff --git a/lib/src/models/database_list.dart b/lib/src/models/database_list.dart index 861b3c4f..ff79d8c9 100644 --- a/lib/src/models/database_list.dart +++ b/lib/src/models/database_list.dart @@ -14,8 +14,7 @@ class DatabaseList implements Model { factory DatabaseList.fromMap(Map<String, dynamic> map) { return DatabaseList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], databases: List<Database>.from(map['databases'].map((p) => Database.fromMap(p))), ); } diff --git a/lib/src/models/deployment.dart b/lib/src/models/deployment.dart index 1c066b55..67e67d6c 100644 --- a/lib/src/models/deployment.dart +++ b/lib/src/models/deployment.dart @@ -87,16 +87,13 @@ class Deployment implements Model { resourceId: map['resourceId'].toString(), resourceType: map['resourceType'].toString(), entrypoint: map['entrypoint'].toString(), - size: (map['size'] is String) ? - int.tryParse(map['size']) ?? 0:map['size'] ?? 0, - buildSize: (map['buildSize'] is String) ? - int.tryParse(map['buildSize']) ?? 0:map['buildSize'] ?? 0, + size: map['size'], + buildSize: map['buildSize'], buildId: map['buildId'].toString(), activate: map['activate'], status: map['status'].toString(), buildLogs: map['buildLogs'].toString(), - buildTime: (map['buildTime'] is String) ? - int.tryParse(map['buildTime']) ?? 0:map['buildTime'] ?? 0, + buildTime: map['buildTime'], providerRepositoryName: map['providerRepositoryName'].toString(), providerRepositoryOwner: map['providerRepositoryOwner'].toString(), providerRepositoryUrl: map['providerRepositoryUrl'].toString(), diff --git a/lib/src/models/deployment_list.dart b/lib/src/models/deployment_list.dart index ddc014f9..3eaa589e 100644 --- a/lib/src/models/deployment_list.dart +++ b/lib/src/models/deployment_list.dart @@ -14,8 +14,7 @@ class DeploymentList implements Model { factory DeploymentList.fromMap(Map<String, dynamic> map) { return DeploymentList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], deployments: List<Deployment>.from(map['deployments'].map((p) => Deployment.fromMap(p))), ); } diff --git a/lib/src/models/document.dart b/lib/src/models/document.dart index d5b8c77e..42721317 100644 --- a/lib/src/models/document.dart +++ b/lib/src/models/document.dart @@ -13,7 +13,7 @@ class Document implements Model { /// Document update date in ISO 8601 format. final String $updatedAt; /// Document permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List $permissions; + final List<String> $permissions; final Map<String, dynamic> data; Document({ diff --git a/lib/src/models/document_list.dart b/lib/src/models/document_list.dart index c418b48e..9d3de14b 100644 --- a/lib/src/models/document_list.dart +++ b/lib/src/models/document_list.dart @@ -14,8 +14,7 @@ class DocumentList implements Model { factory DocumentList.fromMap(Map<String, dynamic> map) { return DocumentList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], documents: List<Document>.from(map['documents'].map((p) => Document.fromMap(p))), ); } diff --git a/lib/src/models/execution.dart b/lib/src/models/execution.dart index b873ed91..9373a245 100644 --- a/lib/src/models/execution.dart +++ b/lib/src/models/execution.dart @@ -9,7 +9,7 @@ class Execution implements Model { /// Execution upate date in ISO 8601 format. final String $updatedAt; /// Execution roles. - final List $permissions; + final List<String> $permissions; /// Function ID. final String functionId; /// The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`. @@ -25,7 +25,7 @@ class Execution implements Model { /// HTTP response status code. final int responseStatusCode; /// HTTP response body. This will return empty unless execution is created as synchronous. - final Payload responseBody; + final String responseBody; /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. final List<Headers> responseHeaders; /// Function logs. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. @@ -69,9 +69,8 @@ class Execution implements Model { requestMethod: map['requestMethod'].toString(), requestPath: map['requestPath'].toString(), requestHeaders: List<Headers>.from(map['requestHeaders'].map((p) => Headers.fromMap(p))), - responseStatusCode: (map['responseStatusCode'] is String) ? - int.tryParse(map['responseStatusCode']) ?? 0:map['responseStatusCode'] ?? 0, - responseBody: map['responseBody'], + responseStatusCode: map['responseStatusCode'], + responseBody: map['responseBody'].toString(), responseHeaders: List<Headers>.from(map['responseHeaders'].map((p) => Headers.fromMap(p))), logs: map['logs'].toString(), errors: map['errors'].toString(), diff --git a/lib/src/models/execution_list.dart b/lib/src/models/execution_list.dart index ba66f150..00333204 100644 --- a/lib/src/models/execution_list.dart +++ b/lib/src/models/execution_list.dart @@ -14,8 +14,7 @@ class ExecutionList implements Model { factory ExecutionList.fromMap(Map<String, dynamic> map) { return ExecutionList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], executions: List<Execution>.from(map['executions'].map((p) => Execution.fromMap(p))), ); } diff --git a/lib/src/models/file.dart b/lib/src/models/file.dart index 34b9e6cf..2dac8960 100644 --- a/lib/src/models/file.dart +++ b/lib/src/models/file.dart @@ -11,7 +11,7 @@ class File implements Model { /// File update date in ISO 8601 format. final String $updatedAt; /// File permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List $permissions; + final List<String> $permissions; /// File name. final String name; /// File MD5 signature. @@ -49,12 +49,9 @@ class File implements Model { name: map['name'].toString(), signature: map['signature'].toString(), mimeType: map['mimeType'].toString(), - sizeOriginal: (map['sizeOriginal'] is String) ? - int.tryParse(map['sizeOriginal']) ?? 0:map['sizeOriginal'] ?? 0, - chunksTotal: (map['chunksTotal'] is String) ? - int.tryParse(map['chunksTotal']) ?? 0:map['chunksTotal'] ?? 0, - chunksUploaded: (map['chunksUploaded'] is String) ? - int.tryParse(map['chunksUploaded']) ?? 0:map['chunksUploaded'] ?? 0, + sizeOriginal: map['sizeOriginal'], + chunksTotal: map['chunksTotal'], + chunksUploaded: map['chunksUploaded'], ); } diff --git a/lib/src/models/file_list.dart b/lib/src/models/file_list.dart index cf7a0ced..b0872489 100644 --- a/lib/src/models/file_list.dart +++ b/lib/src/models/file_list.dart @@ -14,8 +14,7 @@ class FileList implements Model { factory FileList.fromMap(Map<String, dynamic> map) { return FileList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], files: List<File>.from(map['files'].map((p) => File.fromMap(p))), ); } diff --git a/lib/src/models/function.dart b/lib/src/models/function.dart index 870bd5df..bf8c22aa 100644 --- a/lib/src/models/function.dart +++ b/lib/src/models/function.dart @@ -9,7 +9,7 @@ class Func implements Model { /// Function update date in ISO 8601 format. final String $updatedAt; /// Execution permissions. - final List execute; + final List<String> execute; /// Function name. final String name; /// Function enabled. @@ -23,12 +23,12 @@ class Func implements Model { /// Function's active deployment ID. final String deployment; /// Allowed permission scopes. - final List scopes; + final List<String> scopes; /// Function variables. final List<Variable> vars; /// Function trigger events. - final List events; - /// Function execution schedult in CRON format. + final List<String> events; + /// Function execution schedule in CRON format. final String schedule; /// Function execution timeout in seconds. final int timeout; @@ -94,8 +94,7 @@ class Func implements Model { vars: List<Variable>.from(map['vars'].map((p) => Variable.fromMap(p))), events: map['events'] ?? [], schedule: map['schedule'].toString(), - timeout: (map['timeout'] is String) ? - int.tryParse(map['timeout']) ?? 0:map['timeout'] ?? 0, + timeout: map['timeout'], entrypoint: map['entrypoint'].toString(), commands: map['commands'].toString(), version: map['version'].toString(), diff --git a/lib/src/models/function_list.dart b/lib/src/models/function_list.dart index 712e459e..83a8f93b 100644 --- a/lib/src/models/function_list.dart +++ b/lib/src/models/function_list.dart @@ -14,8 +14,7 @@ class FunctionList implements Model { factory FunctionList.fromMap(Map<String, dynamic> map) { return FunctionList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], functions: List<Func>.from(map['functions'].map((p) => Func.fromMap(p))), ); } diff --git a/lib/src/models/health_queue.dart b/lib/src/models/health_queue.dart index 8267e5bc..95da1235 100644 --- a/lib/src/models/health_queue.dart +++ b/lib/src/models/health_queue.dart @@ -11,8 +11,7 @@ class HealthQueue implements Model { factory HealthQueue.fromMap(Map<String, dynamic> map) { return HealthQueue( - size: (map['size'] is String) ? - int.tryParse(map['size']) ?? 0:map['size'] ?? 0, + size: map['size'], ); } diff --git a/lib/src/models/health_status.dart b/lib/src/models/health_status.dart index dbbcfef8..57526c24 100644 --- a/lib/src/models/health_status.dart +++ b/lib/src/models/health_status.dart @@ -18,8 +18,7 @@ class HealthStatus implements Model { factory HealthStatus.fromMap(Map<String, dynamic> map) { return HealthStatus( name: map['name'].toString(), - ping: (map['ping'] is String) ? - int.tryParse(map['ping']) ?? 0:map['ping'] ?? 0, + ping: map['ping'], status: map['status'].toString(), ); } diff --git a/lib/src/models/health_time.dart b/lib/src/models/health_time.dart index 49b00a9d..0b8b4a35 100644 --- a/lib/src/models/health_time.dart +++ b/lib/src/models/health_time.dart @@ -17,12 +17,9 @@ class HealthTime implements Model { factory HealthTime.fromMap(Map<String, dynamic> map) { return HealthTime( - remoteTime: (map['remoteTime'] is String) ? - int.tryParse(map['remoteTime']) ?? 0:map['remoteTime'] ?? 0, - localTime: (map['localTime'] is String) ? - int.tryParse(map['localTime']) ?? 0:map['localTime'] ?? 0, - diff: (map['diff'] is String) ? - int.tryParse(map['diff']) ?? 0:map['diff'] ?? 0, + remoteTime: map['remoteTime'], + localTime: map['localTime'], + diff: map['diff'], ); } diff --git a/lib/src/models/identity_list.dart b/lib/src/models/identity_list.dart index 77b9d8c7..b38c9775 100644 --- a/lib/src/models/identity_list.dart +++ b/lib/src/models/identity_list.dart @@ -14,8 +14,7 @@ class IdentityList implements Model { factory IdentityList.fromMap(Map<String, dynamic> map) { return IdentityList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], identities: List<Identity>.from(map['identities'].map((p) => Identity.fromMap(p))), ); } diff --git a/lib/src/models/index.dart b/lib/src/models/index.dart index 1dfa7921..2f0353d5 100644 --- a/lib/src/models/index.dart +++ b/lib/src/models/index.dart @@ -11,9 +11,9 @@ class Index implements Model { /// Error message. Displays error generated on failure of creating or deleting an index. final String error; /// Index attributes. - final List attributes; + final List<String> attributes; /// Index orders. - final List? orders; + final List<String>? orders; /// Index creation date in ISO 8601 format. final String $createdAt; /// Index update date in ISO 8601 format. diff --git a/lib/src/models/index_list.dart b/lib/src/models/index_list.dart index dbf66137..32bd33e0 100644 --- a/lib/src/models/index_list.dart +++ b/lib/src/models/index_list.dart @@ -14,8 +14,7 @@ class IndexList implements Model { factory IndexList.fromMap(Map<String, dynamic> map) { return IndexList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], indexes: List<Index>.from(map['indexes'].map((p) => Index.fromMap(p))), ); } diff --git a/lib/src/models/language_list.dart b/lib/src/models/language_list.dart index fd4824fb..c6977a0e 100644 --- a/lib/src/models/language_list.dart +++ b/lib/src/models/language_list.dart @@ -14,8 +14,7 @@ class LanguageList implements Model { factory LanguageList.fromMap(Map<String, dynamic> map) { return LanguageList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], languages: List<Language>.from(map['languages'].map((p) => Language.fromMap(p))), ); } diff --git a/lib/src/models/locale_code_list.dart b/lib/src/models/locale_code_list.dart index 9ed7f657..090b332d 100644 --- a/lib/src/models/locale_code_list.dart +++ b/lib/src/models/locale_code_list.dart @@ -14,8 +14,7 @@ class LocaleCodeList implements Model { factory LocaleCodeList.fromMap(Map<String, dynamic> map) { return LocaleCodeList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], localeCodes: List<LocaleCode>.from(map['localeCodes'].map((p) => LocaleCode.fromMap(p))), ); } diff --git a/lib/src/models/log_list.dart b/lib/src/models/log_list.dart index c7d6000c..9af5b1cd 100644 --- a/lib/src/models/log_list.dart +++ b/lib/src/models/log_list.dart @@ -14,8 +14,7 @@ class LogList implements Model { factory LogList.fromMap(Map<String, dynamic> map) { return LogList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], logs: List<Log>.from(map['logs'].map((p) => Log.fromMap(p))), ); } diff --git a/lib/src/models/membership.dart b/lib/src/models/membership.dart index 283f4ee5..62c5b64b 100644 --- a/lib/src/models/membership.dart +++ b/lib/src/models/membership.dart @@ -10,9 +10,9 @@ class Membership implements Model { final String $updatedAt; /// User ID. final String userId; - /// User name. + /// User name. Hide this attribute by toggling membership privacy in the Console. final String userName; - /// User email address. + /// User email address. Hide this attribute by toggling membership privacy in the Console. final String userEmail; /// Team ID. final String teamId; @@ -24,10 +24,10 @@ class Membership implements Model { final String joined; /// User confirmation status, true if the user has joined the team or false otherwise. final bool confirm; - /// Multi factor authentication status, true if the user has MFA enabled or false otherwise. + /// Multi factor authentication status, true if the user has MFA enabled or false otherwise. Hide this attribute by toggling membership privacy in the Console. final bool mfa; /// User list of roles - final List roles; + final List<String> roles; Membership({ required this.$id, diff --git a/lib/src/models/membership_list.dart b/lib/src/models/membership_list.dart index f5302cbf..1da7cd60 100644 --- a/lib/src/models/membership_list.dart +++ b/lib/src/models/membership_list.dart @@ -14,8 +14,7 @@ class MembershipList implements Model { factory MembershipList.fromMap(Map<String, dynamic> map) { return MembershipList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], memberships: List<Membership>.from(map['memberships'].map((p) => Membership.fromMap(p))), ); } diff --git a/lib/src/models/message.dart b/lib/src/models/message.dart index 381ab216..fcf1cba4 100644 --- a/lib/src/models/message.dart +++ b/lib/src/models/message.dart @@ -11,17 +11,17 @@ class Message implements Model { /// Message provider type. final String providerType; /// Topic IDs set as recipients. - final List topics; + final List<String> topics; /// User IDs set as recipients. - final List users; + final List<String> users; /// Target IDs set as recipients. - final List targets; + final List<String> targets; /// The scheduled time for message. final String? scheduledAt; /// The time when the message was delivered. final String? deliveredAt; /// Delivery errors if any. - final List? deliveryErrors; + final List<String>? deliveryErrors; /// Number of recipients the message was delivered to. final int deliveredTotal; /// Data of the message. @@ -57,8 +57,7 @@ class Message implements Model { scheduledAt: map['scheduledAt']?.toString(), deliveredAt: map['deliveredAt']?.toString(), deliveryErrors: map['deliveryErrors'], - deliveredTotal: (map['deliveredTotal'] is String) ? - int.tryParse(map['deliveredTotal']) ?? 0:map['deliveredTotal'] ?? 0, + deliveredTotal: map['deliveredTotal'], data: map['data'], status: map['status'].toString(), ); diff --git a/lib/src/models/message_list.dart b/lib/src/models/message_list.dart index 220d3c52..79389744 100644 --- a/lib/src/models/message_list.dart +++ b/lib/src/models/message_list.dart @@ -14,8 +14,7 @@ class MessageList implements Model { factory MessageList.fromMap(Map<String, dynamic> map) { return MessageList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], messages: List<Message>.from(map['messages'].map((p) => Message.fromMap(p))), ); } diff --git a/lib/src/models/mfa_recovery_codes.dart b/lib/src/models/mfa_recovery_codes.dart index 68402443..cd835186 100644 --- a/lib/src/models/mfa_recovery_codes.dart +++ b/lib/src/models/mfa_recovery_codes.dart @@ -3,7 +3,7 @@ part of '../../models.dart'; /// MFA Recovery Codes class MfaRecoveryCodes implements Model { /// Recovery codes. - final List recoveryCodes; + final List<String> recoveryCodes; MfaRecoveryCodes({ required this.recoveryCodes, diff --git a/lib/src/models/phone_list.dart b/lib/src/models/phone_list.dart index f00a91d3..55e6108e 100644 --- a/lib/src/models/phone_list.dart +++ b/lib/src/models/phone_list.dart @@ -14,8 +14,7 @@ class PhoneList implements Model { factory PhoneList.fromMap(Map<String, dynamic> map) { return PhoneList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], phones: List<Phone>.from(map['phones'].map((p) => Phone.fromMap(p))), ); } diff --git a/lib/src/models/provider_list.dart b/lib/src/models/provider_list.dart index fe6d41d0..228578b7 100644 --- a/lib/src/models/provider_list.dart +++ b/lib/src/models/provider_list.dart @@ -14,8 +14,7 @@ class ProviderList implements Model { factory ProviderList.fromMap(Map<String, dynamic> map) { return ProviderList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], providers: List<Provider>.from(map['providers'].map((p) => Provider.fromMap(p))), ); } diff --git a/lib/src/models/runtime.dart b/lib/src/models/runtime.dart index acda5a4f..75f2ccca 100644 --- a/lib/src/models/runtime.dart +++ b/lib/src/models/runtime.dart @@ -17,7 +17,7 @@ class Runtime implements Model { /// Name of the logo image. final String logo; /// List of supported architectures. - final List supports; + final List<String> supports; Runtime({ required this.$id, diff --git a/lib/src/models/runtime_list.dart b/lib/src/models/runtime_list.dart index 8ee86986..4d7e33ce 100644 --- a/lib/src/models/runtime_list.dart +++ b/lib/src/models/runtime_list.dart @@ -14,8 +14,7 @@ class RuntimeList implements Model { factory RuntimeList.fromMap(Map<String, dynamic> map) { return RuntimeList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], runtimes: List<Runtime>.from(map['runtimes'].map((p) => Runtime.fromMap(p))), ); } diff --git a/lib/src/models/session.dart b/lib/src/models/session.dart index 10566f44..b67bf22f 100644 --- a/lib/src/models/session.dart +++ b/lib/src/models/session.dart @@ -55,7 +55,7 @@ class Session implements Model { /// Returns true if this the current user session. final bool current; /// Returns a list of active session factors. - final List factors; + final List<String> factors; /// Secret used to authenticate the user. Only included if the request was made with an API key final String secret; /// Most recent date in ISO 8601 format when the session successfully passed MFA challenge. diff --git a/lib/src/models/session_list.dart b/lib/src/models/session_list.dart index f17b963d..ee4841a2 100644 --- a/lib/src/models/session_list.dart +++ b/lib/src/models/session_list.dart @@ -14,8 +14,7 @@ class SessionList implements Model { factory SessionList.fromMap(Map<String, dynamic> map) { return SessionList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], sessions: List<Session>.from(map['sessions'].map((p) => Session.fromMap(p))), ); } diff --git a/lib/src/models/specification.dart b/lib/src/models/specification.dart index 97b359f2..49e4c597 100644 --- a/lib/src/models/specification.dart +++ b/lib/src/models/specification.dart @@ -20,8 +20,7 @@ class Specification implements Model { factory Specification.fromMap(Map<String, dynamic> map) { return Specification( - memory: (map['memory'] is String) ? - int.tryParse(map['memory']) ?? 0:map['memory'] ?? 0, + memory: map['memory'], cpus: map['cpus'].toDouble(), enabled: map['enabled'], slug: map['slug'].toString(), diff --git a/lib/src/models/specification_list.dart b/lib/src/models/specification_list.dart index 1b7d3a69..494fd398 100644 --- a/lib/src/models/specification_list.dart +++ b/lib/src/models/specification_list.dart @@ -14,8 +14,7 @@ class SpecificationList implements Model { factory SpecificationList.fromMap(Map<String, dynamic> map) { return SpecificationList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], specifications: List<Specification>.from(map['specifications'].map((p) => Specification.fromMap(p))), ); } diff --git a/lib/src/models/subscriber_list.dart b/lib/src/models/subscriber_list.dart index dc6724cf..c9a87d1f 100644 --- a/lib/src/models/subscriber_list.dart +++ b/lib/src/models/subscriber_list.dart @@ -14,8 +14,7 @@ class SubscriberList implements Model { factory SubscriberList.fromMap(Map<String, dynamic> map) { return SubscriberList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], subscribers: List<Subscriber>.from(map['subscribers'].map((p) => Subscriber.fromMap(p))), ); } diff --git a/lib/src/models/target.dart b/lib/src/models/target.dart index 50134304..6f754c8d 100644 --- a/lib/src/models/target.dart +++ b/lib/src/models/target.dart @@ -18,6 +18,8 @@ class Target implements Model { final String providerType; /// The target identifier. final String identifier; + /// Is the target expired. + final bool expired; Target({ required this.$id, @@ -28,6 +30,7 @@ class Target implements Model { this.providerId, required this.providerType, required this.identifier, + required this.expired, }); factory Target.fromMap(Map<String, dynamic> map) { @@ -40,6 +43,7 @@ class Target implements Model { providerId: map['providerId']?.toString(), providerType: map['providerType'].toString(), identifier: map['identifier'].toString(), + expired: map['expired'], ); } @@ -53,6 +57,7 @@ class Target implements Model { "providerId": providerId, "providerType": providerType, "identifier": identifier, + "expired": expired, }; } } diff --git a/lib/src/models/target_list.dart b/lib/src/models/target_list.dart index bc859bee..bdd8ff58 100644 --- a/lib/src/models/target_list.dart +++ b/lib/src/models/target_list.dart @@ -14,8 +14,7 @@ class TargetList implements Model { factory TargetList.fromMap(Map<String, dynamic> map) { return TargetList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], targets: List<Target>.from(map['targets'].map((p) => Target.fromMap(p))), ); } diff --git a/lib/src/models/team.dart b/lib/src/models/team.dart index 118be8dd..a55d13c9 100644 --- a/lib/src/models/team.dart +++ b/lib/src/models/team.dart @@ -30,8 +30,7 @@ class Team implements Model { $createdAt: map['\$createdAt'].toString(), $updatedAt: map['\$updatedAt'].toString(), name: map['name'].toString(), - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], prefs: Preferences.fromMap(map['prefs']), ); } diff --git a/lib/src/models/team_list.dart b/lib/src/models/team_list.dart index f011ce95..23147a1a 100644 --- a/lib/src/models/team_list.dart +++ b/lib/src/models/team_list.dart @@ -14,8 +14,7 @@ class TeamList implements Model { factory TeamList.fromMap(Map<String, dynamic> map) { return TeamList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], teams: List<Team>.from(map['teams'].map((p) => Team.fromMap(p))), ); } diff --git a/lib/src/models/topic.dart b/lib/src/models/topic.dart index bb9ddc3f..06ab80db 100644 --- a/lib/src/models/topic.dart +++ b/lib/src/models/topic.dart @@ -17,7 +17,7 @@ class Topic implements Model { /// Total count of push subscribers subscribed to the topic. final int pushTotal; /// Subscribe permissions. - final List subscribe; + final List<String> subscribe; Topic({ required this.$id, @@ -36,12 +36,9 @@ class Topic implements Model { $createdAt: map['\$createdAt'].toString(), $updatedAt: map['\$updatedAt'].toString(), name: map['name'].toString(), - emailTotal: (map['emailTotal'] is String) ? - int.tryParse(map['emailTotal']) ?? 0:map['emailTotal'] ?? 0, - smsTotal: (map['smsTotal'] is String) ? - int.tryParse(map['smsTotal']) ?? 0:map['smsTotal'] ?? 0, - pushTotal: (map['pushTotal'] is String) ? - int.tryParse(map['pushTotal']) ?? 0:map['pushTotal'] ?? 0, + emailTotal: map['emailTotal'], + smsTotal: map['smsTotal'], + pushTotal: map['pushTotal'], subscribe: map['subscribe'] ?? [], ); } diff --git a/lib/src/models/topic_list.dart b/lib/src/models/topic_list.dart index 64e6598f..0248a3c0 100644 --- a/lib/src/models/topic_list.dart +++ b/lib/src/models/topic_list.dart @@ -14,8 +14,7 @@ class TopicList implements Model { factory TopicList.fromMap(Map<String, dynamic> map) { return TopicList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], topics: List<Topic>.from(map['topics'].map((p) => Topic.fromMap(p))), ); } diff --git a/lib/src/models/user.dart b/lib/src/models/user.dart index 5937ff55..ccc22c65 100644 --- a/lib/src/models/user.dart +++ b/lib/src/models/user.dart @@ -21,7 +21,7 @@ class User implements Model { /// User status. Pass `true` for enabled and `false` for disabled. final bool status; /// Labels for the user. - final List labels; + final List<String> labels; /// Password update time in ISO 8601 format. final String passwordUpdate; /// User email address. diff --git a/lib/src/models/user_list.dart b/lib/src/models/user_list.dart index 92d926b0..53f47dac 100644 --- a/lib/src/models/user_list.dart +++ b/lib/src/models/user_list.dart @@ -14,8 +14,7 @@ class UserList implements Model { factory UserList.fromMap(Map<String, dynamic> map) { return UserList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], users: List<User>.from(map['users'].map((p) => User.fromMap(p))), ); } diff --git a/lib/src/models/variable_list.dart b/lib/src/models/variable_list.dart index 6883a928..cf795822 100644 --- a/lib/src/models/variable_list.dart +++ b/lib/src/models/variable_list.dart @@ -14,8 +14,7 @@ class VariableList implements Model { factory VariableList.fromMap(Map<String, dynamic> map) { return VariableList( - total: (map['total'] is String) ? - int.tryParse(map['total']) ?? 0:map['total'] ?? 0, + total: map['total'], variables: List<Variable>.from(map['variables'].map((p) => Variable.fromMap(p))), ); } diff --git a/pubspec.yaml b/pubspec.yaml index 62da2c85..bffe869e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,17 +1,14 @@ name: dart_appwrite -version: 13.0.0 +version: 12.2.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-dart issue_tracker: https://github.com/appwrite/sdk-generator/issues documentation: https://appwrite.io/support environment: - sdk: '>=3.0.0 <4.0.0' + sdk: '>=2.17.0 <4.0.0' dependencies: http: '>=0.13.6 <2.0.0' - http_parser: ^4.1.0 - mime: ^1.0.6 - string_scanner: ^1.3.0 dev_dependencies: lints: ^4.0.0 diff --git a/test/services/functions_test.dart b/test/services/functions_test.dart index 2cfbbf95..77e721c9 100644 --- a/test/services/functions_test.dart +++ b/test/services/functions_test.dart @@ -96,7 +96,7 @@ void main() { 'providerBranch': 'main', 'providerRootDirectory': 'functions/helloWorld', 'providerSilentMode': true, - 'specification': 's-0.5vcpu-512mb',}; + 'specification': 's-1vcpu-512mb',}; when(client.call( @@ -172,7 +172,7 @@ void main() { 'providerBranch': 'main', 'providerRootDirectory': 'functions/helloWorld', 'providerSilentMode': true, - 'specification': 's-0.5vcpu-512mb',}; + 'specification': 's-1vcpu-512mb',}; when(client.call( @@ -212,7 +212,7 @@ void main() { 'providerBranch': 'main', 'providerRootDirectory': 'functions/helloWorld', 'providerSilentMode': true, - 'specification': 's-0.5vcpu-512mb',}; + 'specification': 's-1vcpu-512mb',}; when(client.call( @@ -298,7 +298,7 @@ void main() { final response = await functions.createDeployment( functionId: '<FUNCTION_ID>', - code: Payload.fromPath(path: './image.png'), + code: InputFile.fromPath(path: './image.png'), activate: true, ); expect(response, isA<models.Deployment>()); @@ -371,7 +371,7 @@ void main() { 'providerBranch': 'main', 'providerRootDirectory': 'functions/helloWorld', 'providerSilentMode': true, - 'specification': 's-0.5vcpu-512mb',}; + 'specification': 's-1vcpu-512mb',}; when(client.call( @@ -487,19 +487,15 @@ void main() { 'requestPath': '/articles?id=5', 'requestHeaders': [], 'responseStatusCode': 200, - 'responseBody': , + 'responseBody': '', 'responseHeaders': [], 'logs': '', 'errors': '', 'duration': 0.4,}; - when(client.chunkedUpload( - path: argThat(isNotNull), - params: argThat(isNotNull), - paramName: argThat(isNotNull), - idParamName: argThat(isNotNull), - headers: argThat(isNotNull), + when(client.call( + HttpMethod.post, )).thenAnswer((_) async => Response(data: data)); @@ -523,7 +519,7 @@ void main() { 'requestPath': '/articles?id=5', 'requestHeaders': [], 'responseStatusCode': 200, - 'responseBody': , + 'responseBody': '', 'responseHeaders': [], 'logs': '', 'errors': '', diff --git a/test/services/messaging_test.dart b/test/services/messaging_test.dart index 31db4acb..eacea811 100644 --- a/test/services/messaging_test.dart +++ b/test/services/messaging_test.dart @@ -146,8 +146,6 @@ void main() { final response = await messaging.createPush( messageId: '<MESSAGE_ID>', - title: '<TITLE>', - body: '<BODY>', ); expect(response, isA<models.Message>()); diff --git a/test/services/storage_test.dart b/test/services/storage_test.dart index 682a8dbc..c2a81fab 100644 --- a/test/services/storage_test.dart +++ b/test/services/storage_test.dart @@ -215,7 +215,7 @@ void main() { final response = await storage.createFile( bucketId: '<BUCKET_ID>', fileId: '<FILE_ID>', - file: Payload.fromPath(path: './image.png'), + file: InputFile.fromPath(path: './image.png'), ); expect(response, isA<models.File>()); diff --git a/test/services/users_test.dart b/test/services/users_test.dart index 12174ae0..d5ac88da 100644 --- a/test/services/users_test.dart +++ b/test/services/users_test.dart @@ -958,10 +958,11 @@ void main() { '\$id': '259125845563242502', '\$createdAt': '2020-10-15T06:38:00.000+00:00', '\$updatedAt': '2020-10-15T06:38:00.000+00:00', - 'name': 'Aegon apple token', + 'name': 'Apple iPhone 12', 'userId': '259125845563242502', 'providerType': 'email', - 'identifier': 'token',}; + 'identifier': 'token', + 'expired': true,}; when(client.call( @@ -984,10 +985,11 @@ void main() { '\$id': '259125845563242502', '\$createdAt': '2020-10-15T06:38:00.000+00:00', '\$updatedAt': '2020-10-15T06:38:00.000+00:00', - 'name': 'Aegon apple token', + 'name': 'Apple iPhone 12', 'userId': '259125845563242502', 'providerType': 'email', - 'identifier': 'token',}; + 'identifier': 'token', + 'expired': true,}; when(client.call( @@ -1008,10 +1010,11 @@ void main() { '\$id': '259125845563242502', '\$createdAt': '2020-10-15T06:38:00.000+00:00', '\$updatedAt': '2020-10-15T06:38:00.000+00:00', - 'name': 'Aegon apple token', + 'name': 'Apple iPhone 12', 'userId': '259125845563242502', 'providerType': 'email', - 'identifier': 'token',}; + 'identifier': 'token', + 'expired': true,}; when(client.call( diff --git a/test/src/input_file_test.dart b/test/src/input_file_test.dart new file mode 100644 index 00000000..ccbd4387 --- /dev/null +++ b/test/src/input_file_test.dart @@ -0,0 +1,47 @@ +import 'package:test/test.dart'; +import 'package:dart_appwrite/src/exception.dart'; +import 'package:dart_appwrite/src/input_file.dart'; + +void main() { + group('InputFile', () { + test('throws exception when neither path nor bytes are provided', () { + expect( + () => InputFile(), + throwsA(isA<AppwriteException>().having( + (e) => e.message, + 'message', + 'One of `path` or `bytes` is required', + )), + ); + }); + + test('throws exception when path and bytes are both null', () { + expect( + () => InputFile(path: null, bytes: null), + throwsA(isA<AppwriteException>().having( + (e) => e.message, + 'message', + 'One of `path` or `bytes` is required', + )), + ); + }); + + test('creates InputFile from path', () { + final inputFile = InputFile.fromPath(path: '/path/to/file'); + + expect(inputFile.path, '/path/to/file'); + expect(inputFile.filename, isNull); + expect(inputFile.contentType, isNull); + expect(inputFile.bytes, isNull); + }); + + test('creates InputFile from bytes', () { + final inputFile = InputFile.fromBytes(bytes: [1, 2, 3], filename: 'file.txt'); + + expect(inputFile.path, isNull); + expect(inputFile.filename, 'file.txt'); + expect(inputFile.contentType, isNull); + expect(inputFile.bytes, [1, 2, 3]); + }); + }); +} diff --git a/test/src/models/execution_test.dart b/test/src/models/execution_test.dart index e0468292..67e108b0 100644 --- a/test/src/models/execution_test.dart +++ b/test/src/models/execution_test.dart @@ -17,7 +17,7 @@ void main() { requestPath: '/articles?id=5', requestHeaders: [], responseStatusCode: 200, - responseBody: , + responseBody: '', responseHeaders: [], logs: '', errors: '', @@ -38,7 +38,7 @@ void main() { expect(result.requestPath, '/articles?id=5'); expect(result.requestHeaders, []); expect(result.responseStatusCode, 200); - expect(result.responseBody, ); + expect(result.responseBody, ''); expect(result.responseHeaders, []); expect(result.logs, ''); expect(result.errors, ''); diff --git a/test/src/models/function_test.dart b/test/src/models/function_test.dart index 81d6e3e4..7b4e983f 100644 --- a/test/src/models/function_test.dart +++ b/test/src/models/function_test.dart @@ -29,7 +29,7 @@ void main() { providerBranch: 'main', providerRootDirectory: 'functions/helloWorld', providerSilentMode: true, - specification: 's-0.5vcpu-512mb', + specification: 's-1vcpu-512mb', ); final map = model.toMap(); @@ -58,7 +58,7 @@ void main() { expect(result.providerBranch, 'main'); expect(result.providerRootDirectory, 'functions/helloWorld'); expect(result.providerSilentMode, true); - expect(result.specification, 's-0.5vcpu-512mb'); + expect(result.specification, 's-1vcpu-512mb'); }); }); } diff --git a/test/src/models/specification_test.dart b/test/src/models/specification_test.dart index 9ba8e846..a70667d1 100644 --- a/test/src/models/specification_test.dart +++ b/test/src/models/specification_test.dart @@ -9,7 +9,7 @@ void main() { memory: 512, cpus: 1, enabled: true, - slug: 's-0.5vcpu-512mb', + slug: 's-1vcpu-512mb', ); final map = model.toMap(); @@ -18,7 +18,7 @@ void main() { expect(result.memory, 512); expect(result.cpus, 1); expect(result.enabled, true); - expect(result.slug, 's-0.5vcpu-512mb'); + expect(result.slug, 's-1vcpu-512mb'); }); }); } diff --git a/test/src/models/target_test.dart b/test/src/models/target_test.dart index 2d664691..891a939b 100644 --- a/test/src/models/target_test.dart +++ b/test/src/models/target_test.dart @@ -9,10 +9,11 @@ void main() { $id: '259125845563242502', $createdAt: '2020-10-15T06:38:00.000+00:00', $updatedAt: '2020-10-15T06:38:00.000+00:00', - name: 'Aegon apple token', + name: 'Apple iPhone 12', userId: '259125845563242502', providerType: 'email', identifier: 'token', + expired: true, ); final map = model.toMap(); @@ -21,10 +22,11 @@ void main() { expect(result.$id, '259125845563242502'); expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); - expect(result.name, 'Aegon apple token'); + expect(result.name, 'Apple iPhone 12'); expect(result.userId, '259125845563242502'); expect(result.providerType, 'email'); expect(result.identifier, 'token'); + expect(result.expired, true); }); }); } diff --git a/test/src/payload_test.dart b/test/src/payload_test.dart deleted file mode 100644 index 9a1b575e..00000000 --- a/test/src/payload_test.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:test/test.dart'; -import 'package:dart_appwrite/src/exception.dart'; -import 'package:dart_appwrite/payload.dart'; - -void main() { - group('Payload', () { - test('creates Payload from path', () { - final payload = Payload.fromFile(path: '/path/to/file'); - - expect(payload.path, '/path/to/file'); - expect(payload.filename, isNull); - expect(payload.data, isNull); - }); - - test('creates Payload from binary', () { - final payload = Payload.fromBinary(data: [1, 2, 3], filename: 'file.txt'); - - expect(payload.path, isNull); - expect(payload.filename, 'file.txt'); - expect(payload.data, [1, 2, 3]); - }); - }); -} From dc1cd41d1a8baa11f15cdef2c44918d71de9cb93 Mon Sep 17 00:00:00 2001 From: abnegate <abnegate@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:36:52 +0000 Subject: [PATCH 6/7] Commit from GitHub Actions (Format and push) --- lib/client_browser.dart | 2 +- lib/client_io.dart | 2 +- lib/dart_appwrite.dart | 2 +- lib/id.dart | 3 +- lib/query.dart | 45 +- lib/role.dart | 106 +- lib/services/account.dart | 2239 ++++++++--------- lib/services/avatars.dart | 404 +-- lib/services/databases.dart | 2367 ++++++++++-------- lib/services/functions.dart | 1262 +++++----- lib/services/graphql.dart | 94 +- lib/services/health.dart | 929 ++++--- lib/services/locale.dart | 270 +- lib/services/messaging.dart | 2637 ++++++++++---------- lib/services/storage.dart | 732 +++--- lib/services/teams.dart | 688 +++-- lib/services/users.dart | 2072 ++++++++------- lib/src/client.dart | 7 +- lib/src/client_base.dart | 6 +- lib/src/client_browser.dart | 98 +- lib/src/client_io.dart | 98 +- lib/src/client_mixin.dart | 33 +- lib/src/enums/authentication_factor.dart | 18 +- lib/src/enums/authenticator_type.dart | 12 +- lib/src/enums/browser.dart | 38 +- lib/src/enums/compression.dart | 16 +- lib/src/enums/credit_card.dart | 42 +- lib/src/enums/execution_method.dart | 22 +- lib/src/enums/flag.dart | 400 ++- lib/src/enums/image_format.dart | 22 +- lib/src/enums/image_gravity.dart | 28 +- lib/src/enums/index_type.dart | 16 +- lib/src/enums/message_priority.dart | 14 +- lib/src/enums/messaging_provider_type.dart | 16 +- lib/src/enums/name.dart | 34 +- lib/src/enums/o_auth_provider.dart | 88 +- lib/src/enums/password_hash.dart | 32 +- lib/src/enums/relation_mutate.dart | 16 +- lib/src/enums/relationship_type.dart | 18 +- lib/src/enums/runtime.dart | 128 +- lib/src/enums/smtp_encryption.dart | 16 +- lib/src/exception.dart | 2 +- lib/src/models/algo_argon2.dart | 63 +- lib/src/models/algo_bcrypt.dart | 30 +- lib/src/models/algo_md5.dart | 30 +- lib/src/models/algo_phpass.dart | 30 +- lib/src/models/algo_scrypt.dart | 80 +- lib/src/models/algo_scrypt_modified.dart | 63 +- lib/src/models/algo_sha.dart | 30 +- lib/src/models/attribute_boolean.dart | 124 +- lib/src/models/attribute_datetime.dart | 129 +- lib/src/models/attribute_email.dart | 129 +- lib/src/models/attribute_enum.dart | 140 +- lib/src/models/attribute_float.dart | 140 +- lib/src/models/attribute_integer.dart | 140 +- lib/src/models/attribute_ip.dart | 129 +- lib/src/models/attribute_list.dart | 41 +- lib/src/models/attribute_relationship.dart | 179 +- lib/src/models/attribute_string.dart | 129 +- lib/src/models/attribute_url.dart | 129 +- lib/src/models/bucket.dart | 151 +- lib/src/models/bucket_list.dart | 41 +- lib/src/models/build.dart | 124 +- lib/src/models/collection.dart | 129 +- lib/src/models/collection_list.dart | 42 +- lib/src/models/continent.dart | 41 +- lib/src/models/continent_list.dart | 42 +- lib/src/models/country.dart | 41 +- lib/src/models/country_list.dart | 42 +- lib/src/models/currency.dart | 102 +- lib/src/models/currency_list.dart | 42 +- lib/src/models/database.dart | 80 +- lib/src/models/database_list.dart | 42 +- lib/src/models/deployment.dart | 289 ++- lib/src/models/deployment_list.dart | 42 +- lib/src/models/document.dart | 103 +- lib/src/models/document_list.dart | 46 +- lib/src/models/execution.dart | 214 +- lib/src/models/execution_list.dart | 42 +- lib/src/models/file.dart | 140 +- lib/src/models/file_list.dart | 41 +- lib/src/models/function.dart | 289 ++- lib/src/models/function_list.dart | 41 +- lib/src/models/headers.dart | 41 +- lib/src/models/health_antivirus.dart | 41 +- lib/src/models/health_certificate.dart | 91 +- lib/src/models/health_queue.dart | 30 +- lib/src/models/health_status.dart | 52 +- lib/src/models/health_time.dart | 52 +- lib/src/models/identity.dart | 129 +- lib/src/models/identity_list.dart | 42 +- lib/src/models/index.dart | 113 +- lib/src/models/index_list.dart | 41 +- lib/src/models/jwt.dart | 30 +- lib/src/models/language.dart | 52 +- lib/src/models/language_list.dart | 42 +- lib/src/models/locale.dart | 102 +- lib/src/models/locale_code.dart | 41 +- lib/src/models/locale_code_list.dart | 42 +- lib/src/models/log.dart | 256 +- lib/src/models/log_list.dart | 41 +- lib/src/models/membership.dart | 168 +- lib/src/models/membership_list.dart | 42 +- lib/src/models/message.dart | 168 +- lib/src/models/message_list.dart | 42 +- lib/src/models/mfa_challenge.dart | 63 +- lib/src/models/mfa_factors.dart | 63 +- lib/src/models/mfa_recovery_codes.dart | 30 +- lib/src/models/mfa_type.dart | 41 +- lib/src/models/model.dart | 2 +- lib/src/models/phone.dart | 52 +- lib/src/models/phone_list.dart | 41 +- lib/src/models/preferences.dart | 30 +- lib/src/models/provider.dart | 124 +- lib/src/models/provider_list.dart | 42 +- lib/src/models/runtime.dart | 113 +- lib/src/models/runtime_list.dart | 42 +- lib/src/models/session.dart | 344 +-- lib/src/models/session_list.dart | 42 +- lib/src/models/specification.dart | 63 +- lib/src/models/specification_list.dart | 42 +- lib/src/models/subscriber.dart | 124 +- lib/src/models/subscriber_list.dart | 42 +- lib/src/models/target.dart | 124 +- lib/src/models/target_list.dart | 41 +- lib/src/models/team.dart | 91 +- lib/src/models/team_list.dart | 41 +- lib/src/models/token.dart | 91 +- lib/src/models/topic.dart | 113 +- lib/src/models/topic_list.dart | 41 +- lib/src/models/user.dart | 234 +- lib/src/models/user_list.dart | 41 +- lib/src/models/variable.dart | 102 +- lib/src/models/variable_list.dart | 42 +- 134 files changed, 11735 insertions(+), 11159 deletions(-) diff --git a/lib/client_browser.dart b/lib/client_browser.dart index 09f110ea..b9805a3a 100644 --- a/lib/client_browser.dart +++ b/lib/client_browser.dart @@ -1 +1 @@ -export 'src/client_browser.dart'; \ No newline at end of file +export 'src/client_browser.dart'; diff --git a/lib/client_io.dart b/lib/client_io.dart index 4d85cbfa..42a0c0b6 100644 --- a/lib/client_io.dart +++ b/lib/client_io.dart @@ -1 +1 @@ -export 'src/client_io.dart'; \ No newline at end of file +export 'src/client_io.dart'; diff --git a/lib/dart_appwrite.dart b/lib/dart_appwrite.dart index 21865e2e..26412fe3 100644 --- a/lib/dart_appwrite.dart +++ b/lib/dart_appwrite.dart @@ -1,6 +1,6 @@ /// Appwrite Dart SDK /// -/// This SDK is compatible with Appwrite server version 1.6.x. +/// This SDK is compatible with Appwrite server version 1.6.x. /// For older versions, please check /// [previous releases](https://github.com/appwrite/sdk-for-dart/releases). library dart_appwrite; diff --git a/lib/id.dart b/lib/id.dart index 72e26a23..28ff15e8 100644 --- a/lib/id.dart +++ b/lib/id.dart @@ -10,8 +10,7 @@ class ID { final now = DateTime.now(); final sec = (now.millisecondsSinceEpoch / 1000).floor(); final usec = now.microsecondsSinceEpoch - (sec * 1000000); - return sec.toRadixString(16) + - usec.toRadixString(16).padLeft(5, '0'); + return sec.toRadixString(16) + usec.toRadixString(16).padLeft(5, '0'); } // Generate a unique ID with padding to have a longer ID diff --git a/lib/query.dart b/lib/query.dart index 46882207..6b8ed94f 100644 --- a/lib/query.dart +++ b/lib/query.dart @@ -1,6 +1,5 @@ part of 'dart_appwrite.dart'; - /// Helper class to generate query strings. class Query { final String method; @@ -14,11 +13,11 @@ class Query { 'method': method, }; - if(attribute != null) { + if (attribute != null) { map['attribute'] = attribute; } - - if(values != null) { + + if (values != null) { map['values'] = values is List ? values : [values]; } @@ -29,7 +28,7 @@ class Query { String toString() => jsonEncode(toJson()); /// Filter resources where [attribute] is equal to [value]. - /// + /// /// [value] can be a single value or a list. If a list is used /// the query will return resources where [attribute] is equal /// to any of the values in the list. @@ -61,10 +60,12 @@ class Query { Query._('search', attribute, value).toString(); /// Filter resources where [attribute] is null. - static String isNull(String attribute) => Query._('isNull', attribute).toString(); + static String isNull(String attribute) => + Query._('isNull', attribute).toString(); /// Filter resources where [attribute] is not null. - static String isNotNull(String attribute) => Query._('isNotNull', attribute).toString(); + static String isNotNull(String attribute) => + Query._('isNotNull', attribute).toString(); /// Filter resources where [attribute] is between [start] and [end] (inclusive). static String between(String attribute, dynamic start, dynamic end) => @@ -84,40 +85,46 @@ class Query { Query._('contains', attribute, value).toString(); static String or(List<String> queries) => - Query._('or', null, queries.map((query) => jsonDecode(query)).toList()).toString(); + Query._('or', null, queries.map((query) => jsonDecode(query)).toList()) + .toString(); static String and(List<String> queries) => - Query._('and', null, queries.map((query) => jsonDecode(query)).toList()).toString(); + Query._('and', null, queries.map((query) => jsonDecode(query)).toList()) + .toString(); /// Specify which attributes should be returned by the API call. static String select(List<String> attributes) => Query._('select', null, attributes).toString(); /// Sort results by [attribute] ascending. - static String orderAsc(String attribute) => Query._('orderAsc', attribute).toString(); + static String orderAsc(String attribute) => + Query._('orderAsc', attribute).toString(); /// Sort results by [attribute] descending. - static String orderDesc(String attribute) => Query._('orderDesc', attribute).toString(); + static String orderDesc(String attribute) => + Query._('orderDesc', attribute).toString(); /// Return results before [id]. - /// + /// /// Refer to the [Cursor Based Pagination](https://appwrite.io/docs/pagination#cursor-pagination) /// docs for more information. - static String cursorBefore(String id) => Query._('cursorBefore', null, id).toString(); + static String cursorBefore(String id) => + Query._('cursorBefore', null, id).toString(); /// Return results after [id]. - /// + /// /// Refer to the [Cursor Based Pagination](https://appwrite.io/docs/pagination#cursor-pagination) /// docs for more information. - static String cursorAfter(String id) => Query._('cursorAfter', null, id).toString(); + static String cursorAfter(String id) => + Query._('cursorAfter', null, id).toString(); /// Return only [limit] results. static String limit(int limit) => Query._('limit', null, limit).toString(); /// Return results from [offset]. - /// + /// /// Refer to the [Offset Pagination](https://appwrite.io/docs/pagination#offset-pagination) /// docs for more information. - static String offset(int offset) => Query._('offset', null, offset).toString(); - -} \ No newline at end of file + static String offset(int offset) => + Query._('offset', null, offset).toString(); +} diff --git a/lib/role.dart b/lib/role.dart index 6552df47..dafeb78d 100644 --- a/lib/role.dart +++ b/lib/role.dart @@ -2,65 +2,65 @@ part of 'dart_appwrite.dart'; /// Helper class to generate role strings for [Permission]. class Role { - Role._(); - - /// Grants access to anyone. - /// - /// This includes authenticated and unauthenticated users. - static String any() { - return 'any'; - } + Role._(); - /// Grants access to a specific user by user ID. - /// - /// You can optionally pass verified or unverified for - /// [status] to target specific types of users. - static String user(String id, [String status = '']) { - if(status.isEmpty) { - return 'user:$id'; - } - return 'user:$id/$status'; - } + /// Grants access to anyone. + /// + /// This includes authenticated and unauthenticated users. + static String any() { + return 'any'; + } - /// Grants access to any authenticated or anonymous user. - /// - /// You can optionally pass verified or unverified for - /// [status] to target specific types of users. - static String users([String status = '']) { - if(status.isEmpty) { - return 'users'; - } - return 'users/$status'; + /// Grants access to a specific user by user ID. + /// + /// You can optionally pass verified or unverified for + /// [status] to target specific types of users. + static String user(String id, [String status = '']) { + if (status.isEmpty) { + return 'user:$id'; } + return 'user:$id/$status'; + } - /// Grants access to any guest user without a session. - /// - /// Authenticated users don't have access to this role. - static String guests() { - return 'guests'; + /// Grants access to any authenticated or anonymous user. + /// + /// You can optionally pass verified or unverified for + /// [status] to target specific types of users. + static String users([String status = '']) { + if (status.isEmpty) { + return 'users'; } + return 'users/$status'; + } - /// Grants access to a team by team ID. - /// - /// You can optionally pass a role for [role] to target - /// team members with the specified role. - static String team(String id, [String role = '']) { - if(role.isEmpty) { - return 'team:$id'; - } - return 'team:$id/$role'; - } + /// Grants access to any guest user without a session. + /// + /// Authenticated users don't have access to this role. + static String guests() { + return 'guests'; + } - /// Grants access to a specific member of a team. - /// - /// When the member is removed from the team, they will - /// no longer have access. - static String member(String id) { - return 'member:$id'; + /// Grants access to a team by team ID. + /// + /// You can optionally pass a role for [role] to target + /// team members with the specified role. + static String team(String id, [String role = '']) { + if (role.isEmpty) { + return 'team:$id'; } + return 'team:$id/$role'; + } - /// Grants access to a user with the specified label. - static String label(String name) { - return 'label:$name'; - } -} \ No newline at end of file + /// Grants access to a specific member of a team. + /// + /// When the member is removed from the team, they will + /// no longer have access. + static String member(String id) { + return 'member:$id'; + } + + /// Grants access to a user with the specified label. + static String label(String name) { + return 'label:$name'; + } +} diff --git a/lib/services/account.dart b/lib/services/account.dart index d1e830e5..00b7785c 100644 --- a/lib/services/account.dart +++ b/lib/services/account.dart @@ -2,1175 +2,1070 @@ part of '../dart_appwrite.dart'; /// The Account service allows you to authenticate and manage a user account. class Account extends Service { - Account(super.client); - - /// Get account - /// - /// Get the currently logged in user. - Future<models.User> get() async { - final String apiPath = '/account'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - 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](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession). - Future<models.User> create({required String userId, required String email, required String password, String? name}) async { - final String apiPath = '/account'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'email': email, -'password': password, -'name': name, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Update 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<models.User> updateEmail({required String email, required String password}) async { - final String apiPath = '/account/email'; - - final Map<String, dynamic> apiParams = { - - 'email': email, -'password': password, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// List identities - /// - /// Get the list of identities for the currently logged in user. - Future<models.IdentityList> listIdentities({List<String>? queries}) async { - final String apiPath = '/account/identities'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.IdentityList.fromMap(res.data); - - } - - /// Delete identity - /// - /// Delete an identity by its unique ID. - Future deleteIdentity({required String identityId}) async { - final String apiPath = '/account/identities/{identityId}'.replaceAll('{identityId}', identityId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Create 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<models.Jwt> createJWT() async { - final String apiPath = '/account/jwts'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Jwt.fromMap(res.data); - - } - - /// List logs - /// - /// Get the list of latest security activity logs for the currently logged in - /// user. Each log returns user IP address, location and date and time of log. - Future<models.LogList> listLogs({List<String>? queries}) async { - final String apiPath = '/account/logs'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - - } - - /// Update MFA - /// - /// Enable or disable MFA on an account. - Future<models.User> updateMFA({required bool mfa}) async { - final String apiPath = '/account/mfa'; - - final Map<String, dynamic> apiParams = { - - 'mfa': mfa, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create authenticator - /// - /// Add an authenticator app to be used as an MFA factor. Verify the - /// authenticator using the [verify - /// authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) - /// method. - Future<models.MfaType> createMfaAuthenticator({required enums.AuthenticatorType type}) async { - final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaType.fromMap(res.data); - - } - - /// Verify authenticator - /// - /// Verify an authenticator app after adding it using the [add - /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) - /// method. - Future<models.User> updateMfaAuthenticator({required enums.AuthenticatorType type, required String otp}) async { - final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); - - final Map<String, dynamic> apiParams = { - - 'otp': otp, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Delete authenticator - /// - /// Delete an authenticator for a user by ID. - Future deleteMfaAuthenticator({required enums.AuthenticatorType type}) async { - final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Create MFA challenge - /// - /// Begin the process of MFA verification after sign-in. Finish the flow with - /// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) - /// method. - Future<models.MfaChallenge> createMfaChallenge({required enums.AuthenticationFactor factor}) async { - final String apiPath = '/account/mfa/challenge'; - - final Map<String, dynamic> apiParams = { - - 'factor': factor.value, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaChallenge.fromMap(res.data); - - } - - /// Create MFA challenge (confirmation) - /// - /// Complete the MFA challenge by providing the one-time password. Finish the - /// process of MFA verification by providing the one-time password. To begin - /// the flow, use - /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) - /// method. - Future updateMfaChallenge({required String challengeId, required String otp}) async { - final String apiPath = '/account/mfa/challenge'; - - final Map<String, dynamic> apiParams = { - - 'challengeId': challengeId, -'otp': otp, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List factors - /// - /// List the factors available on the account to be used as a MFA challange. - Future<models.MfaFactors> listMfaFactors() async { - final String apiPath = '/account/mfa/factors'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaFactors.fromMap(res.data); - - } - - /// Get MFA recovery codes - /// - /// Get recovery codes that can be used as backup for MFA flow. Before getting - /// codes, they must be generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. An OTP challenge is required to read recovery codes. - Future<models.MfaRecoveryCodes> getMfaRecoveryCodes() async { - final String apiPath = '/account/mfa/recovery-codes'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - - } - - /// Create MFA recovery codes - /// - /// Generate recovery codes as backup for MFA flow. It's recommended to - /// generate and show then immediately after user successfully adds their - /// authehticator. Recovery codes can be used as a MFA verification type in - /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) - /// method. - Future<models.MfaRecoveryCodes> createMfaRecoveryCodes() async { - final String apiPath = '/account/mfa/recovery-codes'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - - } - - /// Regenerate MFA recovery codes - /// - /// Regenerate recovery codes that can be used as backup for MFA flow. Before - /// regenerating codes, they must be first generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. An OTP challenge is required to regenreate recovery codes. - Future<models.MfaRecoveryCodes> updateMfaRecoveryCodes() async { - final String apiPath = '/account/mfa/recovery-codes'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - - } - - /// Update name - /// - /// Update currently logged in user account name. - Future<models.User> updateName({required String name}) async { - final String apiPath = '/account/name'; - - final Map<String, dynamic> apiParams = { - - 'name': name, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Update 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<models.User> updatePassword({required String password, String? oldPassword}) async { - final String apiPath = '/account/password'; - - final Map<String, dynamic> apiParams = { - - 'password': password, -'oldPassword': oldPassword, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Update 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](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification) - /// endpoint to send a confirmation SMS. - Future<models.User> updatePhone({required String phone, required String password}) async { - final String apiPath = '/account/phone'; - - final Map<String, dynamic> apiParams = { - - 'phone': phone, -'password': password, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Get account preferences - /// - /// Get the preferences as a key-value object for the currently logged in user. - Future<models.Preferences> getPrefs() async { - final String apiPath = '/account/prefs'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - - } - - /// Update 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<models.User> updatePrefs({required Map prefs}) async { - final String apiPath = '/account/prefs'; - - final Map<String, dynamic> apiParams = { - - 'prefs': prefs, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - 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](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery) - /// endpoint to complete the process. The verification link sent to the user's - /// email address is valid for 1 hour. - Future<models.Token> createRecovery({required String email, required String url}) async { - final String apiPath = '/account/recovery'; - - final Map<String, dynamic> apiParams = { - - 'email': email, -'url': url, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// Create 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](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery) - /// 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<models.Token> updateRecovery({required String userId, required String secret, required String password}) async { - final String apiPath = '/account/recovery'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'secret': secret, -'password': password, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// List sessions - /// - /// Get the list of active sessions across different devices for the currently - /// logged in user. - Future<models.SessionList> listSessions() async { - final String apiPath = '/account/sessions'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SessionList.fromMap(res.data); - - } - - /// Delete sessions - /// - /// Delete all sessions from the user account and remove any sessions cookies - /// from the end client. - Future deleteSessions() async { - final String apiPath = '/account/sessions'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - 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](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail) - /// or create an [OAuth2 - /// session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session). - Future<models.Session> createAnonymousSession() async { - final String apiPath = '/account/sessions/anonymous'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - - } - - /// Create email password session - /// - /// Allow the user to login into their account by providing a valid email and - /// password combination. This route will create a new session for the user. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future<models.Session> createEmailPasswordSession({required String email, required String password}) async { - final String apiPath = '/account/sessions/email'; - - final Map<String, dynamic> apiParams = { - - 'email': email, -'password': password, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - - } - - /// Update magic URL session - /// - /// Use this endpoint to create a session from token. Provide the **userId** - /// and **secret** parameters from the successful response of authentication - /// flows initiated by token creation. For example, magic URL and phone login. - Future<models.Session> updateMagicURLSession({required String userId, required String secret}) async { - final String apiPath = '/account/sessions/magic-url'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'secret': secret, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - - } - - /// Update phone session - /// - /// Use this endpoint to create a session from token. Provide the **userId** - /// and **secret** parameters from the successful response of authentication - /// flows initiated by token creation. For example, magic URL and phone login. - Future<models.Session> updatePhoneSession({required String userId, required String secret}) async { - final String apiPath = '/account/sessions/phone'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'secret': secret, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - - } - - /// Create session - /// - /// Use this endpoint to create a session from token. Provide the **userId** - /// and **secret** parameters from the successful response of authentication - /// flows initiated by token creation. For example, magic URL and phone login. - Future<models.Session> createSession({required String userId, required String secret}) async { - final String apiPath = '/account/sessions/token'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'secret': secret, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - - } - - /// Get session - /// - /// 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<models.Session> getSession({required String sessionId}) async { - final String apiPath = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - - } - - /// Update session - /// - /// Use this endpoint to extend a session's length. Extending a session is - /// useful when session expiry is short. If the session was created using an - /// OAuth provider, this endpoint refreshes the access token from the provider. - Future<models.Session> updateSession({required String sessionId}) async { - final String apiPath = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - - } - - /// Delete session - /// - /// Logout the user. Use 'current' as the session ID to logout on this device, - /// use a session ID to logout on another device. If you're looking to logout - /// the user on all devices, use [Delete - /// Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions) - /// instead. - Future deleteSession({required String sessionId}) async { - final String apiPath = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Update 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<models.User> updateStatus() async { - final String apiPath = '/account/status'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create email token (OTP) - /// - /// Sends the user an email with a secret key for creating a session. If the - /// provided user ID has not be registered, a new user will be created. Use the - /// returned user ID and secret and submit a request to the [POST - /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. The secret sent to the user's email - /// is valid for 15 minutes. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future<models.Token> createEmailToken({required String userId, required String email, bool? phrase}) async { - final String apiPath = '/account/tokens/email'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'email': email, -'phrase': phrase, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// Create magic URL token - /// - /// Sends the user an email with a secret key for creating a session. If the - /// provided user ID has not been registered, a new user will be created. When - /// the user clicks the link in the email, the user is redirected back to the - /// URL you provided with the secret key and userId values attached to the URL - /// query string. Use the query string parameters to submit a request to the - /// [POST - /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. The link sent to the user's email - /// address is valid for 1 hour. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - /// - Future<models.Token> createMagicURLToken({required String userId, required String email, String? url, bool? phrase}) async { - final String apiPath = '/account/tokens/magic-url'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'email': email, -'url': url, -'phrase': phrase, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// Create OAuth2 token - /// - /// Allow the user to login to their account using the OAuth2 provider of their - /// choice. Each OAuth2 provider should be enabled from the Appwrite console - /// first. Use the success and failure arguments to provide a redirect URL's - /// back to your app when login is completed. - /// - /// If authentication succeeds, `userId` and `secret` of a token will be - /// appended to the success URL as query parameters. These can be used to - /// create a new session using the [Create - /// session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future createOAuth2Token({required enums.OAuthProvider provider, String? success, String? failure, List<String>? scopes}) async { - final String apiPath = '/account/tokens/oauth2/{provider}'.replaceAll('{provider}', provider.value); - - final Map<String, dynamic> params = { - 'success': success, -'failure': failure, -'scopes': scopes, - - - 'project': client.config['project'], - }; - - final List query = []; - - params.forEach((key, value) { - if (value is List) { - for (var item in value) { - query.add(Uri.encodeComponent(key + '[]') + '=' + Uri.encodeComponent(item)); - } - } else if(value != null) { - query.add(Uri.encodeComponent(key) + '=' + Uri.encodeComponent(value)); - } - }); - - Uri endpoint = Uri.parse(client.endPoint); - Uri url = Uri(scheme: endpoint.scheme, - host: endpoint.host, - port: endpoint.port, - path: endpoint.path + apiPath, - query: query.join('&') - ); - - return client.webAuth(url); - } - - /// Create phone token - /// - /// Sends the user an SMS with a secret key for creating a session. If the - /// provided user ID has not be registered, a new user will be created. Use the - /// returned user ID and secret and submit a request to the [POST - /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. The secret sent to the user's phone - /// is valid for 15 minutes. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future<models.Token> createPhoneToken({required String userId, required String phone}) async { - final String apiPath = '/account/tokens/phone'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'phone': phone, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// Create email verification - /// - /// Use this endpoint to send a verification message to your user email address - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). - /// 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<models.Token> createVerification({required String url}) async { - final String apiPath = '/account/verification'; - - final Map<String, dynamic> apiParams = { - - 'url': url, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// Create email verification (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<models.Token> updateVerification({required String userId, required String secret}) async { - final String apiPath = '/account/verification'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'secret': secret, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone) - /// endpoint. Learn more about how to [complete the verification - /// process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification). - /// The verification code sent to the user's phone number is valid for 15 - /// minutes. - Future<models.Token> createPhoneVerification() async { - final String apiPath = '/account/verification/phone'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// Update 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<models.Token> updatePhoneVerification({required String userId, required String secret}) async { - final String apiPath = '/account/verification/phone'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'secret': secret, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } -} \ No newline at end of file + Account(super.client); + + /// Get account + /// + /// Get the currently logged in user. + Future<models.User> get() async { + final String apiPath = '/account'; + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession). + Future<models.User> create( + {required String userId, + required String email, + required String password, + String? name}) async { + final String apiPath = '/account'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'email': email, + 'password': password, + 'name': name, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Update 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<models.User> updateEmail( + {required String email, required String password}) async { + final String apiPath = '/account/email'; + + final Map<String, dynamic> apiParams = { + 'email': email, + 'password': password, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// List identities + /// + /// Get the list of identities for the currently logged in user. + Future<models.IdentityList> listIdentities({List<String>? queries}) async { + final String apiPath = '/account/identities'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.IdentityList.fromMap(res.data); + } + + /// Delete identity + /// + /// Delete an identity by its unique ID. + Future deleteIdentity({required String identityId}) async { + final String apiPath = '/account/identities/{identityId}' + .replaceAll('{identityId}', identityId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Create 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<models.Jwt> createJWT() async { + final String apiPath = '/account/jwts'; + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Jwt.fromMap(res.data); + } + + /// List logs + /// + /// Get the list of latest security activity logs for the currently logged in + /// user. Each log returns user IP address, location and date and time of log. + Future<models.LogList> listLogs({List<String>? queries}) async { + final String apiPath = '/account/logs'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + } + + /// Update MFA + /// + /// Enable or disable MFA on an account. + Future<models.User> updateMFA({required bool mfa}) async { + final String apiPath = '/account/mfa'; + + final Map<String, dynamic> apiParams = { + 'mfa': mfa, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create authenticator + /// + /// Add an authenticator app to be used as an MFA factor. Verify the + /// authenticator using the [verify + /// authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) + /// method. + Future<models.MfaType> createMfaAuthenticator( + {required enums.AuthenticatorType type}) async { + final String apiPath = + '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaType.fromMap(res.data); + } + + /// Verify authenticator + /// + /// Verify an authenticator app after adding it using the [add + /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) + /// method. + Future<models.User> updateMfaAuthenticator( + {required enums.AuthenticatorType type, required String otp}) async { + final String apiPath = + '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map<String, dynamic> apiParams = { + 'otp': otp, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Delete authenticator + /// + /// Delete an authenticator for a user by ID. + Future deleteMfaAuthenticator({required enums.AuthenticatorType type}) async { + final String apiPath = + '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Create MFA challenge + /// + /// Begin the process of MFA verification after sign-in. Finish the flow with + /// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) + /// method. + Future<models.MfaChallenge> createMfaChallenge( + {required enums.AuthenticationFactor factor}) async { + final String apiPath = '/account/mfa/challenge'; + + final Map<String, dynamic> apiParams = { + 'factor': factor.value, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaChallenge.fromMap(res.data); + } + + /// Create MFA challenge (confirmation) + /// + /// Complete the MFA challenge by providing the one-time password. Finish the + /// process of MFA verification by providing the one-time password. To begin + /// the flow, use + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method. + Future updateMfaChallenge( + {required String challengeId, required String otp}) async { + final String apiPath = '/account/mfa/challenge'; + + final Map<String, dynamic> apiParams = { + 'challengeId': challengeId, + 'otp': otp, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List factors + /// + /// List the factors available on the account to be used as a MFA challange. + Future<models.MfaFactors> listMfaFactors() async { + final String apiPath = '/account/mfa/factors'; + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaFactors.fromMap(res.data); + } + + /// Get MFA recovery codes + /// + /// Get recovery codes that can be used as backup for MFA flow. Before getting + /// codes, they must be generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. An OTP challenge is required to read recovery codes. + Future<models.MfaRecoveryCodes> getMfaRecoveryCodes() async { + final String apiPath = '/account/mfa/recovery-codes'; + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + } + + /// Create MFA recovery codes + /// + /// Generate recovery codes as backup for MFA flow. It's recommended to + /// generate and show then immediately after user successfully adds their + /// authehticator. Recovery codes can be used as a MFA verification type in + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method. + Future<models.MfaRecoveryCodes> createMfaRecoveryCodes() async { + final String apiPath = '/account/mfa/recovery-codes'; + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + } + + /// Regenerate MFA recovery codes + /// + /// Regenerate recovery codes that can be used as backup for MFA flow. Before + /// regenerating codes, they must be first generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. An OTP challenge is required to regenreate recovery codes. + Future<models.MfaRecoveryCodes> updateMfaRecoveryCodes() async { + final String apiPath = '/account/mfa/recovery-codes'; + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + } + + /// Update name + /// + /// Update currently logged in user account name. + Future<models.User> updateName({required String name}) async { + final String apiPath = '/account/name'; + + final Map<String, dynamic> apiParams = { + 'name': name, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Update 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<models.User> updatePassword( + {required String password, String? oldPassword}) async { + final String apiPath = '/account/password'; + + final Map<String, dynamic> apiParams = { + 'password': password, + 'oldPassword': oldPassword, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Update 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](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification) + /// endpoint to send a confirmation SMS. + Future<models.User> updatePhone( + {required String phone, required String password}) async { + final String apiPath = '/account/phone'; + + final Map<String, dynamic> apiParams = { + 'phone': phone, + 'password': password, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Get account preferences + /// + /// Get the preferences as a key-value object for the currently logged in user. + Future<models.Preferences> getPrefs() async { + final String apiPath = '/account/prefs'; + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + } + + /// Update 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<models.User> updatePrefs({required Map prefs}) async { + final String apiPath = '/account/prefs'; + + final Map<String, dynamic> apiParams = { + 'prefs': prefs, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery) + /// endpoint to complete the process. The verification link sent to the user's + /// email address is valid for 1 hour. + Future<models.Token> createRecovery( + {required String email, required String url}) async { + final String apiPath = '/account/recovery'; + + final Map<String, dynamic> apiParams = { + 'email': email, + 'url': url, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// Create 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](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery) + /// 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<models.Token> updateRecovery( + {required String userId, + required String secret, + required String password}) async { + final String apiPath = '/account/recovery'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'secret': secret, + 'password': password, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// List sessions + /// + /// Get the list of active sessions across different devices for the currently + /// logged in user. + Future<models.SessionList> listSessions() async { + final String apiPath = '/account/sessions'; + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SessionList.fromMap(res.data); + } + + /// Delete sessions + /// + /// Delete all sessions from the user account and remove any sessions cookies + /// from the end client. + Future deleteSessions() async { + final String apiPath = '/account/sessions'; + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail) + /// or create an [OAuth2 + /// session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session). + Future<models.Session> createAnonymousSession() async { + final String apiPath = '/account/sessions/anonymous'; + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + } + + /// Create email password session + /// + /// Allow the user to login into their account by providing a valid email and + /// password combination. This route will create a new session for the user. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future<models.Session> createEmailPasswordSession( + {required String email, required String password}) async { + final String apiPath = '/account/sessions/email'; + + final Map<String, dynamic> apiParams = { + 'email': email, + 'password': password, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + } + + /// Update magic URL session + /// + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. + Future<models.Session> updateMagicURLSession( + {required String userId, required String secret}) async { + final String apiPath = '/account/sessions/magic-url'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'secret': secret, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + } + + /// Update phone session + /// + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. + Future<models.Session> updatePhoneSession( + {required String userId, required String secret}) async { + final String apiPath = '/account/sessions/phone'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'secret': secret, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + } + + /// Create session + /// + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. + Future<models.Session> createSession( + {required String userId, required String secret}) async { + final String apiPath = '/account/sessions/token'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'secret': secret, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + } + + /// Get session + /// + /// 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<models.Session> getSession({required String sessionId}) async { + final String apiPath = + '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + } + + /// Update session + /// + /// Use this endpoint to extend a session's length. Extending a session is + /// useful when session expiry is short. If the session was created using an + /// OAuth provider, this endpoint refreshes the access token from the provider. + Future<models.Session> updateSession({required String sessionId}) async { + final String apiPath = + '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + } + + /// Delete session + /// + /// Logout the user. Use 'current' as the session ID to logout on this device, + /// use a session ID to logout on another device. If you're looking to logout + /// the user on all devices, use [Delete + /// Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions) + /// instead. + Future deleteSession({required String sessionId}) async { + final String apiPath = + '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Update 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<models.User> updateStatus() async { + final String apiPath = '/account/status'; + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create email token (OTP) + /// + /// Sends the user an email with a secret key for creating a session. If the + /// provided user ID has not be registered, a new user will be created. Use the + /// returned user ID and secret and submit a request to the [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The secret sent to the user's email + /// is valid for 15 minutes. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future<models.Token> createEmailToken( + {required String userId, required String email, bool? phrase}) async { + final String apiPath = '/account/tokens/email'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'email': email, + 'phrase': phrase, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// Create magic URL token + /// + /// Sends the user an email with a secret key for creating a session. If the + /// provided user ID has not been registered, a new user will be created. When + /// the user clicks the link in the email, the user is redirected back to the + /// URL you provided with the secret key and userId values attached to the URL + /// query string. Use the query string parameters to submit a request to the + /// [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The link sent to the user's email + /// address is valid for 1 hour. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + /// + Future<models.Token> createMagicURLToken( + {required String userId, + required String email, + String? url, + bool? phrase}) async { + final String apiPath = '/account/tokens/magic-url'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'email': email, + 'url': url, + 'phrase': phrase, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// Create OAuth2 token + /// + /// Allow the user to login to their account using the OAuth2 provider of their + /// choice. Each OAuth2 provider should be enabled from the Appwrite console + /// first. Use the success and failure arguments to provide a redirect URL's + /// back to your app when login is completed. + /// + /// If authentication succeeds, `userId` and `secret` of a token will be + /// appended to the success URL as query parameters. These can be used to + /// create a new session using the [Create + /// session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future createOAuth2Token( + {required enums.OAuthProvider provider, + String? success, + String? failure, + List<String>? scopes}) async { + final String apiPath = '/account/tokens/oauth2/{provider}' + .replaceAll('{provider}', provider.value); + + final Map<String, dynamic> params = { + 'success': success, + 'failure': failure, + 'scopes': scopes, + 'project': client.config['project'], + }; + + final List query = []; + + params.forEach((key, value) { + if (value is List) { + for (var item in value) { + query.add(Uri.encodeComponent(key + '[]') + + '=' + + Uri.encodeComponent(item)); + } + } else if (value != null) { + query.add(Uri.encodeComponent(key) + '=' + Uri.encodeComponent(value)); + } + }); + + Uri endpoint = Uri.parse(client.endPoint); + Uri url = Uri( + scheme: endpoint.scheme, + host: endpoint.host, + port: endpoint.port, + path: endpoint.path + apiPath, + query: query.join('&')); + + return client.webAuth(url); + } + + /// Create phone token + /// + /// Sends the user an SMS with a secret key for creating a session. If the + /// provided user ID has not be registered, a new user will be created. Use the + /// returned user ID and secret and submit a request to the [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The secret sent to the user's phone + /// is valid for 15 minutes. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future<models.Token> createPhoneToken( + {required String userId, required String phone}) async { + final String apiPath = '/account/tokens/phone'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'phone': phone, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// Create email verification + /// + /// Use this endpoint to send a verification message to your user email address + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). + /// 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<models.Token> createVerification({required String url}) async { + final String apiPath = '/account/verification'; + + final Map<String, dynamic> apiParams = { + 'url': url, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// Create email verification (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<models.Token> updateVerification( + {required String userId, required String secret}) async { + final String apiPath = '/account/verification'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'secret': secret, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone) + /// endpoint. Learn more about how to [complete the verification + /// process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification). + /// The verification code sent to the user's phone number is valid for 15 + /// minutes. + Future<models.Token> createPhoneVerification() async { + final String apiPath = '/account/verification/phone'; + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// Update 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<models.Token> updatePhoneVerification( + {required String userId, required String secret}) async { + final String apiPath = '/account/verification/phone'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'secret': secret, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } +} diff --git a/lib/services/avatars.dart b/lib/services/avatars.dart index 4609b00b..9c77eda6 100644 --- a/lib/services/avatars.dart +++ b/lib/services/avatars.dart @@ -3,201 +3,209 @@ part of '../dart_appwrite.dart'; /// The Avatars service aims to help you complete everyday tasks related to /// your app image, icons, and avatars. class Avatars extends Service { - Avatars(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](https://appwrite.io/docs/references/cloud/client-web/account#getSessions) - /// 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<Uint8List> getBrowser({required enums.Browser code, int? width, int? height, int? quality}) async { - final String apiPath = '/avatars/browsers/{code}'.replaceAll('{code}', code.value); - - final Map<String, dynamic> params = { - 'width': width, -'height': height, -'quality': quality, - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, 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<Uint8List> getCreditCard({required enums.CreditCard code, int? width, int? height, int? quality}) async { - final String apiPath = '/avatars/credit-cards/{code}'.replaceAll('{code}', code.value); - - final Map<String, dynamic> params = { - 'width': width, -'height': height, -'quality': quality, - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, 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. - /// - /// This endpoint does not follow HTTP redirects. - Future<Uint8List> getFavicon({required String url}) async { - final String apiPath = '/avatars/favicon'; - - final Map<String, dynamic> params = { - 'url': url, - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, 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. Country codes - /// follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard. - /// - /// 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<Uint8List> getFlag({required enums.Flag code, int? width, int? height, int? quality}) async { - final String apiPath = '/avatars/flags/{code}'.replaceAll('{code}', code.value); - - final Map<String, dynamic> params = { - 'width': width, -'height': height, -'quality': quality, - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, 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. - /// - /// This endpoint does not follow HTTP redirects. - Future<Uint8List> getImage({required String url, int? width, int? height}) async { - final String apiPath = '/avatars/image'; - - final Map<String, dynamic> params = { - 'url': url, -'width': width, -'height': height, - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, 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<Uint8List> getInitials({String? name, int? width, int? height, String? background}) async { - final String apiPath = '/avatars/initials'; - - final Map<String, dynamic> params = { - 'name': name, -'width': width, -'height': height, -'background': background, - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, 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<Uint8List> getQR({required String text, int? size, int? margin, bool? download}) async { - final String apiPath = '/avatars/qr'; - - final Map<String, dynamic> params = { - 'text': text, -'size': size, -'margin': margin, -'download': download, - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: params, responseType: ResponseType.bytes); - return res.data; - } -} \ No newline at end of file + Avatars(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](https://appwrite.io/docs/references/cloud/client-web/account#getSessions) + /// 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<Uint8List> getBrowser( + {required enums.Browser code, + int? width, + int? height, + int? quality}) async { + final String apiPath = + '/avatars/browsers/{code}'.replaceAll('{code}', code.value); + + final Map<String, dynamic> params = { + 'width': width, + 'height': height, + 'quality': quality, + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, 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<Uint8List> getCreditCard( + {required enums.CreditCard code, + int? width, + int? height, + int? quality}) async { + final String apiPath = + '/avatars/credit-cards/{code}'.replaceAll('{code}', code.value); + + final Map<String, dynamic> params = { + 'width': width, + 'height': height, + 'quality': quality, + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, 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. + /// + /// This endpoint does not follow HTTP redirects. + Future<Uint8List> getFavicon({required String url}) async { + final String apiPath = '/avatars/favicon'; + + final Map<String, dynamic> params = { + 'url': url, + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, 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. Country codes + /// follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard. + /// + /// 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<Uint8List> getFlag( + {required enums.Flag code, int? width, int? height, int? quality}) async { + final String apiPath = + '/avatars/flags/{code}'.replaceAll('{code}', code.value); + + final Map<String, dynamic> params = { + 'width': width, + 'height': height, + 'quality': quality, + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, 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. + /// + /// This endpoint does not follow HTTP redirects. + Future<Uint8List> getImage( + {required String url, int? width, int? height}) async { + final String apiPath = '/avatars/image'; + + final Map<String, dynamic> params = { + 'url': url, + 'width': width, + 'height': height, + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, 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<Uint8List> getInitials( + {String? name, int? width, int? height, String? background}) async { + final String apiPath = '/avatars/initials'; + + final Map<String, dynamic> params = { + 'name': name, + 'width': width, + 'height': height, + 'background': background, + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, 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<Uint8List> getQR( + {required String text, int? size, int? margin, bool? download}) async { + final String apiPath = '/avatars/qr'; + + final Map<String, dynamic> params = { + 'text': text, + 'size': size, + 'margin': margin, + 'download': download, + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: params, responseType: ResponseType.bytes); + return res.data; + } +} diff --git a/lib/services/databases.dart b/lib/services/databases.dart index 6d74eb4b..5d3a8c86 100644 --- a/lib/services/databases.dart +++ b/lib/services/databases.dart @@ -3,1093 +3,1280 @@ part of '../dart_appwrite.dart'; /// The Databases service allows you to create structured collections of /// documents, query and filter lists of documents class Databases extends Service { - Databases(super.client); - - /// List databases - /// - /// Get a list of all databases from the current Appwrite project. You can use - /// the search parameter to filter your results. - Future<models.DatabaseList> list({List<String>? queries, String? search}) async { - final String apiPath = '/databases'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.DatabaseList.fromMap(res.data); - - } - - /// Create database - /// - /// Create a new Database. - /// - Future<models.Database> create({required String databaseId, required String name, bool? enabled}) async { - final String apiPath = '/databases'; - - final Map<String, dynamic> apiParams = { - - 'databaseId': databaseId, -'name': name, -'enabled': enabled, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Database.fromMap(res.data); - - } - - /// Get database - /// - /// Get a database by its unique ID. This endpoint response returns a JSON - /// object with the database metadata. - Future<models.Database> get({required String databaseId}) async { - final String apiPath = '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Database.fromMap(res.data); - - } - - /// Update database - /// - /// Update a database by its unique ID. - Future<models.Database> update({required String databaseId, required String name, bool? enabled}) async { - final String apiPath = '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); - - final Map<String, dynamic> apiParams = { - - 'name': name, -'enabled': enabled, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Database.fromMap(res.data); - - } - - /// Delete database - /// - /// Delete a database by its unique ID. Only API keys with with databases.write - /// scope can delete a database. - Future delete({required String databaseId}) async { - final String apiPath = '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List collections - /// - /// Get a list of all collections that belong to the provided databaseId. You - /// can use the search parameter to filter your results. - Future<models.CollectionList> listCollections({required String databaseId, List<String>? queries, String? search}) async { - final String apiPath = '/databases/{databaseId}/collections'.replaceAll('{databaseId}', databaseId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.CollectionList.fromMap(res.data); - - } - - /// Create collection - /// - /// Create a new Collection. Before using this route, you should create a new - /// database resource using either a [server - /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) - /// API or directly from your database console. - Future<models.Collection> createCollection({required String databaseId, required String collectionId, required String name, List<String>? permissions, bool? documentSecurity, bool? enabled}) async { - final String apiPath = '/databases/{databaseId}/collections'.replaceAll('{databaseId}', databaseId); - - final Map<String, dynamic> apiParams = { - - 'collectionId': collectionId, -'name': name, -'permissions': permissions, -'documentSecurity': documentSecurity, -'enabled': enabled, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Collection.fromMap(res.data); - - } - - /// Get collection - /// - /// Get a collection by its unique ID. This endpoint response returns a JSON - /// object with the collection metadata. - Future<models.Collection> getCollection({required String databaseId, required String collectionId}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Collection.fromMap(res.data); - - } - - /// Update collection - /// - /// Update a collection by its unique ID. - Future<models.Collection> updateCollection({required String databaseId, required String collectionId, required String name, List<String>? permissions, bool? documentSecurity, bool? enabled}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - - 'name': name, -'permissions': permissions, -'documentSecurity': documentSecurity, -'enabled': enabled, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Collection.fromMap(res.data); - - } - - /// Delete collection - /// - /// Delete a collection by its unique ID. Only users with write permissions - /// have access to delete this resource. - Future deleteCollection({required String databaseId, required String collectionId}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List attributes - /// - /// List attributes in the collection. - Future<models.AttributeList> listAttributes({required String databaseId, required String collectionId, List<String>? queries}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeList.fromMap(res.data); - - } - - /// Create boolean attribute - /// - /// Create a boolean attribute. - /// - Future<models.AttributeBoolean> createBooleanAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, bool? xdefault, bool? array}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/boolean'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - - 'key': key, -'required': xrequired, -'default': xdefault, -'array': array, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeBoolean.fromMap(res.data); - - } - - /// Update boolean attribute - /// - /// Update a boolean attribute. Changing the `default` value will not update - /// already existing documents. - Future<models.AttributeBoolean> updateBooleanAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required bool? xdefault, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/boolean/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - - 'required': xrequired, -'default': xdefault, -'newKey': newKey, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeBoolean.fromMap(res.data); - - } - - /// Create datetime attribute - /// - /// Create a date time attribute according to the ISO 8601 standard. - Future<models.AttributeDatetime> createDatetimeAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/datetime'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - - 'key': key, -'required': xrequired, -'default': xdefault, -'array': array, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeDatetime.fromMap(res.data); - - } - - /// Update dateTime attribute - /// - /// Update a date time attribute. Changing the `default` value will not update - /// already existing documents. - Future<models.AttributeDatetime> updateDatetimeAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/datetime/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - - 'required': xrequired, -'default': xdefault, -'newKey': newKey, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeDatetime.fromMap(res.data); - - } - - /// Create email attribute - /// - /// Create an email attribute. - /// - Future<models.AttributeEmail> createEmailAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/email'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - - 'key': key, -'required': xrequired, -'default': xdefault, -'array': array, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEmail.fromMap(res.data); - - } - - /// Update email attribute - /// - /// Update an email attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future<models.AttributeEmail> updateEmailAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/email/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - - 'required': xrequired, -'default': xdefault, -'newKey': newKey, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEmail.fromMap(res.data); - - } - - /// Create enum attribute - /// - /// Create an enumeration attribute. The `elements` param acts as a white-list - /// of accepted values for this attribute. - /// - Future<models.AttributeEnum> createEnumAttribute({required String databaseId, required String collectionId, required String key, required List<String> elements, required bool xrequired, String? xdefault, bool? array}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/enum'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - - 'key': key, -'elements': elements, -'required': xrequired, -'default': xdefault, -'array': array, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEnum.fromMap(res.data); - - } - - /// Update enum attribute - /// - /// Update an enum attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future<models.AttributeEnum> updateEnumAttribute({required String databaseId, required String collectionId, required String key, required List<String> elements, required bool xrequired, required String? xdefault, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/enum/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - - 'elements': elements, -'required': xrequired, -'default': xdefault, -'newKey': newKey, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEnum.fromMap(res.data); - - } - - /// Create float attribute - /// - /// Create a float attribute. Optionally, minimum and maximum values can be - /// provided. - /// - Future<models.AttributeFloat> createFloatAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, double? min, double? max, double? xdefault, bool? array}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/float'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - - 'key': key, -'required': xrequired, -'min': min, -'max': max, -'default': xdefault, -'array': array, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeFloat.fromMap(res.data); - - } - - /// Update float attribute - /// - /// Update a float attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future<models.AttributeFloat> updateFloatAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required double min, required double max, required double? xdefault, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/float/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - - 'required': xrequired, -'min': min, -'max': max, -'default': xdefault, -'newKey': newKey, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeFloat.fromMap(res.data); - - } - - /// Create integer attribute - /// - /// Create an integer attribute. Optionally, minimum and maximum values can be - /// provided. - /// - Future<models.AttributeInteger> createIntegerAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, int? min, int? max, int? xdefault, bool? array}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/integer'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - - 'key': key, -'required': xrequired, -'min': min, -'max': max, -'default': xdefault, -'array': array, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeInteger.fromMap(res.data); - - } - - /// Update integer attribute - /// - /// Update an integer attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future<models.AttributeInteger> updateIntegerAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required int min, required int max, required int? xdefault, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/integer/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - - 'required': xrequired, -'min': min, -'max': max, -'default': xdefault, -'newKey': newKey, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeInteger.fromMap(res.data); - - } - - /// Create IP address attribute - /// - /// Create IP address attribute. - /// - Future<models.AttributeIp> createIpAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/ip'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - - 'key': key, -'required': xrequired, -'default': xdefault, -'array': array, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeIp.fromMap(res.data); - - } - - /// Update IP address attribute - /// - /// Update an ip attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future<models.AttributeIp> updateIpAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/ip/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - - 'required': xrequired, -'default': xdefault, -'newKey': newKey, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeIp.fromMap(res.data); - - } - - /// Create relationship attribute - /// - /// Create relationship attribute. [Learn more about relationship - /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). - /// - Future<models.AttributeRelationship> createRelationshipAttribute({required String databaseId, required String collectionId, required String relatedCollectionId, required enums.RelationshipType type, bool? twoWay, String? key, String? twoWayKey, enums.RelationMutate? onDelete}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/relationship'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - - 'relatedCollectionId': relatedCollectionId, -'type': type.value, -'twoWay': twoWay, -'key': key, -'twoWayKey': twoWayKey, -'onDelete': onDelete?.value, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeRelationship.fromMap(res.data); - - } - - /// Create string attribute - /// - /// Create a string attribute. - /// - Future<models.AttributeString> createStringAttribute({required String databaseId, required String collectionId, required String key, required int size, required bool xrequired, String? xdefault, bool? array, bool? encrypt}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/string'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - - 'key': key, -'size': size, -'required': xrequired, -'default': xdefault, -'array': array, -'encrypt': encrypt, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeString.fromMap(res.data); - - } - - /// Update string attribute - /// - /// Update a string attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future<models.AttributeString> updateStringAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, int? size, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/string/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - - 'required': xrequired, -'default': xdefault, -'size': size, -'newKey': newKey, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeString.fromMap(res.data); - - } - - /// Create URL attribute - /// - /// Create a URL attribute. - /// - Future<models.AttributeUrl> createUrlAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/url'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - - 'key': key, -'required': xrequired, -'default': xdefault, -'array': array, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeUrl.fromMap(res.data); - - } - - /// Update URL attribute - /// - /// Update an url attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future<models.AttributeUrl> updateUrlAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/url/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - - 'required': xrequired, -'default': xdefault, -'newKey': newKey, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeUrl.fromMap(res.data); - - } - - /// Get attribute - /// - /// Get attribute by ID. - Future getAttribute({required String databaseId, required String collectionId, required String key}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Delete attribute - /// - /// Deletes an attribute. - Future deleteAttribute({required String databaseId, required String collectionId, required String key}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Update relationship attribute - /// - /// Update relationship attribute. [Learn more about relationship - /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). - /// - Future<models.AttributeRelationship> updateRelationshipAttribute({required String databaseId, required String collectionId, required String key, enums.RelationMutate? onDelete, String? newKey}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}/relationship'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - - 'onDelete': onDelete?.value, -'newKey': newKey, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeRelationship.fromMap(res.data); - - } - - /// List documents - /// - /// Get a list of all the user's documents in a given collection. You can use - /// the query params to filter your results. - Future<models.DocumentList> listDocuments({required String databaseId, required String collectionId, List<String>? queries}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.DocumentList.fromMap(res.data); - - } - - /// Create document - /// - /// Create a new Document. Before using this route, you should create a new - /// collection resource using either a [server - /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) - /// API or directly from your database console. - Future<models.Document> createDocument({required String databaseId, required String collectionId, required String documentId, required Map data, List<String>? permissions}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - - 'documentId': documentId, -'data': data, -'permissions': permissions, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Document.fromMap(res.data); - - } - - /// Get document - /// - /// Get a document by its unique ID. This endpoint response returns a JSON - /// object with the document data. - Future<models.Document> getDocument({required String databaseId, required String collectionId, required String documentId, List<String>? queries}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Document.fromMap(res.data); - - } - - /// Update document - /// - /// Update a document by its unique ID. Using the patch method you can pass - /// only specific fields that will get updated. - Future<models.Document> updateDocument({required String databaseId, required String collectionId, required String documentId, Map? data, List<String>? permissions}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); - - final Map<String, dynamic> apiParams = { - - 'data': data, -'permissions': permissions, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Document.fromMap(res.data); - - } - - /// Delete document - /// - /// Delete a document by its unique ID. - Future deleteDocument({required String databaseId, required String collectionId, required String documentId}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List indexes - /// - /// List indexes in the collection. - Future<models.IndexList> listIndexes({required String databaseId, required String collectionId, List<String>? queries}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.IndexList.fromMap(res.data); - - } - - /// Create index - /// - /// Creates an index on the attributes listed. Your index should include all - /// the attributes you will query in a single request. - /// Attributes can be `key`, `fulltext`, and `unique`. - Future<models.Index> createIndex({required String databaseId, required String collectionId, required String key, required enums.IndexType type, required List<String> attributes, List<String>? orders}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - - 'key': key, -'type': type.value, -'attributes': attributes, -'orders': orders, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Index.fromMap(res.data); - - } - - /// Get index - /// - /// Get index by ID. - Future<models.Index> getIndex({required String databaseId, required String collectionId, required String key}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Index.fromMap(res.data); - - } - - /// Delete index - /// - /// Delete an index. - Future deleteIndex({required String databaseId, required String collectionId, required String key}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } -} \ No newline at end of file + Databases(super.client); + + /// List databases + /// + /// Get a list of all databases from the current Appwrite project. You can use + /// the search parameter to filter your results. + Future<models.DatabaseList> list( + {List<String>? queries, String? search}) async { + final String apiPath = '/databases'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DatabaseList.fromMap(res.data); + } + + /// Create database + /// + /// Create a new Database. + /// + Future<models.Database> create( + {required String databaseId, required String name, bool? enabled}) async { + final String apiPath = '/databases'; + + final Map<String, dynamic> apiParams = { + 'databaseId': databaseId, + 'name': name, + 'enabled': enabled, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Database.fromMap(res.data); + } + + /// Get database + /// + /// Get a database by its unique ID. This endpoint response returns a JSON + /// object with the database metadata. + Future<models.Database> get({required String databaseId}) async { + final String apiPath = + '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Database.fromMap(res.data); + } + + /// Update database + /// + /// Update a database by its unique ID. + Future<models.Database> update( + {required String databaseId, required String name, bool? enabled}) async { + final String apiPath = + '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); + + final Map<String, dynamic> apiParams = { + 'name': name, + 'enabled': enabled, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Database.fromMap(res.data); + } + + /// Delete database + /// + /// Delete a database by its unique ID. Only API keys with with databases.write + /// scope can delete a database. + Future delete({required String databaseId}) async { + final String apiPath = + '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List collections + /// + /// Get a list of all collections that belong to the provided databaseId. You + /// can use the search parameter to filter your results. + Future<models.CollectionList> listCollections( + {required String databaseId, + List<String>? queries, + String? search}) async { + final String apiPath = '/databases/{databaseId}/collections' + .replaceAll('{databaseId}', databaseId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.CollectionList.fromMap(res.data); + } + + /// Create collection + /// + /// Create a new Collection. Before using this route, you should create a new + /// database resource using either a [server + /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) + /// API or directly from your database console. + Future<models.Collection> createCollection( + {required String databaseId, + required String collectionId, + required String name, + List<String>? permissions, + bool? documentSecurity, + bool? enabled}) async { + final String apiPath = '/databases/{databaseId}/collections' + .replaceAll('{databaseId}', databaseId); + + final Map<String, dynamic> apiParams = { + 'collectionId': collectionId, + 'name': name, + 'permissions': permissions, + 'documentSecurity': documentSecurity, + 'enabled': enabled, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Collection.fromMap(res.data); + } + + /// Get collection + /// + /// Get a collection by its unique ID. This endpoint response returns a JSON + /// object with the collection metadata. + Future<models.Collection> getCollection( + {required String databaseId, required String collectionId}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Collection.fromMap(res.data); + } + + /// Update collection + /// + /// Update a collection by its unique ID. + Future<models.Collection> updateCollection( + {required String databaseId, + required String collectionId, + required String name, + List<String>? permissions, + bool? documentSecurity, + bool? enabled}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'name': name, + 'permissions': permissions, + 'documentSecurity': documentSecurity, + 'enabled': enabled, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Collection.fromMap(res.data); + } + + /// Delete collection + /// + /// Delete a collection by its unique ID. Only users with write permissions + /// have access to delete this resource. + Future deleteCollection( + {required String databaseId, required String collectionId}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List attributes + /// + /// List attributes in the collection. + Future<models.AttributeList> listAttributes( + {required String databaseId, + required String collectionId, + List<String>? queries}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeList.fromMap(res.data); + } + + /// Create boolean attribute + /// + /// Create a boolean attribute. + /// + Future<models.AttributeBoolean> createBooleanAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + bool? xdefault, + bool? array}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/boolean' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'key': key, + 'required': xrequired, + 'default': xdefault, + 'array': array, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeBoolean.fromMap(res.data); + } + + /// Update boolean attribute + /// + /// Update a boolean attribute. Changing the `default` value will not update + /// already existing documents. + Future<models.AttributeBoolean> updateBooleanAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + required bool? xdefault, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/boolean/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + 'required': xrequired, + 'default': xdefault, + 'newKey': newKey, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeBoolean.fromMap(res.data); + } + + /// Create datetime attribute + /// + /// Create a date time attribute according to the ISO 8601 standard. + Future<models.AttributeDatetime> createDatetimeAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + String? xdefault, + bool? array}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/datetime' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'key': key, + 'required': xrequired, + 'default': xdefault, + 'array': array, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeDatetime.fromMap(res.data); + } + + /// Update dateTime attribute + /// + /// Update a date time attribute. Changing the `default` value will not update + /// already existing documents. + Future<models.AttributeDatetime> updateDatetimeAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + required String? xdefault, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/datetime/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + 'required': xrequired, + 'default': xdefault, + 'newKey': newKey, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeDatetime.fromMap(res.data); + } + + /// Create email attribute + /// + /// Create an email attribute. + /// + Future<models.AttributeEmail> createEmailAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + String? xdefault, + bool? array}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/email' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'key': key, + 'required': xrequired, + 'default': xdefault, + 'array': array, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEmail.fromMap(res.data); + } + + /// Update email attribute + /// + /// Update an email attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future<models.AttributeEmail> updateEmailAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + required String? xdefault, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/email/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + 'required': xrequired, + 'default': xdefault, + 'newKey': newKey, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEmail.fromMap(res.data); + } + + /// Create enum attribute + /// + /// Create an enumeration attribute. The `elements` param acts as a white-list + /// of accepted values for this attribute. + /// + Future<models.AttributeEnum> createEnumAttribute( + {required String databaseId, + required String collectionId, + required String key, + required List<String> elements, + required bool xrequired, + String? xdefault, + bool? array}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/enum' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'key': key, + 'elements': elements, + 'required': xrequired, + 'default': xdefault, + 'array': array, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEnum.fromMap(res.data); + } + + /// Update enum attribute + /// + /// Update an enum attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future<models.AttributeEnum> updateEnumAttribute( + {required String databaseId, + required String collectionId, + required String key, + required List<String> elements, + required bool xrequired, + required String? xdefault, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/enum/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + 'elements': elements, + 'required': xrequired, + 'default': xdefault, + 'newKey': newKey, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEnum.fromMap(res.data); + } + + /// Create float attribute + /// + /// Create a float attribute. Optionally, minimum and maximum values can be + /// provided. + /// + Future<models.AttributeFloat> createFloatAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + double? min, + double? max, + double? xdefault, + bool? array}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/float' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'key': key, + 'required': xrequired, + 'min': min, + 'max': max, + 'default': xdefault, + 'array': array, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeFloat.fromMap(res.data); + } + + /// Update float attribute + /// + /// Update a float attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future<models.AttributeFloat> updateFloatAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + required double min, + required double max, + required double? xdefault, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/float/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + 'required': xrequired, + 'min': min, + 'max': max, + 'default': xdefault, + 'newKey': newKey, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeFloat.fromMap(res.data); + } + + /// Create integer attribute + /// + /// Create an integer attribute. Optionally, minimum and maximum values can be + /// provided. + /// + Future<models.AttributeInteger> createIntegerAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + int? min, + int? max, + int? xdefault, + bool? array}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/integer' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'key': key, + 'required': xrequired, + 'min': min, + 'max': max, + 'default': xdefault, + 'array': array, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeInteger.fromMap(res.data); + } + + /// Update integer attribute + /// + /// Update an integer attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future<models.AttributeInteger> updateIntegerAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + required int min, + required int max, + required int? xdefault, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/integer/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + 'required': xrequired, + 'min': min, + 'max': max, + 'default': xdefault, + 'newKey': newKey, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeInteger.fromMap(res.data); + } + + /// Create IP address attribute + /// + /// Create IP address attribute. + /// + Future<models.AttributeIp> createIpAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + String? xdefault, + bool? array}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/ip' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'key': key, + 'required': xrequired, + 'default': xdefault, + 'array': array, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeIp.fromMap(res.data); + } + + /// Update IP address attribute + /// + /// Update an ip attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future<models.AttributeIp> updateIpAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + required String? xdefault, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/ip/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + 'required': xrequired, + 'default': xdefault, + 'newKey': newKey, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeIp.fromMap(res.data); + } + + /// Create relationship attribute + /// + /// Create relationship attribute. [Learn more about relationship + /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). + /// + Future<models.AttributeRelationship> createRelationshipAttribute( + {required String databaseId, + required String collectionId, + required String relatedCollectionId, + required enums.RelationshipType type, + bool? twoWay, + String? key, + String? twoWayKey, + enums.RelationMutate? onDelete}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/relationship' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'relatedCollectionId': relatedCollectionId, + 'type': type.value, + 'twoWay': twoWay, + 'key': key, + 'twoWayKey': twoWayKey, + 'onDelete': onDelete?.value, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeRelationship.fromMap(res.data); + } + + /// Create string attribute + /// + /// Create a string attribute. + /// + Future<models.AttributeString> createStringAttribute( + {required String databaseId, + required String collectionId, + required String key, + required int size, + required bool xrequired, + String? xdefault, + bool? array, + bool? encrypt}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/string' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'key': key, + 'size': size, + 'required': xrequired, + 'default': xdefault, + 'array': array, + 'encrypt': encrypt, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeString.fromMap(res.data); + } + + /// Update string attribute + /// + /// Update a string attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future<models.AttributeString> updateStringAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + required String? xdefault, + int? size, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/string/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + 'required': xrequired, + 'default': xdefault, + 'size': size, + 'newKey': newKey, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeString.fromMap(res.data); + } + + /// Create URL attribute + /// + /// Create a URL attribute. + /// + Future<models.AttributeUrl> createUrlAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + String? xdefault, + bool? array}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/url' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'key': key, + 'required': xrequired, + 'default': xdefault, + 'array': array, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeUrl.fromMap(res.data); + } + + /// Update URL attribute + /// + /// Update an url attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future<models.AttributeUrl> updateUrlAttribute( + {required String databaseId, + required String collectionId, + required String key, + required bool xrequired, + required String? xdefault, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/url/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + 'required': xrequired, + 'default': xdefault, + 'newKey': newKey, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeUrl.fromMap(res.data); + } + + /// Get attribute + /// + /// Get attribute by ID. + Future getAttribute( + {required String databaseId, + required String collectionId, + required String key}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Delete attribute + /// + /// Deletes an attribute. + Future deleteAttribute( + {required String databaseId, + required String collectionId, + required String key}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Update relationship attribute + /// + /// Update relationship attribute. [Learn more about relationship + /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). + /// + Future<models.AttributeRelationship> updateRelationshipAttribute( + {required String databaseId, + required String collectionId, + required String key, + enums.RelationMutate? onDelete, + String? newKey}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/attributes/{key}/relationship' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + 'onDelete': onDelete?.value, + 'newKey': newKey, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeRelationship.fromMap(res.data); + } + + /// List documents + /// + /// Get a list of all the user's documents in a given collection. You can use + /// the query params to filter your results. + Future<models.DocumentList> listDocuments( + {required String databaseId, + required String collectionId, + List<String>? queries}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/documents' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DocumentList.fromMap(res.data); + } + + /// Create document + /// + /// Create a new Document. Before using this route, you should create a new + /// collection resource using either a [server + /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) + /// API or directly from your database console. + Future<models.Document> createDocument( + {required String databaseId, + required String collectionId, + required String documentId, + required Map data, + List<String>? permissions}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/documents' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'documentId': documentId, + 'data': data, + 'permissions': permissions, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Document.fromMap(res.data); + } + + /// Get document + /// + /// Get a document by its unique ID. This endpoint response returns a JSON + /// object with the document data. + Future<models.Document> getDocument( + {required String databaseId, + required String collectionId, + required String documentId, + List<String>? queries}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{documentId}', documentId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Document.fromMap(res.data); + } + + /// Update document + /// + /// Update a document by its unique ID. Using the patch method you can pass + /// only specific fields that will get updated. + Future<models.Document> updateDocument( + {required String databaseId, + required String collectionId, + required String documentId, + Map? data, + List<String>? permissions}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{documentId}', documentId); + + final Map<String, dynamic> apiParams = { + 'data': data, + 'permissions': permissions, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Document.fromMap(res.data); + } + + /// Delete document + /// + /// Delete a document by its unique ID. + Future deleteDocument( + {required String databaseId, + required String collectionId, + required String documentId}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{documentId}', documentId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List indexes + /// + /// List indexes in the collection. + Future<models.IndexList> listIndexes( + {required String databaseId, + required String collectionId, + List<String>? queries}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/indexes' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.IndexList.fromMap(res.data); + } + + /// Create index + /// + /// Creates an index on the attributes listed. Your index should include all + /// the attributes you will query in a single request. + /// Attributes can be `key`, `fulltext`, and `unique`. + Future<models.Index> createIndex( + {required String databaseId, + required String collectionId, + required String key, + required enums.IndexType type, + required List<String> attributes, + List<String>? orders}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/indexes' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'key': key, + 'type': type.value, + 'attributes': attributes, + 'orders': orders, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Index.fromMap(res.data); + } + + /// Get index + /// + /// Get index by ID. + Future<models.Index> getIndex( + {required String databaseId, + required String collectionId, + required String key}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/indexes/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Index.fromMap(res.data); + } + + /// Delete index + /// + /// Delete an index. + Future deleteIndex( + {required String databaseId, + required String collectionId, + required String key}) async { + final String apiPath = + '/databases/{databaseId}/collections/{collectionId}/indexes/{key}' + .replaceAll('{databaseId}', databaseId) + .replaceAll('{collectionId}', collectionId) + .replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } +} diff --git a/lib/services/functions.dart b/lib/services/functions.dart index 374fd507..7a59547e 100644 --- a/lib/services/functions.dart +++ b/lib/services/functions.dart @@ -3,619 +3,649 @@ part of '../dart_appwrite.dart'; /// The Functions Service allows you view, create and manage your Cloud /// Functions. class Functions extends Service { - Functions(super.client); - - /// List functions - /// - /// Get a list of all the project's functions. You can use the query params to - /// filter your results. - Future<models.FunctionList> list({List<String>? queries, String? search}) async { - final String apiPath = '/functions'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.FunctionList.fromMap(res.data); - - } - - /// Create function - /// - /// Create a new function. You can pass a list of - /// [permissions](https://appwrite.io/docs/permissions) to allow different - /// project users or team with access to execute the function using the client - /// API. - Future<models.Func> create({required String functionId, required String name, required enums.Runtime runtime, List<String>? execute, List<String>? events, String? schedule, int? timeout, bool? enabled, bool? logging, String? entrypoint, String? commands, List<String>? scopes, String? installationId, String? providerRepositoryId, String? providerBranch, bool? providerSilentMode, String? providerRootDirectory, String? templateRepository, String? templateOwner, String? templateRootDirectory, String? templateVersion, String? specification}) async { - final String apiPath = '/functions'; - - final Map<String, dynamic> apiParams = { - - 'functionId': functionId, -'name': name, -'runtime': runtime.value, -'execute': execute, -'events': events, -'schedule': schedule, -'timeout': timeout, -'enabled': enabled, -'logging': logging, -'entrypoint': entrypoint, -'commands': commands, -'scopes': scopes, -'installationId': installationId, -'providerRepositoryId': providerRepositoryId, -'providerBranch': providerBranch, -'providerSilentMode': providerSilentMode, -'providerRootDirectory': providerRootDirectory, -'templateRepository': templateRepository, -'templateOwner': templateOwner, -'templateRootDirectory': templateRootDirectory, -'templateVersion': templateVersion, -'specification': specification, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - - } - - /// List runtimes - /// - /// Get a list of all runtimes that are currently active on your instance. - Future<models.RuntimeList> listRuntimes() async { - final String apiPath = '/functions/runtimes'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.RuntimeList.fromMap(res.data); - - } - - /// List available function runtime specifications - /// - /// List allowed function specifications for this instance. - /// - Future<models.SpecificationList> listSpecifications() async { - final String apiPath = '/functions/specifications'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SpecificationList.fromMap(res.data); - - } - - /// Get function - /// - /// Get a function by its unique ID. - Future<models.Func> get({required String functionId}) async { - final String apiPath = '/functions/{functionId}'.replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - - } - - /// Update function - /// - /// Update function by its unique ID. - Future<models.Func> update({required String functionId, required String name, enums.Runtime? runtime, List<String>? execute, List<String>? events, String? schedule, int? timeout, bool? enabled, bool? logging, String? entrypoint, String? commands, List<String>? scopes, String? installationId, String? providerRepositoryId, String? providerBranch, bool? providerSilentMode, String? providerRootDirectory, String? specification}) async { - final String apiPath = '/functions/{functionId}'.replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = { - - 'name': name, -'runtime': runtime?.value, -'execute': execute, -'events': events, -'schedule': schedule, -'timeout': timeout, -'enabled': enabled, -'logging': logging, -'entrypoint': entrypoint, -'commands': commands, -'scopes': scopes, -'installationId': installationId, -'providerRepositoryId': providerRepositoryId, -'providerBranch': providerBranch, -'providerSilentMode': providerSilentMode, -'providerRootDirectory': providerRootDirectory, -'specification': specification, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - - } - - /// Delete function - /// - /// Delete a function by its unique ID. - Future delete({required String functionId}) async { - final String apiPath = '/functions/{functionId}'.replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List deployments - /// - /// Get a list of all the project's code deployments. You can use the query - /// params to filter your results. - Future<models.DeploymentList> listDeployments({required String functionId, List<String>? queries, String? search}) async { - final String apiPath = '/functions/{functionId}/deployments'.replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.DeploymentList.fromMap(res.data); - - } - - /// Create deployment - /// - /// Create a new function code deployment. Use this endpoint to upload a new - /// version of your code function. To execute your newly uploaded code, you'll - /// need to update the function's deployment to use your new deployment UID. - /// - /// This endpoint accepts a tar.gz file compressed with your code. Make sure to - /// include any dependencies your code has within the compressed file. You can - /// learn more about code packaging in the [Appwrite Cloud Functions - /// tutorial](https://appwrite.io/docs/functions). - /// - /// Use the "command" param to set the entrypoint used to execute your code. - Future<models.Deployment> createDeployment({required String functionId, required InputFile code, required bool activate, String? entrypoint, String? commands, Function(UploadProgress)? onProgress}) async { - final String apiPath = '/functions/{functionId}/deployments'.replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = { - - 'entrypoint': entrypoint, -'commands': commands, -'code': code, -'activate': activate, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'multipart/form-data', - - }; - - String idParamName = ''; - final paramName = 'code'; - final res = await client.chunkedUpload( - path: apiPath, - params: apiParams, - paramName: paramName, - idParamName: idParamName, - headers: apiHeaders, - onProgress: onProgress, - ); - - return models.Deployment.fromMap(res.data); - - } - - /// Get deployment - /// - /// Get a code deployment by its unique ID. - Future<models.Deployment> getDeployment({required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Deployment.fromMap(res.data); - - } - - /// Update deployment - /// - /// Update the function code deployment ID using the unique function ID. Use - /// this endpoint to switch the code deployment that should be executed by the - /// execution endpoint. - Future<models.Func> updateDeployment({required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - - } - - /// Delete deployment - /// - /// Delete a code deployment by its unique ID. - Future deleteDeployment({required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Rebuild deployment - /// - Future createBuild({required String functionId, required String deploymentId, String? buildId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}/build'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); - - final Map<String, dynamic> apiParams = { - - 'buildId': buildId, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Cancel deployment - /// - Future<models.Build> updateDeploymentBuild({required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}/build'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Build.fromMap(res.data); - - } - - /// Download deployment - /// - /// Get a Deployment's contents by its unique ID. This endpoint supports range - /// requests for partial or streaming file download. - Future<Uint8List> getDeploymentDownload({required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}/download'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); - - final Map<String, dynamic> params = { - - - 'project': client.config['project'], - 'key': client.config['key'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: params, responseType: ResponseType.bytes); - 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. - Future<models.ExecutionList> listExecutions({required String functionId, List<String>? queries, String? search}) async { - final String apiPath = '/functions/{functionId}/executions'.replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - 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<models.Execution> createExecution({required String functionId, String? body, bool? xasync, String? path, enums.ExecutionMethod? method, Map? headers, String? scheduledAt}) async { - final String apiPath = '/functions/{functionId}/executions'.replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = { - - 'body': body, -'async': xasync, -'path': path, -'method': method?.value, -'headers': headers, -'scheduledAt': scheduledAt, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Execution.fromMap(res.data); - - } - - /// Get execution - /// - /// Get a function execution log by its unique ID. - Future<models.Execution> getExecution({required String functionId, required String executionId}) async { - final String apiPath = '/functions/{functionId}/executions/{executionId}'.replaceAll('{functionId}', functionId).replaceAll('{executionId}', executionId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Execution.fromMap(res.data); - - } - - /// Delete execution - /// - /// Delete a function execution by its unique ID. - /// - Future deleteExecution({required String functionId, required String executionId}) async { - final String apiPath = '/functions/{functionId}/executions/{executionId}'.replaceAll('{functionId}', functionId).replaceAll('{executionId}', executionId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List variables - /// - /// Get a list of all variables of a specific function. - Future<models.VariableList> listVariables({required String functionId}) async { - final String apiPath = '/functions/{functionId}/variables'.replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.VariableList.fromMap(res.data); - - } - - /// Create variable - /// - /// Create a new function environment variable. These variables can be accessed - /// in the function at runtime as environment variables. - Future<models.Variable> createVariable({required String functionId, required String key, required String value}) async { - final String apiPath = '/functions/{functionId}/variables'.replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = { - - 'key': key, -'value': value, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Variable.fromMap(res.data); - - } - - /// Get variable - /// - /// Get a variable by its unique ID. - Future<models.Variable> getVariable({required String functionId, required String variableId}) async { - final String apiPath = '/functions/{functionId}/variables/{variableId}'.replaceAll('{functionId}', functionId).replaceAll('{variableId}', variableId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Variable.fromMap(res.data); - - } - - /// Update variable - /// - /// Update variable by its unique ID. - Future<models.Variable> updateVariable({required String functionId, required String variableId, required String key, String? value}) async { - final String apiPath = '/functions/{functionId}/variables/{variableId}'.replaceAll('{functionId}', functionId).replaceAll('{variableId}', variableId); - - final Map<String, dynamic> apiParams = { - - 'key': key, -'value': value, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Variable.fromMap(res.data); - - } - - /// Delete variable - /// - /// Delete a variable by its unique ID. - Future deleteVariable({required String functionId, required String variableId}) async { - final String apiPath = '/functions/{functionId}/variables/{variableId}'.replaceAll('{functionId}', functionId).replaceAll('{variableId}', variableId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } -} \ No newline at end of file + Functions(super.client); + + /// List functions + /// + /// Get a list of all the project's functions. You can use the query params to + /// filter your results. + Future<models.FunctionList> list( + {List<String>? queries, String? search}) async { + final String apiPath = '/functions'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.FunctionList.fromMap(res.data); + } + + /// Create function + /// + /// Create a new function. You can pass a list of + /// [permissions](https://appwrite.io/docs/permissions) to allow different + /// project users or team with access to execute the function using the client + /// API. + Future<models.Func> create( + {required String functionId, + required String name, + required enums.Runtime runtime, + List<String>? execute, + List<String>? events, + String? schedule, + int? timeout, + bool? enabled, + bool? logging, + String? entrypoint, + String? commands, + List<String>? scopes, + String? installationId, + String? providerRepositoryId, + String? providerBranch, + bool? providerSilentMode, + String? providerRootDirectory, + String? templateRepository, + String? templateOwner, + String? templateRootDirectory, + String? templateVersion, + String? specification}) async { + final String apiPath = '/functions'; + + final Map<String, dynamic> apiParams = { + 'functionId': functionId, + 'name': name, + 'runtime': runtime.value, + 'execute': execute, + 'events': events, + 'schedule': schedule, + 'timeout': timeout, + 'enabled': enabled, + 'logging': logging, + 'entrypoint': entrypoint, + 'commands': commands, + 'scopes': scopes, + 'installationId': installationId, + 'providerRepositoryId': providerRepositoryId, + 'providerBranch': providerBranch, + 'providerSilentMode': providerSilentMode, + 'providerRootDirectory': providerRootDirectory, + 'templateRepository': templateRepository, + 'templateOwner': templateOwner, + 'templateRootDirectory': templateRootDirectory, + 'templateVersion': templateVersion, + 'specification': specification, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + } + + /// List runtimes + /// + /// Get a list of all runtimes that are currently active on your instance. + Future<models.RuntimeList> listRuntimes() async { + final String apiPath = '/functions/runtimes'; + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.RuntimeList.fromMap(res.data); + } + + /// List available function runtime specifications + /// + /// List allowed function specifications for this instance. + /// + Future<models.SpecificationList> listSpecifications() async { + final String apiPath = '/functions/specifications'; + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SpecificationList.fromMap(res.data); + } + + /// Get function + /// + /// Get a function by its unique ID. + Future<models.Func> get({required String functionId}) async { + final String apiPath = + '/functions/{functionId}'.replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + } + + /// Update function + /// + /// Update function by its unique ID. + Future<models.Func> update( + {required String functionId, + required String name, + enums.Runtime? runtime, + List<String>? execute, + List<String>? events, + String? schedule, + int? timeout, + bool? enabled, + bool? logging, + String? entrypoint, + String? commands, + List<String>? scopes, + String? installationId, + String? providerRepositoryId, + String? providerBranch, + bool? providerSilentMode, + String? providerRootDirectory, + String? specification}) async { + final String apiPath = + '/functions/{functionId}'.replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = { + 'name': name, + 'runtime': runtime?.value, + 'execute': execute, + 'events': events, + 'schedule': schedule, + 'timeout': timeout, + 'enabled': enabled, + 'logging': logging, + 'entrypoint': entrypoint, + 'commands': commands, + 'scopes': scopes, + 'installationId': installationId, + 'providerRepositoryId': providerRepositoryId, + 'providerBranch': providerBranch, + 'providerSilentMode': providerSilentMode, + 'providerRootDirectory': providerRootDirectory, + 'specification': specification, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + } + + /// Delete function + /// + /// Delete a function by its unique ID. + Future delete({required String functionId}) async { + final String apiPath = + '/functions/{functionId}'.replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List deployments + /// + /// Get a list of all the project's code deployments. You can use the query + /// params to filter your results. + Future<models.DeploymentList> listDeployments( + {required String functionId, + List<String>? queries, + String? search}) async { + final String apiPath = '/functions/{functionId}/deployments' + .replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DeploymentList.fromMap(res.data); + } + + /// Create deployment + /// + /// Create a new function code deployment. Use this endpoint to upload a new + /// version of your code function. To execute your newly uploaded code, you'll + /// need to update the function's deployment to use your new deployment UID. + /// + /// This endpoint accepts a tar.gz file compressed with your code. Make sure to + /// include any dependencies your code has within the compressed file. You can + /// learn more about code packaging in the [Appwrite Cloud Functions + /// tutorial](https://appwrite.io/docs/functions). + /// + /// Use the "command" param to set the entrypoint used to execute your code. + Future<models.Deployment> createDeployment( + {required String functionId, + required InputFile code, + required bool activate, + String? entrypoint, + String? commands, + Function(UploadProgress)? onProgress}) async { + final String apiPath = '/functions/{functionId}/deployments' + .replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = { + 'entrypoint': entrypoint, + 'commands': commands, + 'code': code, + 'activate': activate, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'multipart/form-data', + }; + + String idParamName = ''; + final paramName = 'code'; + final res = await client.chunkedUpload( + path: apiPath, + params: apiParams, + paramName: paramName, + idParamName: idParamName, + headers: apiHeaders, + onProgress: onProgress, + ); + + return models.Deployment.fromMap(res.data); + } + + /// Get deployment + /// + /// Get a code deployment by its unique ID. + Future<models.Deployment> getDeployment( + {required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}' + .replaceAll('{functionId}', functionId) + .replaceAll('{deploymentId}', deploymentId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Deployment.fromMap(res.data); + } + + /// Update deployment + /// + /// Update the function code deployment ID using the unique function ID. Use + /// this endpoint to switch the code deployment that should be executed by the + /// execution endpoint. + Future<models.Func> updateDeployment( + {required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}' + .replaceAll('{functionId}', functionId) + .replaceAll('{deploymentId}', deploymentId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + } + + /// Delete deployment + /// + /// Delete a code deployment by its unique ID. + Future deleteDeployment( + {required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}' + .replaceAll('{functionId}', functionId) + .replaceAll('{deploymentId}', deploymentId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Rebuild deployment + /// + Future createBuild( + {required String functionId, + required String deploymentId, + String? buildId}) async { + final String apiPath = + '/functions/{functionId}/deployments/{deploymentId}/build' + .replaceAll('{functionId}', functionId) + .replaceAll('{deploymentId}', deploymentId); + + final Map<String, dynamic> apiParams = { + 'buildId': buildId, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Cancel deployment + /// + Future<models.Build> updateDeploymentBuild( + {required String functionId, required String deploymentId}) async { + final String apiPath = + '/functions/{functionId}/deployments/{deploymentId}/build' + .replaceAll('{functionId}', functionId) + .replaceAll('{deploymentId}', deploymentId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Build.fromMap(res.data); + } + + /// Download deployment + /// + /// Get a Deployment's contents by its unique ID. This endpoint supports range + /// requests for partial or streaming file download. + Future<Uint8List> getDeploymentDownload( + {required String functionId, required String deploymentId}) async { + final String apiPath = + '/functions/{functionId}/deployments/{deploymentId}/download' + .replaceAll('{functionId}', functionId) + .replaceAll('{deploymentId}', deploymentId); + + final Map<String, dynamic> params = { + 'project': client.config['project'], + 'key': client.config['key'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: params, responseType: ResponseType.bytes); + 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. + Future<models.ExecutionList> listExecutions( + {required String functionId, + List<String>? queries, + String? search}) async { + final String apiPath = '/functions/{functionId}/executions' + .replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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<models.Execution> createExecution( + {required String functionId, + String? body, + bool? xasync, + String? path, + enums.ExecutionMethod? method, + Map? headers, + String? scheduledAt}) async { + final String apiPath = '/functions/{functionId}/executions' + .replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = { + 'body': body, + 'async': xasync, + 'path': path, + 'method': method?.value, + 'headers': headers, + 'scheduledAt': scheduledAt, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Execution.fromMap(res.data); + } + + /// Get execution + /// + /// Get a function execution log by its unique ID. + Future<models.Execution> getExecution( + {required String functionId, required String executionId}) async { + final String apiPath = '/functions/{functionId}/executions/{executionId}' + .replaceAll('{functionId}', functionId) + .replaceAll('{executionId}', executionId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Execution.fromMap(res.data); + } + + /// Delete execution + /// + /// Delete a function execution by its unique ID. + /// + Future deleteExecution( + {required String functionId, required String executionId}) async { + final String apiPath = '/functions/{functionId}/executions/{executionId}' + .replaceAll('{functionId}', functionId) + .replaceAll('{executionId}', executionId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List variables + /// + /// Get a list of all variables of a specific function. + Future<models.VariableList> listVariables( + {required String functionId}) async { + final String apiPath = '/functions/{functionId}/variables' + .replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.VariableList.fromMap(res.data); + } + + /// Create variable + /// + /// Create a new function environment variable. These variables can be accessed + /// in the function at runtime as environment variables. + Future<models.Variable> createVariable( + {required String functionId, + required String key, + required String value}) async { + final String apiPath = '/functions/{functionId}/variables' + .replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = { + 'key': key, + 'value': value, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Variable.fromMap(res.data); + } + + /// Get variable + /// + /// Get a variable by its unique ID. + Future<models.Variable> getVariable( + {required String functionId, required String variableId}) async { + final String apiPath = '/functions/{functionId}/variables/{variableId}' + .replaceAll('{functionId}', functionId) + .replaceAll('{variableId}', variableId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Variable.fromMap(res.data); + } + + /// Update variable + /// + /// Update variable by its unique ID. + Future<models.Variable> updateVariable( + {required String functionId, + required String variableId, + required String key, + String? value}) async { + final String apiPath = '/functions/{functionId}/variables/{variableId}' + .replaceAll('{functionId}', functionId) + .replaceAll('{variableId}', variableId); + + final Map<String, dynamic> apiParams = { + 'key': key, + 'value': value, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Variable.fromMap(res.data); + } + + /// Delete variable + /// + /// Delete a variable by its unique ID. + Future deleteVariable( + {required String functionId, required String variableId}) async { + final String apiPath = '/functions/{functionId}/variables/{variableId}' + .replaceAll('{functionId}', functionId) + .replaceAll('{variableId}', variableId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } +} diff --git a/lib/services/graphql.dart b/lib/services/graphql.dart index be9d037b..fdc1ae0b 100644 --- a/lib/services/graphql.dart +++ b/lib/services/graphql.dart @@ -3,53 +3,47 @@ part of '../dart_appwrite.dart'; /// The GraphQL API allows you to query and mutate your Appwrite server using /// GraphQL. class Graphql extends Service { - Graphql(super.client); - - /// GraphQL endpoint - /// - /// Execute a GraphQL mutation. - Future query({required Map query}) async { - final String apiPath = '/graphql'; - - final Map<String, dynamic> apiParams = { - - 'query': query, - - }; - - final Map<String, String> apiHeaders = { - 'x-sdk-graphql': 'true', -'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// GraphQL endpoint - /// - /// Execute a GraphQL mutation. - Future mutation({required Map query}) async { - final String apiPath = '/graphql/mutation'; - - final Map<String, dynamic> apiParams = { - - 'query': query, - - }; - - final Map<String, String> apiHeaders = { - 'x-sdk-graphql': 'true', -'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } -} \ No newline at end of file + Graphql(super.client); + + /// GraphQL endpoint + /// + /// Execute a GraphQL mutation. + Future query({required Map query}) async { + final String apiPath = '/graphql'; + + final Map<String, dynamic> apiParams = { + 'query': query, + }; + + final Map<String, String> apiHeaders = { + 'x-sdk-graphql': 'true', + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// GraphQL endpoint + /// + /// Execute a GraphQL mutation. + Future mutation({required Map query}) async { + final String apiPath = '/graphql/mutation'; + + final Map<String, dynamic> apiParams = { + 'query': query, + }; + + final Map<String, String> apiHeaders = { + 'x-sdk-graphql': 'true', + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } +} diff --git a/lib/services/health.dart b/lib/services/health.dart index 4e7b4603..121083c0 100644 --- a/lib/services/health.dart +++ b/lib/services/health.dart @@ -3,548 +3,473 @@ part of '../dart_appwrite.dart'; /// The Health service allows you to both validate and monitor your Appwrite /// server's health. class Health extends Service { - Health(super.client); + Health(super.client); - /// Get HTTP - /// - /// Check the Appwrite HTTP server is up and responsive. - Future<models.HealthStatus> get() async { - final String apiPath = '/health'; + /// Get HTTP + /// + /// Check the Appwrite HTTP server is up and responsive. + Future<models.HealthStatus> get() async { + final String apiPath = '/health'; - final Map<String, dynamic> apiParams = { - - - }; + final Map<String, dynamic> apiParams = {}; - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; - }; + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + return models.HealthStatus.fromMap(res.data); + } - return models.HealthStatus.fromMap(res.data); + /// Get antivirus + /// + /// Check the Appwrite Antivirus server is up and connection is successful. + Future<models.HealthAntivirus> getAntivirus() async { + final String apiPath = '/health/anti-virus'; - } + final Map<String, dynamic> apiParams = {}; - /// Get antivirus - /// - /// Check the Appwrite Antivirus server is up and connection is successful. - Future<models.HealthAntivirus> getAntivirus() async { - final String apiPath = '/health/anti-virus'; + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; - final Map<String, dynamic> apiParams = { - - - }; + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', + return models.HealthAntivirus.fromMap(res.data); + } - }; + /// Get cache + /// + /// Check the Appwrite in-memory cache servers are up and connection is + /// successful. + Future<models.HealthStatus> getCache() async { + final String apiPath = '/health/cache'; - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + final Map<String, dynamic> apiParams = {}; - return models.HealthAntivirus.fromMap(res.data); + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; - } + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - /// Get cache - /// - /// Check the Appwrite in-memory cache servers are up and connection is - /// successful. - Future<models.HealthStatus> getCache() async { - final String apiPath = '/health/cache'; + return models.HealthStatus.fromMap(res.data); + } - final Map<String, dynamic> apiParams = { - - - }; + /// Get the SSL certificate for a domain + /// + /// Get the SSL certificate for a domain + Future<models.HealthCertificate> getCertificate({String? domain}) async { + final String apiPath = '/health/certificate'; - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', + final Map<String, dynamic> apiParams = { + 'domain': domain, + }; - }; + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - return models.HealthStatus.fromMap(res.data); + return models.HealthCertificate.fromMap(res.data); + } - } + /// Get DB + /// + /// Check the Appwrite database servers are up and connection is successful. + Future<models.HealthStatus> getDB() async { + final String apiPath = '/health/db'; - /// Get the SSL certificate for a domain - /// - /// Get the SSL certificate for a domain - Future<models.HealthCertificate> getCertificate({String? domain}) async { - final String apiPath = '/health/certificate'; + final Map<String, dynamic> apiParams = {}; - final Map<String, dynamic> apiParams = { - 'domain': domain, + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; - - }; + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', + return models.HealthStatus.fromMap(res.data); + } - }; + /// Get pubsub + /// + /// Check the Appwrite pub-sub servers are up and connection is successful. + Future<models.HealthStatus> getPubSub() async { + final String apiPath = '/health/pubsub'; - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + final Map<String, dynamic> apiParams = {}; - return models.HealthCertificate.fromMap(res.data); + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; - } + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - /// Get DB - /// - /// Check the Appwrite database servers are up and connection is successful. - Future<models.HealthStatus> getDB() async { - final String apiPath = '/health/db'; + return models.HealthStatus.fromMap(res.data); + } - final Map<String, dynamic> apiParams = { - - - }; + /// Get queue + /// + /// Check the Appwrite queue messaging servers are up and connection is + /// successful. + Future<models.HealthStatus> getQueue() async { + final String apiPath = '/health/queue'; - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', + final Map<String, dynamic> apiParams = {}; - }; + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthStatus.fromMap(res.data); + } - return models.HealthStatus.fromMap(res.data); + /// Get builds queue + /// + /// Get the number of builds that are waiting to be processed in the Appwrite + /// internal queue server. + Future<models.HealthQueue> getQueueBuilds({int? threshold}) async { + final String apiPath = '/health/queue/builds'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + }; - } + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get certificates queue + /// + /// Get the number of certificates that are waiting to be issued against + /// [Letsencrypt](https://letsencrypt.org/) in the Appwrite internal queue + /// server. + Future<models.HealthQueue> getQueueCertificates({int? threshold}) async { + final String apiPath = '/health/queue/certificates'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get databases queue + /// + /// Get the number of database changes that are waiting to be processed in the + /// Appwrite internal queue server. + Future<models.HealthQueue> getQueueDatabases( + {String? name, int? threshold}) async { + final String apiPath = '/health/queue/databases'; + + final Map<String, dynamic> apiParams = { + 'name': name, + 'threshold': threshold, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get deletes queue + /// + /// Get the number of background destructive changes that are waiting to be + /// processed in the Appwrite internal queue server. + Future<models.HealthQueue> getQueueDeletes({int? threshold}) async { + final String apiPath = '/health/queue/deletes'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get number of failed queue jobs + /// + /// Returns the amount of failed jobs in a given queue. + /// + Future<models.HealthQueue> getFailedJobs( + {required enums.Name name, int? threshold}) async { + final String apiPath = + '/health/queue/failed/{name}'.replaceAll('{name}', name.value); + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get functions queue + /// + /// Get the number of function executions that are waiting to be processed in + /// the Appwrite internal queue server. + Future<models.HealthQueue> getQueueFunctions({int? threshold}) async { + final String apiPath = '/health/queue/functions'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get logs queue + /// + /// Get the number of logs that are waiting to be processed in the Appwrite + /// internal queue server. + Future<models.HealthQueue> getQueueLogs({int? threshold}) async { + final String apiPath = '/health/queue/logs'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get mails queue + /// + /// Get the number of mails that are waiting to be processed in the Appwrite + /// internal queue server. + Future<models.HealthQueue> getQueueMails({int? threshold}) async { + final String apiPath = '/health/queue/mails'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get messaging queue + /// + /// Get the number of messages that are waiting to be processed in the Appwrite + /// internal queue server. + Future<models.HealthQueue> getQueueMessaging({int? threshold}) async { + final String apiPath = '/health/queue/messaging'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get migrations queue + /// + /// Get the number of migrations that are waiting to be processed in the + /// Appwrite internal queue server. + Future<models.HealthQueue> getQueueMigrations({int? threshold}) async { + final String apiPath = '/health/queue/migrations'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } - /// Get pubsub - /// - /// Check the Appwrite pub-sub servers are up and connection is successful. - Future<models.HealthStatus> getPubSub() async { - final String apiPath = '/health/pubsub'; + /// Get usage queue + /// + /// Get the number of metrics that are waiting to be processed in the Appwrite + /// internal queue server. + Future<models.HealthQueue> getQueueUsage({int? threshold}) async { + final String apiPath = '/health/queue/usage'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get usage dump queue + /// + /// Get the number of projects containing metrics that are waiting to be + /// processed in the Appwrite internal queue server. + Future<models.HealthQueue> getQueueUsageDump({int? threshold}) async { + final String apiPath = '/health/queue/usage-dump'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get webhooks queue + /// + /// Get the number of webhooks that are waiting to be processed in the Appwrite + /// internal queue server. + Future<models.HealthQueue> getQueueWebhooks({int? threshold}) async { + final String apiPath = '/health/queue/webhooks'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + } + + /// Get storage + /// + /// Check the Appwrite storage device is up and connection is successful. + Future<models.HealthStatus> getStorage() async { + final String apiPath = '/health/storage'; - final Map<String, dynamic> apiParams = { - - - }; + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthStatus.fromMap(res.data); + } + + /// Get local storage + /// + /// Check the Appwrite local storage device is up and connection is successful. + Future<models.HealthStatus> getStorageLocal() async { + final String apiPath = '/health/storage/local'; + + final Map<String, dynamic> apiParams = {}; - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; - }; + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthStatus.fromMap(res.data); + } + + /// Get time + /// + /// Check the Appwrite server time is synced with Google remote NTP server. We + /// use this technology to smoothly handle leap seconds with no disruptive + /// events. The [Network Time + /// Protocol](https://en.wikipedia.org/wiki/Network_Time_Protocol) (NTP) is + /// used by hundreds of millions of computers and devices to synchronize their + /// clocks over the Internet. If your computer sets its own clock, it likely + /// uses NTP. + Future<models.HealthTime> getTime() async { + final String apiPath = '/health/time'; - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + final Map<String, dynamic> apiParams = {}; - return models.HealthStatus.fromMap(res.data); + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; - } - - /// Get queue - /// - /// Check the Appwrite queue messaging servers are up and connection is - /// successful. - Future<models.HealthStatus> getQueue() async { - final String apiPath = '/health/queue'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthStatus.fromMap(res.data); - - } - - /// Get builds queue - /// - /// Get the number of builds that are waiting to be processed in the Appwrite - /// internal queue server. - Future<models.HealthQueue> getQueueBuilds({int? threshold}) async { - final String apiPath = '/health/queue/builds'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get certificates queue - /// - /// Get the number of certificates that are waiting to be issued against - /// [Letsencrypt](https://letsencrypt.org/) in the Appwrite internal queue - /// server. - Future<models.HealthQueue> getQueueCertificates({int? threshold}) async { - final String apiPath = '/health/queue/certificates'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get databases queue - /// - /// Get the number of database changes that are waiting to be processed in the - /// Appwrite internal queue server. - Future<models.HealthQueue> getQueueDatabases({String? name, int? threshold}) async { - final String apiPath = '/health/queue/databases'; - - final Map<String, dynamic> apiParams = { - 'name': name, -'threshold': threshold, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get deletes queue - /// - /// Get the number of background destructive changes that are waiting to be - /// processed in the Appwrite internal queue server. - Future<models.HealthQueue> getQueueDeletes({int? threshold}) async { - final String apiPath = '/health/queue/deletes'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get number of failed queue jobs - /// - /// Returns the amount of failed jobs in a given queue. - /// - Future<models.HealthQueue> getFailedJobs({required enums.Name name, int? threshold}) async { - final String apiPath = '/health/queue/failed/{name}'.replaceAll('{name}', name.value); - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get functions queue - /// - /// Get the number of function executions that are waiting to be processed in - /// the Appwrite internal queue server. - Future<models.HealthQueue> getQueueFunctions({int? threshold}) async { - final String apiPath = '/health/queue/functions'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get logs queue - /// - /// Get the number of logs that are waiting to be processed in the Appwrite - /// internal queue server. - Future<models.HealthQueue> getQueueLogs({int? threshold}) async { - final String apiPath = '/health/queue/logs'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get mails queue - /// - /// Get the number of mails that are waiting to be processed in the Appwrite - /// internal queue server. - Future<models.HealthQueue> getQueueMails({int? threshold}) async { - final String apiPath = '/health/queue/mails'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get messaging queue - /// - /// Get the number of messages that are waiting to be processed in the Appwrite - /// internal queue server. - Future<models.HealthQueue> getQueueMessaging({int? threshold}) async { - final String apiPath = '/health/queue/messaging'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get migrations queue - /// - /// Get the number of migrations that are waiting to be processed in the - /// Appwrite internal queue server. - Future<models.HealthQueue> getQueueMigrations({int? threshold}) async { - final String apiPath = '/health/queue/migrations'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get usage queue - /// - /// Get the number of metrics that are waiting to be processed in the Appwrite - /// internal queue server. - Future<models.HealthQueue> getQueueUsage({int? threshold}) async { - final String apiPath = '/health/queue/usage'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get usage dump queue - /// - /// Get the number of projects containing metrics that are waiting to be - /// processed in the Appwrite internal queue server. - Future<models.HealthQueue> getQueueUsageDump({int? threshold}) async { - final String apiPath = '/health/queue/usage-dump'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get webhooks queue - /// - /// Get the number of webhooks that are waiting to be processed in the Appwrite - /// internal queue server. - Future<models.HealthQueue> getQueueWebhooks({int? threshold}) async { - final String apiPath = '/health/queue/webhooks'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - - } - - /// Get storage - /// - /// Check the Appwrite storage device is up and connection is successful. - Future<models.HealthStatus> getStorage() async { - final String apiPath = '/health/storage'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthStatus.fromMap(res.data); - - } - - /// Get local storage - /// - /// Check the Appwrite local storage device is up and connection is successful. - Future<models.HealthStatus> getStorageLocal() async { - final String apiPath = '/health/storage/local'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthStatus.fromMap(res.data); - - } - - /// Get time - /// - /// Check the Appwrite server time is synced with Google remote NTP server. We - /// use this technology to smoothly handle leap seconds with no disruptive - /// events. The [Network Time - /// Protocol](https://en.wikipedia.org/wiki/Network_Time_Protocol) (NTP) is - /// used by hundreds of millions of computers and devices to synchronize their - /// clocks over the Internet. If your computer sets its own clock, it likely - /// uses NTP. - Future<models.HealthTime> getTime() async { - final String apiPath = '/health/time'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthTime.fromMap(res.data); - - } -} \ No newline at end of file + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthTime.fromMap(res.data); + } +} diff --git a/lib/services/locale.dart b/lib/services/locale.dart index cf65a2f3..a7eaf3bb 100644 --- a/lib/services/locale.dart +++ b/lib/services/locale.dart @@ -3,194 +3,162 @@ part of '../dart_appwrite.dart'; /// The Locale service allows you to customize your app based on your users' /// location. class Locale extends Service { - Locale(super.client); + Locale(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<models.Locale> get() async { - final String apiPath = '/locale'; + /// 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<models.Locale> get() async { + final String apiPath = '/locale'; - final Map<String, dynamic> apiParams = { - - - }; + final Map<String, dynamic> apiParams = {}; - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; - }; + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + return models.Locale.fromMap(res.data); + } - return models.Locale.fromMap(res.data); + /// List locale codes + /// + /// List of all locale codes in [ISO + /// 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). + Future<models.LocaleCodeList> listCodes() async { + final String apiPath = '/locale/codes'; - } + final Map<String, dynamic> apiParams = {}; - /// List locale codes - /// - /// List of all locale codes in [ISO - /// 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). - Future<models.LocaleCodeList> listCodes() async { - final String apiPath = '/locale/codes'; + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; - final Map<String, dynamic> apiParams = { - - - }; + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', + return models.LocaleCodeList.fromMap(res.data); + } - }; + /// List continents + /// + /// List of all continents. You can use the locale header to get the data in a + /// supported language. + Future<models.ContinentList> listContinents() async { + final String apiPath = '/locale/continents'; - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + final Map<String, dynamic> apiParams = {}; - return models.LocaleCodeList.fromMap(res.data); + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; - } + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - /// List continents - /// - /// List of all continents. You can use the locale header to get the data in a - /// supported language. - Future<models.ContinentList> listContinents() async { - final String apiPath = '/locale/continents'; + return models.ContinentList.fromMap(res.data); + } - final Map<String, dynamic> apiParams = { - - - }; + /// List countries + /// + /// List of all countries. You can use the locale header to get the data in a + /// supported language. + Future<models.CountryList> listCountries() async { + final String apiPath = '/locale/countries'; - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', + final Map<String, dynamic> apiParams = {}; - }; + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - return models.ContinentList.fromMap(res.data); + 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<models.CountryList> listCountriesEU() async { + final String apiPath = '/locale/countries/eu'; - /// List countries - /// - /// List of all countries. You can use the locale header to get the data in a - /// supported language. - Future<models.CountryList> listCountries() async { - final String apiPath = '/locale/countries'; + final Map<String, dynamic> apiParams = {}; - final Map<String, dynamic> apiParams = { - - - }; + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - }; + return models.CountryList.fromMap(res.data); + } - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + /// 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<models.PhoneList> listCountriesPhones() async { + final String apiPath = '/locale/countries/phones'; - return models.CountryList.fromMap(res.data); + final Map<String, dynamic> apiParams = {}; - } + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; - /// 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<models.CountryList> listCountriesEU() async { - final String apiPath = '/locale/countries/eu'; + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - final Map<String, dynamic> apiParams = { - - - }; + return models.PhoneList.fromMap(res.data); + } - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', + /// 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<models.CurrencyList> listCurrencies() async { + final String apiPath = '/locale/currencies'; - }; + final Map<String, dynamic> apiParams = {}; - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; - return models.CountryList.fromMap(res.data); + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - } + return models.CurrencyList.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<models.PhoneList> listCountriesPhones() async { - final String apiPath = '/locale/countries/phones'; + /// 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<models.LanguageList> listLanguages() async { + final String apiPath = '/locale/languages'; - final Map<String, dynamic> apiParams = { - - - }; + final Map<String, dynamic> apiParams = {}; - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; - }; + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - 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<models.CurrencyList> listCurrencies() async { - final String apiPath = '/locale/currencies'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - 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<models.LanguageList> listLanguages() async { - final String apiPath = '/locale/languages'; - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LanguageList.fromMap(res.data); - - } -} \ No newline at end of file + return models.LanguageList.fromMap(res.data); + } +} diff --git a/lib/services/messaging.dart b/lib/services/messaging.dart index c138f93c..5fc759fd 100644 --- a/lib/services/messaging.dart +++ b/lib/services/messaging.dart @@ -3,1257 +3,1386 @@ part of '../dart_appwrite.dart'; /// The Messaging service allows you to send messages to any provider type /// (SMTP, push notification, SMS, etc.). class Messaging extends Service { - Messaging(super.client); - - /// List messages - /// - /// Get a list of all messages from the current Appwrite project. - Future<models.MessageList> listMessages({List<String>? queries, String? search}) async { - final String apiPath = '/messaging/messages'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MessageList.fromMap(res.data); - - } - - /// Create email - /// - /// Create a new email message. - Future<models.Message> createEmail({required String messageId, required String subject, required String content, List<String>? topics, List<String>? users, List<String>? targets, List<String>? cc, List<String>? bcc, List<String>? attachments, bool? draft, bool? html, String? scheduledAt}) async { - final String apiPath = '/messaging/messages/email'; - - final Map<String, dynamic> apiParams = { - - 'messageId': messageId, -'subject': subject, -'content': content, -'topics': topics, -'users': users, -'targets': targets, -'cc': cc, -'bcc': bcc, -'attachments': attachments, -'draft': draft, -'html': html, -'scheduledAt': scheduledAt, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - - } - - /// Update email - /// - /// Update an email message by its unique ID. - /// - Future<models.Message> updateEmail({required String messageId, List<String>? topics, List<String>? users, List<String>? targets, String? subject, String? content, bool? draft, bool? html, List<String>? cc, List<String>? bcc, String? scheduledAt, List<String>? attachments}) async { - final String apiPath = '/messaging/messages/email/{messageId}'.replaceAll('{messageId}', messageId); - - final Map<String, dynamic> apiParams = { - - 'topics': topics, -'users': users, -'targets': targets, -'subject': subject, -'content': content, -'draft': draft, -'html': html, -'cc': cc, -'bcc': bcc, -'scheduledAt': scheduledAt, -'attachments': attachments, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - - } - - /// Create push notification - /// - /// Create a new push notification. - Future<models.Message> createPush({required String messageId, String? title, String? body, List<String>? topics, List<String>? users, List<String>? targets, Map? data, String? action, String? image, String? icon, String? sound, String? color, String? tag, int? badge, bool? draft, String? scheduledAt, bool? contentAvailable, bool? critical, enums.MessagePriority? priority}) async { - final String apiPath = '/messaging/messages/push'; - - final Map<String, dynamic> apiParams = { - - 'messageId': messageId, -'title': title, -'body': body, -'topics': topics, -'users': users, -'targets': targets, -'data': data, -'action': action, -'image': image, -'icon': icon, -'sound': sound, -'color': color, -'tag': tag, -'badge': badge, -'draft': draft, -'scheduledAt': scheduledAt, -'contentAvailable': contentAvailable, -'critical': critical, -'priority': priority?.value, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - - } - - /// Update push notification - /// - /// Update a push notification by its unique ID. - /// - Future<models.Message> updatePush({required String messageId, List<String>? topics, List<String>? users, List<String>? targets, String? title, String? body, Map? data, String? action, String? image, String? icon, String? sound, String? color, String? tag, int? badge, bool? draft, String? scheduledAt, bool? contentAvailable, bool? critical, enums.MessagePriority? priority}) async { - final String apiPath = '/messaging/messages/push/{messageId}'.replaceAll('{messageId}', messageId); - - final Map<String, dynamic> apiParams = { - - 'topics': topics, -'users': users, -'targets': targets, -'title': title, -'body': body, -'data': data, -'action': action, -'image': image, -'icon': icon, -'sound': sound, -'color': color, -'tag': tag, -'badge': badge, -'draft': draft, -'scheduledAt': scheduledAt, -'contentAvailable': contentAvailable, -'critical': critical, -'priority': priority?.value, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - - } - - /// Create SMS - /// - /// Create a new SMS message. - Future<models.Message> createSms({required String messageId, required String content, List<String>? topics, List<String>? users, List<String>? targets, bool? draft, String? scheduledAt}) async { - final String apiPath = '/messaging/messages/sms'; - - final Map<String, dynamic> apiParams = { - - 'messageId': messageId, -'content': content, -'topics': topics, -'users': users, -'targets': targets, -'draft': draft, -'scheduledAt': scheduledAt, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - - } - - /// Update SMS - /// - /// Update an email message by its unique ID. - /// - Future<models.Message> updateSms({required String messageId, List<String>? topics, List<String>? users, List<String>? targets, String? content, bool? draft, String? scheduledAt}) async { - final String apiPath = '/messaging/messages/sms/{messageId}'.replaceAll('{messageId}', messageId); - - final Map<String, dynamic> apiParams = { - - 'topics': topics, -'users': users, -'targets': targets, -'content': content, -'draft': draft, -'scheduledAt': scheduledAt, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - - } - - /// Get message - /// - /// Get a message by its unique ID. - /// - Future<models.Message> getMessage({required String messageId}) async { - final String apiPath = '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - - } - - /// Delete message - /// - /// Delete a message. If the message is not a draft or scheduled, but has been - /// sent, this will not recall the message. - Future delete({required String messageId}) async { - final String apiPath = '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List message logs - /// - /// Get the message activity logs listed by its unique ID. - Future<models.LogList> listMessageLogs({required String messageId, List<String>? queries}) async { - final String apiPath = '/messaging/messages/{messageId}/logs'.replaceAll('{messageId}', messageId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - - } - - /// List message targets - /// - /// Get a list of the targets associated with a message. - Future<models.TargetList> listTargets({required String messageId, List<String>? queries}) async { - final String apiPath = '/messaging/messages/{messageId}/targets'.replaceAll('{messageId}', messageId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.TargetList.fromMap(res.data); - - } - - /// List providers - /// - /// Get a list of all providers from the current Appwrite project. - Future<models.ProviderList> listProviders({List<String>? queries, String? search}) async { - final String apiPath = '/messaging/providers'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.ProviderList.fromMap(res.data); - - } - - /// Create APNS provider - /// - /// Create a new Apple Push Notification service provider. - Future<models.Provider> createApnsProvider({required String providerId, required String name, String? authKey, String? authKeyId, String? teamId, String? bundleId, bool? sandbox, bool? enabled}) async { - final String apiPath = '/messaging/providers/apns'; - - final Map<String, dynamic> apiParams = { - - 'providerId': providerId, -'name': name, -'authKey': authKey, -'authKeyId': authKeyId, -'teamId': teamId, -'bundleId': bundleId, -'sandbox': sandbox, -'enabled': enabled, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update APNS provider - /// - /// Update a Apple Push Notification service provider by its unique ID. - Future<models.Provider> updateApnsProvider({required String providerId, String? name, bool? enabled, String? authKey, String? authKeyId, String? teamId, String? bundleId, bool? sandbox}) async { - final String apiPath = '/messaging/providers/apns/{providerId}'.replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - - 'name': name, -'enabled': enabled, -'authKey': authKey, -'authKeyId': authKeyId, -'teamId': teamId, -'bundleId': bundleId, -'sandbox': sandbox, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create FCM provider - /// - /// Create a new Firebase Cloud Messaging provider. - Future<models.Provider> createFcmProvider({required String providerId, required String name, Map? serviceAccountJSON, bool? enabled}) async { - final String apiPath = '/messaging/providers/fcm'; - - final Map<String, dynamic> apiParams = { - - 'providerId': providerId, -'name': name, -'serviceAccountJSON': serviceAccountJSON, -'enabled': enabled, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update FCM provider - /// - /// Update a Firebase Cloud Messaging provider by its unique ID. - Future<models.Provider> updateFcmProvider({required String providerId, String? name, bool? enabled, Map? serviceAccountJSON}) async { - final String apiPath = '/messaging/providers/fcm/{providerId}'.replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - - 'name': name, -'enabled': enabled, -'serviceAccountJSON': serviceAccountJSON, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create Mailgun provider - /// - /// Create a new Mailgun provider. - Future<models.Provider> createMailgunProvider({required String providerId, required String name, String? apiKey, String? domain, bool? isEuRegion, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { - final String apiPath = '/messaging/providers/mailgun'; - - final Map<String, dynamic> apiParams = { - - 'providerId': providerId, -'name': name, -'apiKey': apiKey, -'domain': domain, -'isEuRegion': isEuRegion, -'fromName': fromName, -'fromEmail': fromEmail, -'replyToName': replyToName, -'replyToEmail': replyToEmail, -'enabled': enabled, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update Mailgun provider - /// - /// Update a Mailgun provider by its unique ID. - Future<models.Provider> updateMailgunProvider({required String providerId, String? name, String? apiKey, String? domain, bool? isEuRegion, bool? enabled, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail}) async { - final String apiPath = '/messaging/providers/mailgun/{providerId}'.replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - - 'name': name, -'apiKey': apiKey, -'domain': domain, -'isEuRegion': isEuRegion, -'enabled': enabled, -'fromName': fromName, -'fromEmail': fromEmail, -'replyToName': replyToName, -'replyToEmail': replyToEmail, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create Msg91 provider - /// - /// Create a new MSG91 provider. - Future<models.Provider> createMsg91Provider({required String providerId, required String name, String? templateId, String? senderId, String? authKey, bool? enabled}) async { - final String apiPath = '/messaging/providers/msg91'; - - final Map<String, dynamic> apiParams = { - - 'providerId': providerId, -'name': name, -'templateId': templateId, -'senderId': senderId, -'authKey': authKey, -'enabled': enabled, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update Msg91 provider - /// - /// Update a MSG91 provider by its unique ID. - Future<models.Provider> updateMsg91Provider({required String providerId, String? name, bool? enabled, String? templateId, String? senderId, String? authKey}) async { - final String apiPath = '/messaging/providers/msg91/{providerId}'.replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - - 'name': name, -'enabled': enabled, -'templateId': templateId, -'senderId': senderId, -'authKey': authKey, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create Sendgrid provider - /// - /// Create a new Sendgrid provider. - Future<models.Provider> createSendgridProvider({required String providerId, required String name, String? apiKey, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { - final String apiPath = '/messaging/providers/sendgrid'; - - final Map<String, dynamic> apiParams = { - - 'providerId': providerId, -'name': name, -'apiKey': apiKey, -'fromName': fromName, -'fromEmail': fromEmail, -'replyToName': replyToName, -'replyToEmail': replyToEmail, -'enabled': enabled, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update Sendgrid provider - /// - /// Update a Sendgrid provider by its unique ID. - Future<models.Provider> updateSendgridProvider({required String providerId, String? name, bool? enabled, String? apiKey, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail}) async { - final String apiPath = '/messaging/providers/sendgrid/{providerId}'.replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - - 'name': name, -'enabled': enabled, -'apiKey': apiKey, -'fromName': fromName, -'fromEmail': fromEmail, -'replyToName': replyToName, -'replyToEmail': replyToEmail, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create SMTP provider - /// - /// Create a new SMTP provider. - Future<models.Provider> createSmtpProvider({required String providerId, required String name, required String host, int? port, String? username, String? password, enums.SmtpEncryption? encryption, bool? autoTLS, String? mailer, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { - final String apiPath = '/messaging/providers/smtp'; - - final Map<String, dynamic> apiParams = { - - 'providerId': providerId, -'name': name, -'host': host, -'port': port, -'username': username, -'password': password, -'encryption': encryption?.value, -'autoTLS': autoTLS, -'mailer': mailer, -'fromName': fromName, -'fromEmail': fromEmail, -'replyToName': replyToName, -'replyToEmail': replyToEmail, -'enabled': enabled, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update SMTP provider - /// - /// Update a SMTP provider by its unique ID. - Future<models.Provider> updateSmtpProvider({required String providerId, String? name, String? host, int? port, String? username, String? password, enums.SmtpEncryption? encryption, bool? autoTLS, String? mailer, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { - final String apiPath = '/messaging/providers/smtp/{providerId}'.replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - - 'name': name, -'host': host, -'port': port, -'username': username, -'password': password, -'encryption': encryption?.value, -'autoTLS': autoTLS, -'mailer': mailer, -'fromName': fromName, -'fromEmail': fromEmail, -'replyToName': replyToName, -'replyToEmail': replyToEmail, -'enabled': enabled, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create Telesign provider - /// - /// Create a new Telesign provider. - Future<models.Provider> createTelesignProvider({required String providerId, required String name, String? from, String? customerId, String? apiKey, bool? enabled}) async { - final String apiPath = '/messaging/providers/telesign'; - - final Map<String, dynamic> apiParams = { - - 'providerId': providerId, -'name': name, -'from': from, -'customerId': customerId, -'apiKey': apiKey, -'enabled': enabled, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update Telesign provider - /// - /// Update a Telesign provider by its unique ID. - Future<models.Provider> updateTelesignProvider({required String providerId, String? name, bool? enabled, String? customerId, String? apiKey, String? from}) async { - final String apiPath = '/messaging/providers/telesign/{providerId}'.replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - - 'name': name, -'enabled': enabled, -'customerId': customerId, -'apiKey': apiKey, -'from': from, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create Textmagic provider - /// - /// Create a new Textmagic provider. - Future<models.Provider> createTextmagicProvider({required String providerId, required String name, String? from, String? username, String? apiKey, bool? enabled}) async { - final String apiPath = '/messaging/providers/textmagic'; - - final Map<String, dynamic> apiParams = { - - 'providerId': providerId, -'name': name, -'from': from, -'username': username, -'apiKey': apiKey, -'enabled': enabled, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update Textmagic provider - /// - /// Update a Textmagic provider by its unique ID. - Future<models.Provider> updateTextmagicProvider({required String providerId, String? name, bool? enabled, String? username, String? apiKey, String? from}) async { - final String apiPath = '/messaging/providers/textmagic/{providerId}'.replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - - 'name': name, -'enabled': enabled, -'username': username, -'apiKey': apiKey, -'from': from, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create Twilio provider - /// - /// Create a new Twilio provider. - Future<models.Provider> createTwilioProvider({required String providerId, required String name, String? from, String? accountSid, String? authToken, bool? enabled}) async { - final String apiPath = '/messaging/providers/twilio'; - - final Map<String, dynamic> apiParams = { - - 'providerId': providerId, -'name': name, -'from': from, -'accountSid': accountSid, -'authToken': authToken, -'enabled': enabled, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update Twilio provider - /// - /// Update a Twilio provider by its unique ID. - Future<models.Provider> updateTwilioProvider({required String providerId, String? name, bool? enabled, String? accountSid, String? authToken, String? from}) async { - final String apiPath = '/messaging/providers/twilio/{providerId}'.replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - - 'name': name, -'enabled': enabled, -'accountSid': accountSid, -'authToken': authToken, -'from': from, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Create Vonage provider - /// - /// Create a new Vonage provider. - Future<models.Provider> createVonageProvider({required String providerId, required String name, String? from, String? apiKey, String? apiSecret, bool? enabled}) async { - final String apiPath = '/messaging/providers/vonage'; - - final Map<String, dynamic> apiParams = { - - 'providerId': providerId, -'name': name, -'from': from, -'apiKey': apiKey, -'apiSecret': apiSecret, -'enabled': enabled, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Update Vonage provider - /// - /// Update a Vonage provider by its unique ID. - Future<models.Provider> updateVonageProvider({required String providerId, String? name, bool? enabled, String? apiKey, String? apiSecret, String? from}) async { - final String apiPath = '/messaging/providers/vonage/{providerId}'.replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - - 'name': name, -'enabled': enabled, -'apiKey': apiKey, -'apiSecret': apiSecret, -'from': from, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Get provider - /// - /// Get a provider by its unique ID. - /// - Future<models.Provider> getProvider({required String providerId}) async { - final String apiPath = '/messaging/providers/{providerId}'.replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - - } - - /// Delete provider - /// - /// Delete a provider by its unique ID. - Future deleteProvider({required String providerId}) async { - final String apiPath = '/messaging/providers/{providerId}'.replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List provider logs - /// - /// Get the provider activity logs listed by its unique ID. - Future<models.LogList> listProviderLogs({required String providerId, List<String>? queries}) async { - final String apiPath = '/messaging/providers/{providerId}/logs'.replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - - } - - /// List subscriber logs - /// - /// Get the subscriber activity logs listed by its unique ID. - Future<models.LogList> listSubscriberLogs({required String subscriberId, List<String>? queries}) async { - final String apiPath = '/messaging/subscribers/{subscriberId}/logs'.replaceAll('{subscriberId}', subscriberId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - - } - - /// List topics - /// - /// Get a list of all topics from the current Appwrite project. - Future<models.TopicList> listTopics({List<String>? queries, String? search}) async { - final String apiPath = '/messaging/topics'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.TopicList.fromMap(res.data); - - } - - /// Create topic - /// - /// Create a new topic. - Future<models.Topic> createTopic({required String topicId, required String name, List<String>? subscribe}) async { - final String apiPath = '/messaging/topics'; - - final Map<String, dynamic> apiParams = { - - 'topicId': topicId, -'name': name, -'subscribe': subscribe, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Topic.fromMap(res.data); - - } - - /// Get topic - /// - /// Get a topic by its unique ID. - /// - Future<models.Topic> getTopic({required String topicId}) async { - final String apiPath = '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Topic.fromMap(res.data); - - } - - /// Update topic - /// - /// Update a topic by its unique ID. - /// - Future<models.Topic> updateTopic({required String topicId, String? name, List<String>? subscribe}) async { - final String apiPath = '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); - - final Map<String, dynamic> apiParams = { - - 'name': name, -'subscribe': subscribe, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Topic.fromMap(res.data); - - } - - /// Delete topic - /// - /// Delete a topic by its unique ID. - Future deleteTopic({required String topicId}) async { - final String apiPath = '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List topic logs - /// - /// Get the topic activity logs listed by its unique ID. - Future<models.LogList> listTopicLogs({required String topicId, List<String>? queries}) async { - final String apiPath = '/messaging/topics/{topicId}/logs'.replaceAll('{topicId}', topicId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - - } - - /// List subscribers - /// - /// Get a list of all subscribers from the current Appwrite project. - Future<models.SubscriberList> listSubscribers({required String topicId, List<String>? queries, String? search}) async { - final String apiPath = '/messaging/topics/{topicId}/subscribers'.replaceAll('{topicId}', topicId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SubscriberList.fromMap(res.data); - - } - - /// Create subscriber - /// - /// Create a new subscriber. - Future<models.Subscriber> createSubscriber({required String topicId, required String subscriberId, required String targetId}) async { - final String apiPath = '/messaging/topics/{topicId}/subscribers'.replaceAll('{topicId}', topicId); - - final Map<String, dynamic> apiParams = { - - 'subscriberId': subscriberId, -'targetId': targetId, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Subscriber.fromMap(res.data); - - } - - /// Get subscriber - /// - /// Get a subscriber by its unique ID. - /// - Future<models.Subscriber> getSubscriber({required String topicId, required String subscriberId}) async { - final String apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replaceAll('{topicId}', topicId).replaceAll('{subscriberId}', subscriberId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Subscriber.fromMap(res.data); - - } - - /// Delete subscriber - /// - /// Delete a subscriber by its unique ID. - Future deleteSubscriber({required String topicId, required String subscriberId}) async { - final String apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replaceAll('{topicId}', topicId).replaceAll('{subscriberId}', subscriberId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } -} \ No newline at end of file + Messaging(super.client); + + /// List messages + /// + /// Get a list of all messages from the current Appwrite project. + Future<models.MessageList> listMessages( + {List<String>? queries, String? search}) async { + final String apiPath = '/messaging/messages'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MessageList.fromMap(res.data); + } + + /// Create email + /// + /// Create a new email message. + Future<models.Message> createEmail( + {required String messageId, + required String subject, + required String content, + List<String>? topics, + List<String>? users, + List<String>? targets, + List<String>? cc, + List<String>? bcc, + List<String>? attachments, + bool? draft, + bool? html, + String? scheduledAt}) async { + final String apiPath = '/messaging/messages/email'; + + final Map<String, dynamic> apiParams = { + 'messageId': messageId, + 'subject': subject, + 'content': content, + 'topics': topics, + 'users': users, + 'targets': targets, + 'cc': cc, + 'bcc': bcc, + 'attachments': attachments, + 'draft': draft, + 'html': html, + 'scheduledAt': scheduledAt, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + } + + /// Update email + /// + /// Update an email message by its unique ID. + /// + Future<models.Message> updateEmail( + {required String messageId, + List<String>? topics, + List<String>? users, + List<String>? targets, + String? subject, + String? content, + bool? draft, + bool? html, + List<String>? cc, + List<String>? bcc, + String? scheduledAt, + List<String>? attachments}) async { + final String apiPath = '/messaging/messages/email/{messageId}' + .replaceAll('{messageId}', messageId); + + final Map<String, dynamic> apiParams = { + 'topics': topics, + 'users': users, + 'targets': targets, + 'subject': subject, + 'content': content, + 'draft': draft, + 'html': html, + 'cc': cc, + 'bcc': bcc, + 'scheduledAt': scheduledAt, + 'attachments': attachments, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + } + + /// Create push notification + /// + /// Create a new push notification. + Future<models.Message> createPush( + {required String messageId, + String? title, + String? body, + List<String>? topics, + List<String>? users, + List<String>? targets, + Map? data, + String? action, + String? image, + String? icon, + String? sound, + String? color, + String? tag, + int? badge, + bool? draft, + String? scheduledAt, + bool? contentAvailable, + bool? critical, + enums.MessagePriority? priority}) async { + final String apiPath = '/messaging/messages/push'; + + final Map<String, dynamic> apiParams = { + 'messageId': messageId, + 'title': title, + 'body': body, + 'topics': topics, + 'users': users, + 'targets': targets, + 'data': data, + 'action': action, + 'image': image, + 'icon': icon, + 'sound': sound, + 'color': color, + 'tag': tag, + 'badge': badge, + 'draft': draft, + 'scheduledAt': scheduledAt, + 'contentAvailable': contentAvailable, + 'critical': critical, + 'priority': priority?.value, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + } + + /// Update push notification + /// + /// Update a push notification by its unique ID. + /// + Future<models.Message> updatePush( + {required String messageId, + List<String>? topics, + List<String>? users, + List<String>? targets, + String? title, + String? body, + Map? data, + String? action, + String? image, + String? icon, + String? sound, + String? color, + String? tag, + int? badge, + bool? draft, + String? scheduledAt, + bool? contentAvailable, + bool? critical, + enums.MessagePriority? priority}) async { + final String apiPath = '/messaging/messages/push/{messageId}' + .replaceAll('{messageId}', messageId); + + final Map<String, dynamic> apiParams = { + 'topics': topics, + 'users': users, + 'targets': targets, + 'title': title, + 'body': body, + 'data': data, + 'action': action, + 'image': image, + 'icon': icon, + 'sound': sound, + 'color': color, + 'tag': tag, + 'badge': badge, + 'draft': draft, + 'scheduledAt': scheduledAt, + 'contentAvailable': contentAvailable, + 'critical': critical, + 'priority': priority?.value, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + } + + /// Create SMS + /// + /// Create a new SMS message. + Future<models.Message> createSms( + {required String messageId, + required String content, + List<String>? topics, + List<String>? users, + List<String>? targets, + bool? draft, + String? scheduledAt}) async { + final String apiPath = '/messaging/messages/sms'; + + final Map<String, dynamic> apiParams = { + 'messageId': messageId, + 'content': content, + 'topics': topics, + 'users': users, + 'targets': targets, + 'draft': draft, + 'scheduledAt': scheduledAt, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + } + + /// Update SMS + /// + /// Update an email message by its unique ID. + /// + Future<models.Message> updateSms( + {required String messageId, + List<String>? topics, + List<String>? users, + List<String>? targets, + String? content, + bool? draft, + String? scheduledAt}) async { + final String apiPath = '/messaging/messages/sms/{messageId}' + .replaceAll('{messageId}', messageId); + + final Map<String, dynamic> apiParams = { + 'topics': topics, + 'users': users, + 'targets': targets, + 'content': content, + 'draft': draft, + 'scheduledAt': scheduledAt, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + } + + /// Get message + /// + /// Get a message by its unique ID. + /// + Future<models.Message> getMessage({required String messageId}) async { + final String apiPath = + '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + } + + /// Delete message + /// + /// Delete a message. If the message is not a draft or scheduled, but has been + /// sent, this will not recall the message. + Future delete({required String messageId}) async { + final String apiPath = + '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List message logs + /// + /// Get the message activity logs listed by its unique ID. + Future<models.LogList> listMessageLogs( + {required String messageId, List<String>? queries}) async { + final String apiPath = '/messaging/messages/{messageId}/logs' + .replaceAll('{messageId}', messageId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + } + + /// List message targets + /// + /// Get a list of the targets associated with a message. + Future<models.TargetList> listTargets( + {required String messageId, List<String>? queries}) async { + final String apiPath = '/messaging/messages/{messageId}/targets' + .replaceAll('{messageId}', messageId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.TargetList.fromMap(res.data); + } + + /// List providers + /// + /// Get a list of all providers from the current Appwrite project. + Future<models.ProviderList> listProviders( + {List<String>? queries, String? search}) async { + final String apiPath = '/messaging/providers'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.ProviderList.fromMap(res.data); + } + + /// Create APNS provider + /// + /// Create a new Apple Push Notification service provider. + Future<models.Provider> createApnsProvider( + {required String providerId, + required String name, + String? authKey, + String? authKeyId, + String? teamId, + String? bundleId, + bool? sandbox, + bool? enabled}) async { + final String apiPath = '/messaging/providers/apns'; + + final Map<String, dynamic> apiParams = { + 'providerId': providerId, + 'name': name, + 'authKey': authKey, + 'authKeyId': authKeyId, + 'teamId': teamId, + 'bundleId': bundleId, + 'sandbox': sandbox, + 'enabled': enabled, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update APNS provider + /// + /// Update a Apple Push Notification service provider by its unique ID. + Future<models.Provider> updateApnsProvider( + {required String providerId, + String? name, + bool? enabled, + String? authKey, + String? authKeyId, + String? teamId, + String? bundleId, + bool? sandbox}) async { + final String apiPath = '/messaging/providers/apns/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + 'name': name, + 'enabled': enabled, + 'authKey': authKey, + 'authKeyId': authKeyId, + 'teamId': teamId, + 'bundleId': bundleId, + 'sandbox': sandbox, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create FCM provider + /// + /// Create a new Firebase Cloud Messaging provider. + Future<models.Provider> createFcmProvider( + {required String providerId, + required String name, + Map? serviceAccountJSON, + bool? enabled}) async { + final String apiPath = '/messaging/providers/fcm'; + + final Map<String, dynamic> apiParams = { + 'providerId': providerId, + 'name': name, + 'serviceAccountJSON': serviceAccountJSON, + 'enabled': enabled, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update FCM provider + /// + /// Update a Firebase Cloud Messaging provider by its unique ID. + Future<models.Provider> updateFcmProvider( + {required String providerId, + String? name, + bool? enabled, + Map? serviceAccountJSON}) async { + final String apiPath = '/messaging/providers/fcm/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + 'name': name, + 'enabled': enabled, + 'serviceAccountJSON': serviceAccountJSON, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create Mailgun provider + /// + /// Create a new Mailgun provider. + Future<models.Provider> createMailgunProvider( + {required String providerId, + required String name, + String? apiKey, + String? domain, + bool? isEuRegion, + String? fromName, + String? fromEmail, + String? replyToName, + String? replyToEmail, + bool? enabled}) async { + final String apiPath = '/messaging/providers/mailgun'; + + final Map<String, dynamic> apiParams = { + 'providerId': providerId, + 'name': name, + 'apiKey': apiKey, + 'domain': domain, + 'isEuRegion': isEuRegion, + 'fromName': fromName, + 'fromEmail': fromEmail, + 'replyToName': replyToName, + 'replyToEmail': replyToEmail, + 'enabled': enabled, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update Mailgun provider + /// + /// Update a Mailgun provider by its unique ID. + Future<models.Provider> updateMailgunProvider( + {required String providerId, + String? name, + String? apiKey, + String? domain, + bool? isEuRegion, + bool? enabled, + String? fromName, + String? fromEmail, + String? replyToName, + String? replyToEmail}) async { + final String apiPath = '/messaging/providers/mailgun/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + 'name': name, + 'apiKey': apiKey, + 'domain': domain, + 'isEuRegion': isEuRegion, + 'enabled': enabled, + 'fromName': fromName, + 'fromEmail': fromEmail, + 'replyToName': replyToName, + 'replyToEmail': replyToEmail, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create Msg91 provider + /// + /// Create a new MSG91 provider. + Future<models.Provider> createMsg91Provider( + {required String providerId, + required String name, + String? templateId, + String? senderId, + String? authKey, + bool? enabled}) async { + final String apiPath = '/messaging/providers/msg91'; + + final Map<String, dynamic> apiParams = { + 'providerId': providerId, + 'name': name, + 'templateId': templateId, + 'senderId': senderId, + 'authKey': authKey, + 'enabled': enabled, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update Msg91 provider + /// + /// Update a MSG91 provider by its unique ID. + Future<models.Provider> updateMsg91Provider( + {required String providerId, + String? name, + bool? enabled, + String? templateId, + String? senderId, + String? authKey}) async { + final String apiPath = '/messaging/providers/msg91/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + 'name': name, + 'enabled': enabled, + 'templateId': templateId, + 'senderId': senderId, + 'authKey': authKey, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create Sendgrid provider + /// + /// Create a new Sendgrid provider. + Future<models.Provider> createSendgridProvider( + {required String providerId, + required String name, + String? apiKey, + String? fromName, + String? fromEmail, + String? replyToName, + String? replyToEmail, + bool? enabled}) async { + final String apiPath = '/messaging/providers/sendgrid'; + + final Map<String, dynamic> apiParams = { + 'providerId': providerId, + 'name': name, + 'apiKey': apiKey, + 'fromName': fromName, + 'fromEmail': fromEmail, + 'replyToName': replyToName, + 'replyToEmail': replyToEmail, + 'enabled': enabled, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update Sendgrid provider + /// + /// Update a Sendgrid provider by its unique ID. + Future<models.Provider> updateSendgridProvider( + {required String providerId, + String? name, + bool? enabled, + String? apiKey, + String? fromName, + String? fromEmail, + String? replyToName, + String? replyToEmail}) async { + final String apiPath = '/messaging/providers/sendgrid/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + 'name': name, + 'enabled': enabled, + 'apiKey': apiKey, + 'fromName': fromName, + 'fromEmail': fromEmail, + 'replyToName': replyToName, + 'replyToEmail': replyToEmail, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create SMTP provider + /// + /// Create a new SMTP provider. + Future<models.Provider> createSmtpProvider( + {required String providerId, + required String name, + required String host, + int? port, + String? username, + String? password, + enums.SmtpEncryption? encryption, + bool? autoTLS, + String? mailer, + String? fromName, + String? fromEmail, + String? replyToName, + String? replyToEmail, + bool? enabled}) async { + final String apiPath = '/messaging/providers/smtp'; + + final Map<String, dynamic> apiParams = { + 'providerId': providerId, + 'name': name, + 'host': host, + 'port': port, + 'username': username, + 'password': password, + 'encryption': encryption?.value, + 'autoTLS': autoTLS, + 'mailer': mailer, + 'fromName': fromName, + 'fromEmail': fromEmail, + 'replyToName': replyToName, + 'replyToEmail': replyToEmail, + 'enabled': enabled, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update SMTP provider + /// + /// Update a SMTP provider by its unique ID. + Future<models.Provider> updateSmtpProvider( + {required String providerId, + String? name, + String? host, + int? port, + String? username, + String? password, + enums.SmtpEncryption? encryption, + bool? autoTLS, + String? mailer, + String? fromName, + String? fromEmail, + String? replyToName, + String? replyToEmail, + bool? enabled}) async { + final String apiPath = '/messaging/providers/smtp/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + 'name': name, + 'host': host, + 'port': port, + 'username': username, + 'password': password, + 'encryption': encryption?.value, + 'autoTLS': autoTLS, + 'mailer': mailer, + 'fromName': fromName, + 'fromEmail': fromEmail, + 'replyToName': replyToName, + 'replyToEmail': replyToEmail, + 'enabled': enabled, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create Telesign provider + /// + /// Create a new Telesign provider. + Future<models.Provider> createTelesignProvider( + {required String providerId, + required String name, + String? from, + String? customerId, + String? apiKey, + bool? enabled}) async { + final String apiPath = '/messaging/providers/telesign'; + + final Map<String, dynamic> apiParams = { + 'providerId': providerId, + 'name': name, + 'from': from, + 'customerId': customerId, + 'apiKey': apiKey, + 'enabled': enabled, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update Telesign provider + /// + /// Update a Telesign provider by its unique ID. + Future<models.Provider> updateTelesignProvider( + {required String providerId, + String? name, + bool? enabled, + String? customerId, + String? apiKey, + String? from}) async { + final String apiPath = '/messaging/providers/telesign/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + 'name': name, + 'enabled': enabled, + 'customerId': customerId, + 'apiKey': apiKey, + 'from': from, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create Textmagic provider + /// + /// Create a new Textmagic provider. + Future<models.Provider> createTextmagicProvider( + {required String providerId, + required String name, + String? from, + String? username, + String? apiKey, + bool? enabled}) async { + final String apiPath = '/messaging/providers/textmagic'; + + final Map<String, dynamic> apiParams = { + 'providerId': providerId, + 'name': name, + 'from': from, + 'username': username, + 'apiKey': apiKey, + 'enabled': enabled, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update Textmagic provider + /// + /// Update a Textmagic provider by its unique ID. + Future<models.Provider> updateTextmagicProvider( + {required String providerId, + String? name, + bool? enabled, + String? username, + String? apiKey, + String? from}) async { + final String apiPath = '/messaging/providers/textmagic/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + 'name': name, + 'enabled': enabled, + 'username': username, + 'apiKey': apiKey, + 'from': from, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create Twilio provider + /// + /// Create a new Twilio provider. + Future<models.Provider> createTwilioProvider( + {required String providerId, + required String name, + String? from, + String? accountSid, + String? authToken, + bool? enabled}) async { + final String apiPath = '/messaging/providers/twilio'; + + final Map<String, dynamic> apiParams = { + 'providerId': providerId, + 'name': name, + 'from': from, + 'accountSid': accountSid, + 'authToken': authToken, + 'enabled': enabled, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update Twilio provider + /// + /// Update a Twilio provider by its unique ID. + Future<models.Provider> updateTwilioProvider( + {required String providerId, + String? name, + bool? enabled, + String? accountSid, + String? authToken, + String? from}) async { + final String apiPath = '/messaging/providers/twilio/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + 'name': name, + 'enabled': enabled, + 'accountSid': accountSid, + 'authToken': authToken, + 'from': from, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Create Vonage provider + /// + /// Create a new Vonage provider. + Future<models.Provider> createVonageProvider( + {required String providerId, + required String name, + String? from, + String? apiKey, + String? apiSecret, + bool? enabled}) async { + final String apiPath = '/messaging/providers/vonage'; + + final Map<String, dynamic> apiParams = { + 'providerId': providerId, + 'name': name, + 'from': from, + 'apiKey': apiKey, + 'apiSecret': apiSecret, + 'enabled': enabled, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Update Vonage provider + /// + /// Update a Vonage provider by its unique ID. + Future<models.Provider> updateVonageProvider( + {required String providerId, + String? name, + bool? enabled, + String? apiKey, + String? apiSecret, + String? from}) async { + final String apiPath = '/messaging/providers/vonage/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + 'name': name, + 'enabled': enabled, + 'apiKey': apiKey, + 'apiSecret': apiSecret, + 'from': from, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Get provider + /// + /// Get a provider by its unique ID. + /// + Future<models.Provider> getProvider({required String providerId}) async { + final String apiPath = '/messaging/providers/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + } + + /// Delete provider + /// + /// Delete a provider by its unique ID. + Future deleteProvider({required String providerId}) async { + final String apiPath = '/messaging/providers/{providerId}' + .replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List provider logs + /// + /// Get the provider activity logs listed by its unique ID. + Future<models.LogList> listProviderLogs( + {required String providerId, List<String>? queries}) async { + final String apiPath = '/messaging/providers/{providerId}/logs' + .replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + } + + /// List subscriber logs + /// + /// Get the subscriber activity logs listed by its unique ID. + Future<models.LogList> listSubscriberLogs( + {required String subscriberId, List<String>? queries}) async { + final String apiPath = '/messaging/subscribers/{subscriberId}/logs' + .replaceAll('{subscriberId}', subscriberId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + } + + /// List topics + /// + /// Get a list of all topics from the current Appwrite project. + Future<models.TopicList> listTopics( + {List<String>? queries, String? search}) async { + final String apiPath = '/messaging/topics'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.TopicList.fromMap(res.data); + } + + /// Create topic + /// + /// Create a new topic. + Future<models.Topic> createTopic( + {required String topicId, + required String name, + List<String>? subscribe}) async { + final String apiPath = '/messaging/topics'; + + final Map<String, dynamic> apiParams = { + 'topicId': topicId, + 'name': name, + 'subscribe': subscribe, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Topic.fromMap(res.data); + } + + /// Get topic + /// + /// Get a topic by its unique ID. + /// + Future<models.Topic> getTopic({required String topicId}) async { + final String apiPath = + '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Topic.fromMap(res.data); + } + + /// Update topic + /// + /// Update a topic by its unique ID. + /// + Future<models.Topic> updateTopic( + {required String topicId, String? name, List<String>? subscribe}) async { + final String apiPath = + '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); + + final Map<String, dynamic> apiParams = { + 'name': name, + 'subscribe': subscribe, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Topic.fromMap(res.data); + } + + /// Delete topic + /// + /// Delete a topic by its unique ID. + Future deleteTopic({required String topicId}) async { + final String apiPath = + '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List topic logs + /// + /// Get the topic activity logs listed by its unique ID. + Future<models.LogList> listTopicLogs( + {required String topicId, List<String>? queries}) async { + final String apiPath = + '/messaging/topics/{topicId}/logs'.replaceAll('{topicId}', topicId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + } + + /// List subscribers + /// + /// Get a list of all subscribers from the current Appwrite project. + Future<models.SubscriberList> listSubscribers( + {required String topicId, List<String>? queries, String? search}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers' + .replaceAll('{topicId}', topicId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SubscriberList.fromMap(res.data); + } + + /// Create subscriber + /// + /// Create a new subscriber. + Future<models.Subscriber> createSubscriber( + {required String topicId, + required String subscriberId, + required String targetId}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers' + .replaceAll('{topicId}', topicId); + + final Map<String, dynamic> apiParams = { + 'subscriberId': subscriberId, + 'targetId': targetId, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Subscriber.fromMap(res.data); + } + + /// Get subscriber + /// + /// Get a subscriber by its unique ID. + /// + Future<models.Subscriber> getSubscriber( + {required String topicId, required String subscriberId}) async { + final String apiPath = + '/messaging/topics/{topicId}/subscribers/{subscriberId}' + .replaceAll('{topicId}', topicId) + .replaceAll('{subscriberId}', subscriberId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Subscriber.fromMap(res.data); + } + + /// Delete subscriber + /// + /// Delete a subscriber by its unique ID. + Future deleteSubscriber( + {required String topicId, required String subscriberId}) async { + final String apiPath = + '/messaging/topics/{topicId}/subscribers/{subscriberId}' + .replaceAll('{topicId}', topicId) + .replaceAll('{subscriberId}', subscriberId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } +} diff --git a/lib/services/storage.dart b/lib/services/storage.dart index a6f987bc..25808b70 100644 --- a/lib/services/storage.dart +++ b/lib/services/storage.dart @@ -2,356 +2,382 @@ part of '../dart_appwrite.dart'; /// The Storage service allows you to manage your project files. class Storage extends Service { - Storage(super.client); - - /// List buckets - /// - /// Get a list of all the storage buckets. You can use the query params to - /// filter your results. - Future<models.BucketList> listBuckets({List<String>? queries, String? search}) async { - final String apiPath = '/storage/buckets'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.BucketList.fromMap(res.data); - - } - - /// Create bucket - /// - /// Create a new storage bucket. - Future<models.Bucket> createBucket({required String bucketId, required String name, List<String>? permissions, bool? fileSecurity, bool? enabled, int? maximumFileSize, List<String>? allowedFileExtensions, enums.Compression? compression, bool? encryption, bool? antivirus}) async { - final String apiPath = '/storage/buckets'; - - final Map<String, dynamic> apiParams = { - - 'bucketId': bucketId, -'name': name, -'permissions': permissions, -'fileSecurity': fileSecurity, -'enabled': enabled, -'maximumFileSize': maximumFileSize, -'allowedFileExtensions': allowedFileExtensions, -'compression': compression?.value, -'encryption': encryption, -'antivirus': antivirus, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Bucket.fromMap(res.data); - - } - - /// Get bucket - /// - /// Get a storage bucket by its unique ID. This endpoint response returns a - /// JSON object with the storage bucket metadata. - Future<models.Bucket> getBucket({required String bucketId}) async { - final String apiPath = '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Bucket.fromMap(res.data); - - } - - /// Update bucket - /// - /// Update a storage bucket by its unique ID. - Future<models.Bucket> updateBucket({required String bucketId, required String name, List<String>? permissions, bool? fileSecurity, bool? enabled, int? maximumFileSize, List<String>? allowedFileExtensions, enums.Compression? compression, bool? encryption, bool? antivirus}) async { - final String apiPath = '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); - - final Map<String, dynamic> apiParams = { - - 'name': name, -'permissions': permissions, -'fileSecurity': fileSecurity, -'enabled': enabled, -'maximumFileSize': maximumFileSize, -'allowedFileExtensions': allowedFileExtensions, -'compression': compression?.value, -'encryption': encryption, -'antivirus': antivirus, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Bucket.fromMap(res.data); - - } - - /// Delete bucket - /// - /// Delete a storage bucket by its unique ID. - Future deleteBucket({required String bucketId}) async { - final String apiPath = '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List files - /// - /// Get a list of all the user files. You can use the query params to filter - /// your results. - Future<models.FileList> listFiles({required String bucketId, List<String>? queries, String? search}) async { - final String apiPath = '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - 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](https://appwrite.io/docs/server/storage#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<models.File> createFile({required String bucketId, required String fileId, required InputFile file, List<String>? permissions, Function(UploadProgress)? onProgress}) async { - final String apiPath = '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); - - final Map<String, dynamic> apiParams = { - - 'fileId': fileId, -'file': file, -'permissions': permissions, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'multipart/form-data', - - }; - - String idParamName = ''; - idParamName = 'fileId'; - final paramName = 'file'; - final res = await client.chunkedUpload( - path: apiPath, - params: apiParams, - paramName: paramName, - idParamName: idParamName, - headers: apiHeaders, - onProgress: onProgress, - ); - - 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<models.File> getFile({required String bucketId, required String fileId}) async { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - 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<models.File> updateFile({required String bucketId, required String fileId, String? name, List<String>? permissions}) async { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); - - final Map<String, dynamic> apiParams = { - - 'name': name, -'permissions': permissions, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - 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<Uint8List> getFileDownload({required String bucketId, required String fileId}) async { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); - - final Map<String, dynamic> params = { - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, 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<Uint8List> getFilePreview({required String bucketId, required String fileId, int? width, int? height, enums.ImageGravity? gravity, int? quality, int? borderWidth, String? borderColor, int? borderRadius, double? opacity, int? rotation, String? background, enums.ImageFormat? output}) async { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); - - final Map<String, dynamic> params = { - 'width': width, -'height': height, -'gravity': gravity?.value, -'quality': quality, -'borderWidth': borderWidth, -'borderColor': borderColor, -'borderRadius': borderRadius, -'opacity': opacity, -'rotation': rotation, -'background': background, -'output': output?.value, - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, 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<Uint8List> getFileView({required String bucketId, required String fileId}) async { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); - - final Map<String, dynamic> params = { - - - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: params, responseType: ResponseType.bytes); - return res.data; - } -} \ No newline at end of file + Storage(super.client); + + /// List buckets + /// + /// Get a list of all the storage buckets. You can use the query params to + /// filter your results. + Future<models.BucketList> listBuckets( + {List<String>? queries, String? search}) async { + final String apiPath = '/storage/buckets'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.BucketList.fromMap(res.data); + } + + /// Create bucket + /// + /// Create a new storage bucket. + Future<models.Bucket> createBucket( + {required String bucketId, + required String name, + List<String>? permissions, + bool? fileSecurity, + bool? enabled, + int? maximumFileSize, + List<String>? allowedFileExtensions, + enums.Compression? compression, + bool? encryption, + bool? antivirus}) async { + final String apiPath = '/storage/buckets'; + + final Map<String, dynamic> apiParams = { + 'bucketId': bucketId, + 'name': name, + 'permissions': permissions, + 'fileSecurity': fileSecurity, + 'enabled': enabled, + 'maximumFileSize': maximumFileSize, + 'allowedFileExtensions': allowedFileExtensions, + 'compression': compression?.value, + 'encryption': encryption, + 'antivirus': antivirus, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Bucket.fromMap(res.data); + } + + /// Get bucket + /// + /// Get a storage bucket by its unique ID. This endpoint response returns a + /// JSON object with the storage bucket metadata. + Future<models.Bucket> getBucket({required String bucketId}) async { + final String apiPath = + '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Bucket.fromMap(res.data); + } + + /// Update bucket + /// + /// Update a storage bucket by its unique ID. + Future<models.Bucket> updateBucket( + {required String bucketId, + required String name, + List<String>? permissions, + bool? fileSecurity, + bool? enabled, + int? maximumFileSize, + List<String>? allowedFileExtensions, + enums.Compression? compression, + bool? encryption, + bool? antivirus}) async { + final String apiPath = + '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); + + final Map<String, dynamic> apiParams = { + 'name': name, + 'permissions': permissions, + 'fileSecurity': fileSecurity, + 'enabled': enabled, + 'maximumFileSize': maximumFileSize, + 'allowedFileExtensions': allowedFileExtensions, + 'compression': compression?.value, + 'encryption': encryption, + 'antivirus': antivirus, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Bucket.fromMap(res.data); + } + + /// Delete bucket + /// + /// Delete a storage bucket by its unique ID. + Future deleteBucket({required String bucketId}) async { + final String apiPath = + '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List files + /// + /// Get a list of all the user files. You can use the query params to filter + /// your results. + Future<models.FileList> listFiles( + {required String bucketId, List<String>? queries, String? search}) async { + final String apiPath = + '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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](https://appwrite.io/docs/server/storage#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<models.File> createFile( + {required String bucketId, + required String fileId, + required InputFile file, + List<String>? permissions, + Function(UploadProgress)? onProgress}) async { + final String apiPath = + '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); + + final Map<String, dynamic> apiParams = { + 'fileId': fileId, + 'file': file, + 'permissions': permissions, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'multipart/form-data', + }; + + String idParamName = ''; + idParamName = 'fileId'; + final paramName = 'file'; + final res = await client.chunkedUpload( + path: apiPath, + params: apiParams, + paramName: paramName, + idParamName: idParamName, + headers: apiHeaders, + onProgress: onProgress, + ); + + 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<models.File> getFile( + {required String bucketId, required String fileId}) async { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}' + .replaceAll('{bucketId}', bucketId) + .replaceAll('{fileId}', fileId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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<models.File> updateFile( + {required String bucketId, + required String fileId, + String? name, + List<String>? permissions}) async { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}' + .replaceAll('{bucketId}', bucketId) + .replaceAll('{fileId}', fileId); + + final Map<String, dynamic> apiParams = { + 'name': name, + 'permissions': permissions, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}' + .replaceAll('{bucketId}', bucketId) + .replaceAll('{fileId}', fileId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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<Uint8List> getFileDownload( + {required String bucketId, required String fileId}) async { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download' + .replaceAll('{bucketId}', bucketId) + .replaceAll('{fileId}', fileId); + + final Map<String, dynamic> params = { + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, 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<Uint8List> getFilePreview( + {required String bucketId, + required String fileId, + int? width, + int? height, + enums.ImageGravity? gravity, + int? quality, + int? borderWidth, + String? borderColor, + int? borderRadius, + double? opacity, + int? rotation, + String? background, + enums.ImageFormat? output}) async { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview' + .replaceAll('{bucketId}', bucketId) + .replaceAll('{fileId}', fileId); + + final Map<String, dynamic> params = { + 'width': width, + 'height': height, + 'gravity': gravity?.value, + 'quality': quality, + 'borderWidth': borderWidth, + 'borderColor': borderColor, + 'borderRadius': borderRadius, + 'opacity': opacity, + 'rotation': rotation, + 'background': background, + 'output': output?.value, + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, 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<Uint8List> getFileView( + {required String bucketId, required String fileId}) async { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view' + .replaceAll('{bucketId}', bucketId) + .replaceAll('{fileId}', fileId); + + final Map<String, dynamic> params = { + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: params, responseType: ResponseType.bytes); + return res.data; + } +} diff --git a/lib/services/teams.dart b/lib/services/teams.dart index 699608fb..7833e8f6 100644 --- a/lib/services/teams.dart +++ b/lib/services/teams.dart @@ -3,352 +3,342 @@ part of '../dart_appwrite.dart'; /// 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(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. - Future<models.TeamList> list({List<String>? queries, String? search}) async { - final String apiPath = '/teams'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - 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<models.Team> create({required String teamId, required String name, List<String>? roles}) async { - final String apiPath = '/teams'; - - final Map<String, dynamic> apiParams = { - - 'teamId': teamId, -'name': name, -'roles': roles, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Team.fromMap(res.data); - - } - - /// Get team - /// - /// Get a team by its ID. All team members have read access for this resource. - Future<models.Team> get({required String teamId}) async { - final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Team.fromMap(res.data); - - } - - /// Update name - /// - /// Update the team's name by its unique ID. - Future<models.Team> updateName({required String teamId, required String name}) async { - final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); - - final Map<String, dynamic> apiParams = { - - 'name': name, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// List 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. Hide sensitive attributes from - /// the response by toggling membership privacy in the Console. - Future<models.MembershipList> listMemberships({required String teamId, List<String>? queries, String? search}) async { - final String apiPath = '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MembershipList.fromMap(res.data); - - } - - /// Create team membership - /// - /// Invite a new member to join your team. Provide an ID for existing users, or - /// invite unregistered users using an email or phone number. If initiated from - /// a Client SDK, Appwrite will send an email or sms with a link to join the - /// team to the invited user, and an account will be created for them if one - /// doesn't exist. If initiated from a Server SDK, the new member will be added - /// automatically to the team. - /// - /// You only need to provide one of a user ID, email, or phone number. Appwrite - /// will prioritize accepting the user ID > email > phone number if you provide - /// more than one of these parameters. - /// - /// Use the `url` parameter to redirect the user from the invitation email to - /// your app. After the user is redirected, use the [Update Team Membership - /// Status](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus) - /// 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) - /// Appwrite will accept the only redirect URLs under the domains you have - /// added as a platform on the Appwrite Console. - /// - Future<models.Membership> createMembership({required String teamId, required List<String> roles, String? email, String? userId, String? phone, String? url, String? name}) async { - final String apiPath = '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); - - final Map<String, dynamic> apiParams = { - - 'email': email, -'userId': userId, -'phone': phone, -'roles': roles, -'url': url, -'name': name, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - 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. Hide sensitive attributes from the response by - /// toggling membership privacy in the Console. - Future<models.Membership> getMembership({required String teamId, required String membershipId}) async { - final String apiPath = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Membership.fromMap(res.data); - - } - - /// Update membership - /// - /// 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](https://appwrite.io/docs/permissions). - /// - Future<models.Membership> updateMembership({required String teamId, required String membershipId, required List<String> roles}) async { - final String apiPath = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); - - final Map<String, dynamic> apiParams = { - - 'roles': roles, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - 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<models.Membership> updateMembershipStatus({required String teamId, required String membershipId, required String userId, required String secret}) async { - final String apiPath = '/teams/{teamId}/memberships/{membershipId}/status'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'secret': secret, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Membership.fromMap(res.data); - - } - - /// Get team preferences - /// - /// Get the team's shared preferences by its unique ID. If a preference doesn't - /// need to be shared by all team members, prefer storing them in [user - /// preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs). - Future<models.Preferences> getPrefs({required String teamId}) async { - final String apiPath = '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - - } - - /// Update preferences - /// - /// Update the team's preferences by its unique ID. The object you pass is - /// stored as is and replaces any previous value. The maximum allowed prefs - /// size is 64kB and throws an error if exceeded. - Future<models.Preferences> updatePrefs({required String teamId, required Map prefs}) async { - final String apiPath = '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); - - final Map<String, dynamic> apiParams = { - - 'prefs': prefs, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - - } -} \ No newline at end of file + Teams(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. + Future<models.TeamList> list({List<String>? queries, String? search}) async { + final String apiPath = '/teams'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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<models.Team> create( + {required String teamId, + required String name, + List<String>? roles}) async { + final String apiPath = '/teams'; + + final Map<String, dynamic> apiParams = { + 'teamId': teamId, + 'name': name, + 'roles': roles, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Team.fromMap(res.data); + } + + /// Get team + /// + /// Get a team by its ID. All team members have read access for this resource. + Future<models.Team> get({required String teamId}) async { + final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Team.fromMap(res.data); + } + + /// Update name + /// + /// Update the team's name by its unique ID. + Future<models.Team> updateName( + {required String teamId, required String name}) async { + final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); + + final Map<String, dynamic> apiParams = { + 'name': name, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// List 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. Hide sensitive attributes from + /// the response by toggling membership privacy in the Console. + Future<models.MembershipList> listMemberships( + {required String teamId, List<String>? queries, String? search}) async { + final String apiPath = + '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MembershipList.fromMap(res.data); + } + + /// Create team membership + /// + /// Invite a new member to join your team. Provide an ID for existing users, or + /// invite unregistered users using an email or phone number. If initiated from + /// a Client SDK, Appwrite will send an email or sms with a link to join the + /// team to the invited user, and an account will be created for them if one + /// doesn't exist. If initiated from a Server SDK, the new member will be added + /// automatically to the team. + /// + /// You only need to provide one of a user ID, email, or phone number. Appwrite + /// will prioritize accepting the user ID > email > phone number if you provide + /// more than one of these parameters. + /// + /// Use the `url` parameter to redirect the user from the invitation email to + /// your app. After the user is redirected, use the [Update Team Membership + /// Status](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus) + /// 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) + /// Appwrite will accept the only redirect URLs under the domains you have + /// added as a platform on the Appwrite Console. + /// + Future<models.Membership> createMembership( + {required String teamId, + required List<String> roles, + String? email, + String? userId, + String? phone, + String? url, + String? name}) async { + final String apiPath = + '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); + + final Map<String, dynamic> apiParams = { + 'email': email, + 'userId': userId, + 'phone': phone, + 'roles': roles, + 'url': url, + 'name': name, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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. Hide sensitive attributes from the response by + /// toggling membership privacy in the Console. + Future<models.Membership> getMembership( + {required String teamId, required String membershipId}) async { + final String apiPath = '/teams/{teamId}/memberships/{membershipId}' + .replaceAll('{teamId}', teamId) + .replaceAll('{membershipId}', membershipId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Membership.fromMap(res.data); + } + + /// Update membership + /// + /// 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](https://appwrite.io/docs/permissions). + /// + Future<models.Membership> updateMembership( + {required String teamId, + required String membershipId, + required List<String> roles}) async { + final String apiPath = '/teams/{teamId}/memberships/{membershipId}' + .replaceAll('{teamId}', teamId) + .replaceAll('{membershipId}', membershipId); + + final Map<String, dynamic> apiParams = { + 'roles': roles, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams/{teamId}/memberships/{membershipId}' + .replaceAll('{teamId}', teamId) + .replaceAll('{membershipId}', membershipId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + 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<models.Membership> updateMembershipStatus( + {required String teamId, + required String membershipId, + required String userId, + required String secret}) async { + final String apiPath = '/teams/{teamId}/memberships/{membershipId}/status' + .replaceAll('{teamId}', teamId) + .replaceAll('{membershipId}', membershipId); + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'secret': secret, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Membership.fromMap(res.data); + } + + /// Get team preferences + /// + /// Get the team's shared preferences by its unique ID. If a preference doesn't + /// need to be shared by all team members, prefer storing them in [user + /// preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs). + Future<models.Preferences> getPrefs({required String teamId}) async { + final String apiPath = + '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + } + + /// Update preferences + /// + /// Update the team's preferences by its unique ID. The object you pass is + /// stored as is and replaces any previous value. The maximum allowed prefs + /// size is 64kB and throws an error if exceeded. + Future<models.Preferences> updatePrefs( + {required String teamId, required Map prefs}) async { + final String apiPath = + '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); + + final Map<String, dynamic> apiParams = { + 'prefs': prefs, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + } +} diff --git a/lib/services/users.dart b/lib/services/users.dart index 25acfa75..28673732 100644 --- a/lib/services/users.dart +++ b/lib/services/users.dart @@ -2,1055 +2,1023 @@ part of '../dart_appwrite.dart'; /// The Users service allows you to manage your project users. class Users extends Service { - Users(super.client); - - /// List users - /// - /// Get a list of all the project's users. You can use the query params to - /// filter your results. - Future<models.UserList> list({List<String>? queries, String? search}) async { - final String apiPath = '/users'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.UserList.fromMap(res.data); - - } - - /// Create user - /// - /// Create a new user. - Future<models.User> create({required String userId, String? email, String? phone, String? password, String? name}) async { - final String apiPath = '/users'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'email': email, -'phone': phone, -'password': password, -'name': name, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create user with Argon2 password - /// - /// Create a new user. Password provided must be hashed with the - /// [Argon2](https://en.wikipedia.org/wiki/Argon2) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future<models.User> createArgon2User({required String userId, required String email, required String password, String? name}) async { - final String apiPath = '/users/argon2'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'email': email, -'password': password, -'name': name, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create user with bcrypt password - /// - /// Create a new user. Password provided must be hashed with the - /// [Bcrypt](https://en.wikipedia.org/wiki/Bcrypt) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future<models.User> createBcryptUser({required String userId, required String email, required String password, String? name}) async { - final String apiPath = '/users/bcrypt'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'email': email, -'password': password, -'name': name, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// List identities - /// - /// Get identities for all users. - Future<models.IdentityList> listIdentities({List<String>? queries, String? search}) async { - final String apiPath = '/users/identities'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, -'search': search, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.IdentityList.fromMap(res.data); - - } - - /// Delete identity - /// - /// Delete an identity by its unique ID. - Future deleteIdentity({required String identityId}) async { - final String apiPath = '/users/identities/{identityId}'.replaceAll('{identityId}', identityId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Create user with MD5 password - /// - /// Create a new user. Password provided must be hashed with the - /// [MD5](https://en.wikipedia.org/wiki/MD5) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future<models.User> createMD5User({required String userId, required String email, required String password, String? name}) async { - final String apiPath = '/users/md5'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'email': email, -'password': password, -'name': name, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create user with PHPass password - /// - /// Create a new user. Password provided must be hashed with the - /// [PHPass](https://www.openwall.com/phpass/) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future<models.User> createPHPassUser({required String userId, required String email, required String password, String? name}) async { - final String apiPath = '/users/phpass'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'email': email, -'password': password, -'name': name, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create user with Scrypt password - /// - /// Create a new user. Password provided must be hashed with the - /// [Scrypt](https://github.com/Tarsnap/scrypt) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future<models.User> createScryptUser({required String userId, required String email, required String password, required String passwordSalt, required int passwordCpu, required int passwordMemory, required int passwordParallel, required int passwordLength, String? name}) async { - final String apiPath = '/users/scrypt'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'email': email, -'password': password, -'passwordSalt': passwordSalt, -'passwordCpu': passwordCpu, -'passwordMemory': passwordMemory, -'passwordParallel': passwordParallel, -'passwordLength': passwordLength, -'name': name, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create user with Scrypt modified password - /// - /// Create a new user. Password provided must be hashed with the [Scrypt - /// Modified](https://gist.github.com/Meldiron/eecf84a0225eccb5a378d45bb27462cc) - /// algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future<models.User> createScryptModifiedUser({required String userId, required String email, required String password, required String passwordSalt, required String passwordSaltSeparator, required String passwordSignerKey, String? name}) async { - final String apiPath = '/users/scrypt-modified'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'email': email, -'password': password, -'passwordSalt': passwordSalt, -'passwordSaltSeparator': passwordSaltSeparator, -'passwordSignerKey': passwordSignerKey, -'name': name, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create user with SHA password - /// - /// Create a new user. Password provided must be hashed with the - /// [SHA](https://en.wikipedia.org/wiki/Secure_Hash_Algorithm) algorithm. Use - /// the [POST /users](https://appwrite.io/docs/server/users#usersCreate) - /// endpoint to create users with a plain text password. - Future<models.User> createSHAUser({required String userId, required String email, required String password, enums.PasswordHash? passwordVersion, String? name}) async { - final String apiPath = '/users/sha'; - - final Map<String, dynamic> apiParams = { - - 'userId': userId, -'email': email, -'password': password, -'passwordVersion': passwordVersion?.value, -'name': name, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Get user - /// - /// Get a user by its unique ID. - Future<models.User> get({required String userId}) async { - final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Delete user - /// - /// Delete a user by its unique ID, thereby releasing it's ID. Since ID is - /// released and can be reused, all user-related resources like documents or - /// storage files should be deleted before user deletion. If you want to keep - /// ID reserved, use the - /// [updateStatus](https://appwrite.io/docs/server/users#usersUpdateStatus) - /// endpoint instead. - Future delete({required String userId}) async { - final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Update email - /// - /// Update the user email by its unique ID. - Future<models.User> updateEmail({required String userId, required String email}) async { - final String apiPath = '/users/{userId}/email'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - 'email': email, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Create user JWT - /// - /// Use this endpoint to create a JSON Web Token for user by its unique ID. You - /// can use the resulting JWT to authenticate on behalf of the user. The JWT - /// secret will become invalid if the session it uses gets deleted. - Future<models.Jwt> createJWT({required String userId, String? sessionId, int? duration}) async { - final String apiPath = '/users/{userId}/jwts'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - 'sessionId': sessionId, -'duration': duration, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Jwt.fromMap(res.data); - - } - - /// Update user labels - /// - /// Update the user labels by its unique ID. - /// - /// Labels can be used to grant access to resources. While teams are a way for - /// user's to share access to a resource, labels can be defined by the - /// developer to grant access without an invitation. See the [Permissions - /// docs](https://appwrite.io/docs/permissions) for more info. - Future<models.User> updateLabels({required String userId, required List<String> labels}) async { - final String apiPath = '/users/{userId}/labels'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - 'labels': labels, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// List user logs - /// - /// Get the user activity logs list by its unique ID. - Future<models.LogList> listLogs({required String userId, List<String>? queries}) async { - final String apiPath = '/users/{userId}/logs'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - - } - - /// List user memberships - /// - /// Get the user membership list by its unique ID. - Future<models.MembershipList> listMemberships({required String userId}) async { - final String apiPath = '/users/{userId}/memberships'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MembershipList.fromMap(res.data); - - } - - /// Update MFA - /// - /// Enable or disable MFA on a user account. - Future<models.User> updateMfa({required String userId, required bool mfa}) async { - final String apiPath = '/users/{userId}/mfa'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - 'mfa': mfa, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Delete authenticator - /// - /// Delete an authenticator app. - Future<models.User> deleteMfaAuthenticator({required String userId, required enums.AuthenticatorType type}) async { - final String apiPath = '/users/{userId}/mfa/authenticators/{type}'.replaceAll('{userId}', userId).replaceAll('{type}', type.value); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// List factors - /// - /// List the factors available on the account to be used as a MFA challange. - Future<models.MfaFactors> listMfaFactors({required String userId}) async { - final String apiPath = '/users/{userId}/mfa/factors'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaFactors.fromMap(res.data); - - } - - /// Get MFA recovery codes - /// - /// Get recovery codes that can be used as backup for MFA flow by User ID. - /// Before getting codes, they must be generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. - Future<models.MfaRecoveryCodes> getMfaRecoveryCodes({required String userId}) async { - final String apiPath = '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - - } - - /// Regenerate MFA recovery codes - /// - /// Regenerate recovery codes that can be used as backup for MFA flow by User - /// ID. Before regenerating codes, they must be first generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. - Future<models.MfaRecoveryCodes> updateMfaRecoveryCodes({required String userId}) async { - final String apiPath = '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - - } - - /// Create MFA recovery codes - /// - /// Generate recovery codes used as backup for MFA flow for User ID. Recovery - /// codes can be used as a MFA verification type in - /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) - /// method by client SDK. - Future<models.MfaRecoveryCodes> createMfaRecoveryCodes({required String userId}) async { - final String apiPath = '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - - } - - /// Update name - /// - /// Update the user name by its unique ID. - Future<models.User> updateName({required String userId, required String name}) async { - final String apiPath = '/users/{userId}/name'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - 'name': name, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Update password - /// - /// Update the user password by its unique ID. - Future<models.User> updatePassword({required String userId, required String password}) async { - final String apiPath = '/users/{userId}/password'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - 'password': password, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Update phone - /// - /// Update the user phone by its unique ID. - Future<models.User> updatePhone({required String userId, required String number}) async { - final String apiPath = '/users/{userId}/phone'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - 'number': number, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Get user preferences - /// - /// Get the user preferences by its unique ID. - Future<models.Preferences> getPrefs({required String userId}) async { - final String apiPath = '/users/{userId}/prefs'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - - } - - /// Update user preferences - /// - /// Update the user preferences by its unique ID. 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<models.Preferences> updatePrefs({required String userId, required Map prefs}) async { - final String apiPath = '/users/{userId}/prefs'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - 'prefs': prefs, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - - } - - /// List user sessions - /// - /// Get the user sessions list by its unique ID. - Future<models.SessionList> listSessions({required String userId}) async { - final String apiPath = '/users/{userId}/sessions'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SessionList.fromMap(res.data); - - } - - /// Create session - /// - /// Creates a session for a user. Returns an immediately usable session object. - /// - /// If you want to generate a token for a custom authentication flow, use the - /// [POST - /// /users/{userId}/tokens](https://appwrite.io/docs/server/users#createToken) - /// endpoint. - Future<models.Session> createSession({required String userId}) async { - final String apiPath = '/users/{userId}/sessions'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - - } - - /// Delete user sessions - /// - /// Delete all user's sessions by using the user's unique ID. - Future deleteSessions({required String userId}) async { - final String apiPath = '/users/{userId}/sessions'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Delete user session - /// - /// Delete a user sessions by its unique ID. - Future deleteSession({required String userId, required String sessionId}) async { - final String apiPath = '/users/{userId}/sessions/{sessionId}'.replaceAll('{userId}', userId).replaceAll('{sessionId}', sessionId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Update user status - /// - /// Update the user status by its unique ID. Use this endpoint as an - /// alternative to deleting a user if you want to keep user's ID reserved. - Future<models.User> updateStatus({required String userId, required bool status}) async { - final String apiPath = '/users/{userId}/status'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - 'status': status, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// List user targets - /// - /// List the messaging targets that are associated with a user. - Future<models.TargetList> listTargets({required String userId, List<String>? queries}) async { - final String apiPath = '/users/{userId}/targets'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.TargetList.fromMap(res.data); - - } - - /// Create user target - /// - /// Create a messaging target. - Future<models.Target> createTarget({required String userId, required String targetId, required enums.MessagingProviderType providerType, required String identifier, String? providerId, String? name}) async { - final String apiPath = '/users/{userId}/targets'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - 'targetId': targetId, -'providerType': providerType.value, -'identifier': identifier, -'providerId': providerId, -'name': name, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Target.fromMap(res.data); - - } - - /// Get user target - /// - /// Get a user's push notification target by ID. - Future<models.Target> getTarget({required String userId, required String targetId}) async { - final String apiPath = '/users/{userId}/targets/{targetId}'.replaceAll('{userId}', userId).replaceAll('{targetId}', targetId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Target.fromMap(res.data); - - } - - /// Update user target - /// - /// Update a messaging target. - Future<models.Target> updateTarget({required String userId, required String targetId, String? identifier, String? providerId, String? name}) async { - final String apiPath = '/users/{userId}/targets/{targetId}'.replaceAll('{userId}', userId).replaceAll('{targetId}', targetId); - - final Map<String, dynamic> apiParams = { - - 'identifier': identifier, -'providerId': providerId, -'name': name, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Target.fromMap(res.data); - - } - - /// Delete user target - /// - /// Delete a messaging target. - Future deleteTarget({required String userId, required String targetId}) async { - final String apiPath = '/users/{userId}/targets/{targetId}'.replaceAll('{userId}', userId).replaceAll('{targetId}', targetId); - - final Map<String, dynamic> apiParams = { - - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - - } - - /// Create token - /// - /// Returns a token with a secret key for creating a session. Use the user ID - /// and secret and submit a request to the [PUT - /// /account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. - /// - Future<models.Token> createToken({required String userId, int? length, int? expire}) async { - final String apiPath = '/users/{userId}/tokens'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - 'length': length, -'expire': expire, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - - } - - /// Update email verification - /// - /// Update the user email verification status by its unique ID. - Future<models.User> updateEmailVerification({required String userId, required bool emailVerification}) async { - final String apiPath = '/users/{userId}/verification'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - 'emailVerification': emailVerification, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } - - /// Update phone verification - /// - /// Update the user phone verification status by its unique ID. - Future<models.User> updatePhoneVerification({required String userId, required bool phoneVerification}) async { - final String apiPath = '/users/{userId}/verification/phone'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - - 'phoneVerification': phoneVerification, - - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - - }; - - final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - - } -} \ No newline at end of file + Users(super.client); + + /// List users + /// + /// Get a list of all the project's users. You can use the query params to + /// filter your results. + Future<models.UserList> list({List<String>? queries, String? search}) async { + final String apiPath = '/users'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.UserList.fromMap(res.data); + } + + /// Create user + /// + /// Create a new user. + Future<models.User> create( + {required String userId, + String? email, + String? phone, + String? password, + String? name}) async { + final String apiPath = '/users'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'email': email, + 'phone': phone, + 'password': password, + 'name': name, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create user with Argon2 password + /// + /// Create a new user. Password provided must be hashed with the + /// [Argon2](https://en.wikipedia.org/wiki/Argon2) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future<models.User> createArgon2User( + {required String userId, + required String email, + required String password, + String? name}) async { + final String apiPath = '/users/argon2'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'email': email, + 'password': password, + 'name': name, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create user with bcrypt password + /// + /// Create a new user. Password provided must be hashed with the + /// [Bcrypt](https://en.wikipedia.org/wiki/Bcrypt) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future<models.User> createBcryptUser( + {required String userId, + required String email, + required String password, + String? name}) async { + final String apiPath = '/users/bcrypt'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'email': email, + 'password': password, + 'name': name, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// List identities + /// + /// Get identities for all users. + Future<models.IdentityList> listIdentities( + {List<String>? queries, String? search}) async { + final String apiPath = '/users/identities'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, + 'search': search, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.IdentityList.fromMap(res.data); + } + + /// Delete identity + /// + /// Delete an identity by its unique ID. + Future deleteIdentity({required String identityId}) async { + final String apiPath = + '/users/identities/{identityId}'.replaceAll('{identityId}', identityId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Create user with MD5 password + /// + /// Create a new user. Password provided must be hashed with the + /// [MD5](https://en.wikipedia.org/wiki/MD5) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future<models.User> createMD5User( + {required String userId, + required String email, + required String password, + String? name}) async { + final String apiPath = '/users/md5'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'email': email, + 'password': password, + 'name': name, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create user with PHPass password + /// + /// Create a new user. Password provided must be hashed with the + /// [PHPass](https://www.openwall.com/phpass/) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future<models.User> createPHPassUser( + {required String userId, + required String email, + required String password, + String? name}) async { + final String apiPath = '/users/phpass'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'email': email, + 'password': password, + 'name': name, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create user with Scrypt password + /// + /// Create a new user. Password provided must be hashed with the + /// [Scrypt](https://github.com/Tarsnap/scrypt) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future<models.User> createScryptUser( + {required String userId, + required String email, + required String password, + required String passwordSalt, + required int passwordCpu, + required int passwordMemory, + required int passwordParallel, + required int passwordLength, + String? name}) async { + final String apiPath = '/users/scrypt'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'email': email, + 'password': password, + 'passwordSalt': passwordSalt, + 'passwordCpu': passwordCpu, + 'passwordMemory': passwordMemory, + 'passwordParallel': passwordParallel, + 'passwordLength': passwordLength, + 'name': name, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create user with Scrypt modified password + /// + /// Create a new user. Password provided must be hashed with the [Scrypt + /// Modified](https://gist.github.com/Meldiron/eecf84a0225eccb5a378d45bb27462cc) + /// algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future<models.User> createScryptModifiedUser( + {required String userId, + required String email, + required String password, + required String passwordSalt, + required String passwordSaltSeparator, + required String passwordSignerKey, + String? name}) async { + final String apiPath = '/users/scrypt-modified'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'email': email, + 'password': password, + 'passwordSalt': passwordSalt, + 'passwordSaltSeparator': passwordSaltSeparator, + 'passwordSignerKey': passwordSignerKey, + 'name': name, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create user with SHA password + /// + /// Create a new user. Password provided must be hashed with the + /// [SHA](https://en.wikipedia.org/wiki/Secure_Hash_Algorithm) algorithm. Use + /// the [POST /users](https://appwrite.io/docs/server/users#usersCreate) + /// endpoint to create users with a plain text password. + Future<models.User> createSHAUser( + {required String userId, + required String email, + required String password, + enums.PasswordHash? passwordVersion, + String? name}) async { + final String apiPath = '/users/sha'; + + final Map<String, dynamic> apiParams = { + 'userId': userId, + 'email': email, + 'password': password, + 'passwordVersion': passwordVersion?.value, + 'name': name, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Get user + /// + /// Get a user by its unique ID. + Future<models.User> get({required String userId}) async { + final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Delete user + /// + /// Delete a user by its unique ID, thereby releasing it's ID. Since ID is + /// released and can be reused, all user-related resources like documents or + /// storage files should be deleted before user deletion. If you want to keep + /// ID reserved, use the + /// [updateStatus](https://appwrite.io/docs/server/users#usersUpdateStatus) + /// endpoint instead. + Future delete({required String userId}) async { + final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Update email + /// + /// Update the user email by its unique ID. + Future<models.User> updateEmail( + {required String userId, required String email}) async { + final String apiPath = + '/users/{userId}/email'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + 'email': email, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Create user JWT + /// + /// Use this endpoint to create a JSON Web Token for user by its unique ID. You + /// can use the resulting JWT to authenticate on behalf of the user. The JWT + /// secret will become invalid if the session it uses gets deleted. + Future<models.Jwt> createJWT( + {required String userId, String? sessionId, int? duration}) async { + final String apiPath = + '/users/{userId}/jwts'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + 'sessionId': sessionId, + 'duration': duration, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Jwt.fromMap(res.data); + } + + /// Update user labels + /// + /// Update the user labels by its unique ID. + /// + /// Labels can be used to grant access to resources. While teams are a way for + /// user's to share access to a resource, labels can be defined by the + /// developer to grant access without an invitation. See the [Permissions + /// docs](https://appwrite.io/docs/permissions) for more info. + Future<models.User> updateLabels( + {required String userId, required List<String> labels}) async { + final String apiPath = + '/users/{userId}/labels'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + 'labels': labels, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// List user logs + /// + /// Get the user activity logs list by its unique ID. + Future<models.LogList> listLogs( + {required String userId, List<String>? queries}) async { + final String apiPath = + '/users/{userId}/logs'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + } + + /// List user memberships + /// + /// Get the user membership list by its unique ID. + Future<models.MembershipList> listMemberships( + {required String userId}) async { + final String apiPath = + '/users/{userId}/memberships'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MembershipList.fromMap(res.data); + } + + /// Update MFA + /// + /// Enable or disable MFA on a user account. + Future<models.User> updateMfa( + {required String userId, required bool mfa}) async { + final String apiPath = '/users/{userId}/mfa'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + 'mfa': mfa, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Delete authenticator + /// + /// Delete an authenticator app. + Future<models.User> deleteMfaAuthenticator( + {required String userId, required enums.AuthenticatorType type}) async { + final String apiPath = '/users/{userId}/mfa/authenticators/{type}' + .replaceAll('{userId}', userId) + .replaceAll('{type}', type.value); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// List factors + /// + /// List the factors available on the account to be used as a MFA challange. + Future<models.MfaFactors> listMfaFactors({required String userId}) async { + final String apiPath = + '/users/{userId}/mfa/factors'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaFactors.fromMap(res.data); + } + + /// Get MFA recovery codes + /// + /// Get recovery codes that can be used as backup for MFA flow by User ID. + /// Before getting codes, they must be generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. + Future<models.MfaRecoveryCodes> getMfaRecoveryCodes( + {required String userId}) async { + final String apiPath = + '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + } + + /// Regenerate MFA recovery codes + /// + /// Regenerate recovery codes that can be used as backup for MFA flow by User + /// ID. Before regenerating codes, they must be first generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. + Future<models.MfaRecoveryCodes> updateMfaRecoveryCodes( + {required String userId}) async { + final String apiPath = + '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + } + + /// Create MFA recovery codes + /// + /// Generate recovery codes used as backup for MFA flow for User ID. Recovery + /// codes can be used as a MFA verification type in + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method by client SDK. + Future<models.MfaRecoveryCodes> createMfaRecoveryCodes( + {required String userId}) async { + final String apiPath = + '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + } + + /// Update name + /// + /// Update the user name by its unique ID. + Future<models.User> updateName( + {required String userId, required String name}) async { + final String apiPath = + '/users/{userId}/name'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + 'name': name, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Update password + /// + /// Update the user password by its unique ID. + Future<models.User> updatePassword( + {required String userId, required String password}) async { + final String apiPath = + '/users/{userId}/password'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + 'password': password, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Update phone + /// + /// Update the user phone by its unique ID. + Future<models.User> updatePhone( + {required String userId, required String number}) async { + final String apiPath = + '/users/{userId}/phone'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + 'number': number, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Get user preferences + /// + /// Get the user preferences by its unique ID. + Future<models.Preferences> getPrefs({required String userId}) async { + final String apiPath = + '/users/{userId}/prefs'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + } + + /// Update user preferences + /// + /// Update the user preferences by its unique ID. 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<models.Preferences> updatePrefs( + {required String userId, required Map prefs}) async { + final String apiPath = + '/users/{userId}/prefs'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + 'prefs': prefs, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + } + + /// List user sessions + /// + /// Get the user sessions list by its unique ID. + Future<models.SessionList> listSessions({required String userId}) async { + final String apiPath = + '/users/{userId}/sessions'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SessionList.fromMap(res.data); + } + + /// Create session + /// + /// Creates a session for a user. Returns an immediately usable session object. + /// + /// If you want to generate a token for a custom authentication flow, use the + /// [POST + /// /users/{userId}/tokens](https://appwrite.io/docs/server/users#createToken) + /// endpoint. + Future<models.Session> createSession({required String userId}) async { + final String apiPath = + '/users/{userId}/sessions'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + } + + /// Delete user sessions + /// + /// Delete all user's sessions by using the user's unique ID. + Future deleteSessions({required String userId}) async { + final String apiPath = + '/users/{userId}/sessions'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Delete user session + /// + /// Delete a user sessions by its unique ID. + Future deleteSession( + {required String userId, required String sessionId}) async { + final String apiPath = '/users/{userId}/sessions/{sessionId}' + .replaceAll('{userId}', userId) + .replaceAll('{sessionId}', sessionId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Update user status + /// + /// Update the user status by its unique ID. Use this endpoint as an + /// alternative to deleting a user if you want to keep user's ID reserved. + Future<models.User> updateStatus( + {required String userId, required bool status}) async { + final String apiPath = + '/users/{userId}/status'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + 'status': status, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// List user targets + /// + /// List the messaging targets that are associated with a user. + Future<models.TargetList> listTargets( + {required String userId, List<String>? queries}) async { + final String apiPath = + '/users/{userId}/targets'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.TargetList.fromMap(res.data); + } + + /// Create user target + /// + /// Create a messaging target. + Future<models.Target> createTarget( + {required String userId, + required String targetId, + required enums.MessagingProviderType providerType, + required String identifier, + String? providerId, + String? name}) async { + final String apiPath = + '/users/{userId}/targets'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + 'targetId': targetId, + 'providerType': providerType.value, + 'identifier': identifier, + 'providerId': providerId, + 'name': name, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Target.fromMap(res.data); + } + + /// Get user target + /// + /// Get a user's push notification target by ID. + Future<models.Target> getTarget( + {required String userId, required String targetId}) async { + final String apiPath = '/users/{userId}/targets/{targetId}' + .replaceAll('{userId}', userId) + .replaceAll('{targetId}', targetId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Target.fromMap(res.data); + } + + /// Update user target + /// + /// Update a messaging target. + Future<models.Target> updateTarget( + {required String userId, + required String targetId, + String? identifier, + String? providerId, + String? name}) async { + final String apiPath = '/users/{userId}/targets/{targetId}' + .replaceAll('{userId}', userId) + .replaceAll('{targetId}', targetId); + + final Map<String, dynamic> apiParams = { + 'identifier': identifier, + 'providerId': providerId, + 'name': name, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Target.fromMap(res.data); + } + + /// Delete user target + /// + /// Delete a messaging target. + Future deleteTarget( + {required String userId, required String targetId}) async { + final String apiPath = '/users/{userId}/targets/{targetId}' + .replaceAll('{userId}', userId) + .replaceAll('{targetId}', targetId); + + final Map<String, dynamic> apiParams = {}; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.delete, + path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + } + + /// Create token + /// + /// Returns a token with a secret key for creating a session. Use the user ID + /// and secret and submit a request to the [PUT + /// /account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. + /// + Future<models.Token> createToken( + {required String userId, int? length, int? expire}) async { + final String apiPath = + '/users/{userId}/tokens'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + 'length': length, + 'expire': expire, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + } + + /// Update email verification + /// + /// Update the user email verification status by its unique ID. + Future<models.User> updateEmailVerification( + {required String userId, required bool emailVerification}) async { + final String apiPath = + '/users/{userId}/verification'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + 'emailVerification': emailVerification, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } + + /// Update phone verification + /// + /// Update the user phone verification status by its unique ID. + Future<models.User> updatePhoneVerification( + {required String userId, required bool phoneVerification}) async { + final String apiPath = + '/users/{userId}/verification/phone'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + 'phoneVerification': phoneVerification, + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + } +} diff --git a/lib/src/client.dart b/lib/src/client.dart index 8dee2426..bac07cfb 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -8,7 +8,7 @@ import 'upload_progress.dart'; /// [Client] that handles requests to Appwrite abstract class Client { /// The size for cunked uploads in bytes. - static const int CHUNK_SIZE = 5*1024*1024; + static const int CHUNK_SIZE = 5 * 1024 * 1024; /// Holds configuration such as project. late Map<String, String> config; @@ -27,7 +27,7 @@ abstract class Client { Future<String?> webAuth(Uri url); /// Set self signed to [status]. - /// + /// /// If self signed is true, [Client] will ignore invalid certificates. /// This is helpful in environments where your Appwrite /// instance does not have a valid SSL certificate. @@ -78,7 +78,8 @@ abstract class Client { }); /// Send the API request. - Future<Response> call(HttpMethod method, { + Future<Response> call( + HttpMethod method, { String path = '', Map<String, String> headers = const {}, Map<String, dynamic> params = const {}, diff --git a/lib/src/client_base.dart b/lib/src/client_base.dart index 21992eb0..95476465 100644 --- a/lib/src/client_base.dart +++ b/lib/src/client_base.dart @@ -2,21 +2,25 @@ import 'response.dart'; import 'client.dart'; import 'enums.dart'; -abstract class ClientBase implements Client { +abstract class ClientBase implements Client { /// Your project ID @override ClientBase setProject(value); + /// Your secret API key @override ClientBase setKey(value); + /// Your secret JSON Web Token @override ClientBase setJWT(value); @override ClientBase setLocale(value); + /// The user session to authenticate with @override ClientBase setSession(value); + /// The user agent string of the client that made the request @override ClientBase setForwardedUserAgent(value); diff --git a/lib/src/client_browser.dart b/lib/src/client_browser.dart index 009a8454..428877a5 100644 --- a/lib/src/client_browser.dart +++ b/lib/src/client_browser.dart @@ -16,7 +16,7 @@ ClientBase createClient({ ClientBrowser(endPoint: endPoint, selfSigned: selfSigned); class ClientBrowser extends ClientBase with ClientMixin { - static const int CHUNK_SIZE = 5*1024*1024; + static const int CHUNK_SIZE = 5 * 1024 * 1024; String _endPoint; Map<String, String>? _headers; @override @@ -34,7 +34,7 @@ class ClientBrowser extends ClientBase with ClientMixin { 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', 'x-sdk-version': '12.2.0', - 'X-Appwrite-Response-Format' : '1.6.0', + 'X-Appwrite-Response-Format': '1.6.0', }; config = {}; @@ -46,47 +46,52 @@ class ClientBrowser extends ClientBase with ClientMixin { @override String get endPoint => _endPoint; - /// Your project ID - @override - ClientBrowser setProject(value) { - config['project'] = value; - addHeader('X-Appwrite-Project', value); - return this; - } - /// Your secret API key - @override - ClientBrowser setKey(value) { - config['key'] = value; - addHeader('X-Appwrite-Key', value); - return this; - } - /// Your secret JSON Web Token - @override - ClientBrowser setJWT(value) { - config['jWT'] = value; - addHeader('X-Appwrite-JWT', value); - return this; - } - @override - ClientBrowser setLocale(value) { - config['locale'] = value; - addHeader('X-Appwrite-Locale', value); - return this; - } - /// The user session to authenticate with - @override - ClientBrowser setSession(value) { - config['session'] = value; - addHeader('X-Appwrite-Session', value); - return this; - } - /// The user agent string of the client that made the request - @override - ClientBrowser setForwardedUserAgent(value) { - config['forwardedUserAgent'] = value; - addHeader('X-Forwarded-User-Agent', value); - return this; - } + /// Your project ID + @override + ClientBrowser setProject(value) { + config['project'] = value; + addHeader('X-Appwrite-Project', value); + return this; + } + + /// Your secret API key + @override + ClientBrowser setKey(value) { + config['key'] = value; + addHeader('X-Appwrite-Key', value); + return this; + } + + /// Your secret JSON Web Token + @override + ClientBrowser setJWT(value) { + config['jWT'] = value; + addHeader('X-Appwrite-JWT', value); + return this; + } + + @override + ClientBrowser setLocale(value) { + config['locale'] = value; + addHeader('X-Appwrite-Locale', value); + return this; + } + + /// The user session to authenticate with + @override + ClientBrowser setSession(value) { + config['session'] = value; + addHeader('X-Appwrite-Session', value); + return this; + } + + /// The user agent string of the client that made the request + @override + ClientBrowser setForwardedUserAgent(value) { + config['forwardedUserAgent'] = value; + addHeader('X-Forwarded-User-Agent', value); + return this; + } @override ClientBrowser setSelfSigned({bool status = true}) { @@ -131,7 +136,8 @@ class ClientBrowser extends ClientBase with ClientMixin { late Response res; if (size <= CHUNK_SIZE) { - params[paramName] = http.MultipartFile.fromBytes(paramName, file.bytes!, filename: file.filename); + params[paramName] = http.MultipartFile.fromBytes(paramName, file.bytes!, + filename: file.filename); return call( HttpMethod.post, path: path, @@ -158,8 +164,8 @@ class ClientBrowser extends ClientBase with ClientMixin { List<int> chunk = []; final end = min(offset + CHUNK_SIZE, size); chunk = file.bytes!.getRange(offset, end).toList(); - params[paramName] = - http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename); + params[paramName] = http.MultipartFile.fromBytes(paramName, chunk, + filename: file.filename); headers['content-range'] = 'bytes $offset-${min<int>((offset + CHUNK_SIZE - 1), size - 1)}/$size'; res = await call(HttpMethod.post, diff --git a/lib/src/client_io.dart b/lib/src/client_io.dart index 41ee49b6..f0b5c028 100644 --- a/lib/src/client_io.dart +++ b/lib/src/client_io.dart @@ -20,7 +20,7 @@ ClientBase createClient({ ); class ClientIO extends ClientBase with ClientMixin { - static const int CHUNK_SIZE = 5*1024*1024; + static const int CHUNK_SIZE = 5 * 1024 * 1024; String _endPoint; Map<String, String>? _headers; @override @@ -43,8 +43,9 @@ class ClientIO extends ClientBase with ClientMixin { 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', 'x-sdk-version': '12.2.0', - 'user-agent' : 'AppwriteDartSDK/12.2.0 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', - 'X-Appwrite-Response-Format' : '1.6.0', + 'user-agent': + 'AppwriteDartSDK/12.2.0 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', + 'X-Appwrite-Response-Format': '1.6.0', }; config = {}; @@ -56,47 +57,52 @@ class ClientIO extends ClientBase with ClientMixin { @override String get endPoint => _endPoint; - /// Your project ID - @override - ClientIO setProject(value) { - config['project'] = value; - addHeader('X-Appwrite-Project', value); - return this; - } - /// Your secret API key - @override - ClientIO setKey(value) { - config['key'] = value; - addHeader('X-Appwrite-Key', value); - return this; - } - /// Your secret JSON Web Token - @override - ClientIO setJWT(value) { - config['jWT'] = value; - addHeader('X-Appwrite-JWT', value); - return this; - } - @override - ClientIO setLocale(value) { - config['locale'] = value; - addHeader('X-Appwrite-Locale', value); - return this; - } - /// The user session to authenticate with - @override - ClientIO setSession(value) { - config['session'] = value; - addHeader('X-Appwrite-Session', value); - return this; - } - /// The user agent string of the client that made the request - @override - ClientIO setForwardedUserAgent(value) { - config['forwardedUserAgent'] = value; - addHeader('X-Forwarded-User-Agent', value); - return this; - } + /// Your project ID + @override + ClientIO setProject(value) { + config['project'] = value; + addHeader('X-Appwrite-Project', value); + return this; + } + + /// Your secret API key + @override + ClientIO setKey(value) { + config['key'] = value; + addHeader('X-Appwrite-Key', value); + return this; + } + + /// Your secret JSON Web Token + @override + ClientIO setJWT(value) { + config['jWT'] = value; + addHeader('X-Appwrite-JWT', value); + return this; + } + + @override + ClientIO setLocale(value) { + config['locale'] = value; + addHeader('X-Appwrite-Locale', value); + return this; + } + + /// The user session to authenticate with + @override + ClientIO setSession(value) { + config['session'] = value; + addHeader('X-Appwrite-Session', value); + return this; + } + + /// The user agent string of the client that made the request + @override + ClientIO setForwardedUserAgent(value) { + config['forwardedUserAgent'] = value; + addHeader('X-Forwarded-User-Agent', value); + return this; + } @override ClientIO setSelfSigned({bool status = true}) { @@ -190,8 +196,8 @@ class ClientIO extends ClientBase with ClientMixin { raf!.setPositionSync(offset); chunk = raf.readSync(CHUNK_SIZE); } - params[paramName] = - http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename); + params[paramName] = http.MultipartFile.fromBytes(paramName, chunk, + filename: file.filename); headers['content-range'] = 'bytes $offset-${min<int>((offset + CHUNK_SIZE - 1), size - 1)}/$size'; res = await call(HttpMethod.post, diff --git a/lib/src/client_mixin.dart b/lib/src/client_mixin.dart index 36bcdbd3..1078c313 100644 --- a/lib/src/client_mixin.dart +++ b/lib/src/client_mixin.dart @@ -40,7 +40,7 @@ class ClientMixin { } } else if (method == HttpMethod.get) { if (params.isNotEmpty) { - params = params.map((key, value){ + params = params.map((key, value) { if (value is int || value is double) { return MapEntry(key, value.toString()); } @@ -106,18 +106,23 @@ class ClientMixin { return Response(data: data); } - Future<http.Response> toResponse(http.StreamedResponse streamedResponse) async { - if(streamedResponse.statusCode == 204) { - return http.Response('', - streamedResponse.statusCode, - headers: streamedResponse.headers.map((k,v) => k.toLowerCase()=='content-type' ? MapEntry(k, 'text/plain') : MapEntry(k,v)), - request: streamedResponse.request, - isRedirect: streamedResponse.isRedirect, - persistentConnection: streamedResponse.persistentConnection, - reasonPhrase: streamedResponse.reasonPhrase, - ); - } else { - return await http.Response.fromStream(streamedResponse); - } + Future<http.Response> toResponse( + http.StreamedResponse streamedResponse) async { + if (streamedResponse.statusCode == 204) { + return http.Response( + '', + streamedResponse.statusCode, + headers: streamedResponse.headers.map((k, v) => + k.toLowerCase() == 'content-type' + ? MapEntry(k, 'text/plain') + : MapEntry(k, v)), + request: streamedResponse.request, + isRedirect: streamedResponse.isRedirect, + persistentConnection: streamedResponse.persistentConnection, + reasonPhrase: streamedResponse.reasonPhrase, + ); + } else { + return await http.Response.fromStream(streamedResponse); + } } } diff --git a/lib/src/enums/authentication_factor.dart b/lib/src/enums/authentication_factor.dart index 00d12830..1d5271eb 100644 --- a/lib/src/enums/authentication_factor.dart +++ b/lib/src/enums/authentication_factor.dart @@ -1,16 +1,14 @@ part of '../../enums.dart'; enum AuthenticationFactor { - email(value: 'email'), - phone(value: 'phone'), - totp(value: 'totp'), - recoverycode(value: 'recoverycode'); + email(value: 'email'), + phone(value: 'phone'), + totp(value: 'totp'), + recoverycode(value: 'recoverycode'); - const AuthenticationFactor({ - required this.value - }); + const AuthenticationFactor({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/authenticator_type.dart b/lib/src/enums/authenticator_type.dart index 10460393..c1fe8584 100644 --- a/lib/src/enums/authenticator_type.dart +++ b/lib/src/enums/authenticator_type.dart @@ -1,13 +1,11 @@ part of '../../enums.dart'; enum AuthenticatorType { - totp(value: 'totp'); + totp(value: 'totp'); - const AuthenticatorType({ - required this.value - }); + const AuthenticatorType({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/browser.dart b/lib/src/enums/browser.dart index 386fa11d..949f4c47 100644 --- a/lib/src/enums/browser.dart +++ b/lib/src/enums/browser.dart @@ -1,26 +1,24 @@ part of '../../enums.dart'; enum Browser { - avantBrowser(value: 'aa'), - androidWebViewBeta(value: 'an'), - googleChrome(value: 'ch'), - googleChromeIOS(value: 'ci'), - googleChromeMobile(value: 'cm'), - chromium(value: 'cr'), - mozillaFirefox(value: 'ff'), - safari(value: 'sf'), - mobileSafari(value: 'mf'), - microsoftEdge(value: 'ps'), - microsoftEdgeIOS(value: 'oi'), - operaMini(value: 'om'), - opera(value: 'op'), - operaNext(value: 'on'); + avantBrowser(value: 'aa'), + androidWebViewBeta(value: 'an'), + googleChrome(value: 'ch'), + googleChromeIOS(value: 'ci'), + googleChromeMobile(value: 'cm'), + chromium(value: 'cr'), + mozillaFirefox(value: 'ff'), + safari(value: 'sf'), + mobileSafari(value: 'mf'), + microsoftEdge(value: 'ps'), + microsoftEdgeIOS(value: 'oi'), + operaMini(value: 'om'), + opera(value: 'op'), + operaNext(value: 'on'); - const Browser({ - required this.value - }); + const Browser({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/compression.dart b/lib/src/enums/compression.dart index 209acfb8..768930d9 100644 --- a/lib/src/enums/compression.dart +++ b/lib/src/enums/compression.dart @@ -1,15 +1,13 @@ part of '../../enums.dart'; enum Compression { - none(value: 'none'), - gzip(value: 'gzip'), - zstd(value: 'zstd'); + none(value: 'none'), + gzip(value: 'gzip'), + zstd(value: 'zstd'); - const Compression({ - required this.value - }); + const Compression({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/credit_card.dart b/lib/src/enums/credit_card.dart index 7d54fa80..3a6b256a 100644 --- a/lib/src/enums/credit_card.dart +++ b/lib/src/enums/credit_card.dart @@ -1,28 +1,26 @@ part of '../../enums.dart'; enum CreditCard { - americanExpress(value: 'amex'), - argencard(value: 'argencard'), - cabal(value: 'cabal'), - cencosud(value: 'cencosud'), - dinersClub(value: 'diners'), - discover(value: 'discover'), - elo(value: 'elo'), - hipercard(value: 'hipercard'), - jCB(value: 'jcb'), - mastercard(value: 'mastercard'), - naranja(value: 'naranja'), - tarjetaShopping(value: 'targeta-shopping'), - unionChinaPay(value: 'union-china-pay'), - visa(value: 'visa'), - mIR(value: 'mir'), - maestro(value: 'maestro'); + americanExpress(value: 'amex'), + argencard(value: 'argencard'), + cabal(value: 'cabal'), + cencosud(value: 'cencosud'), + dinersClub(value: 'diners'), + discover(value: 'discover'), + elo(value: 'elo'), + hipercard(value: 'hipercard'), + jCB(value: 'jcb'), + mastercard(value: 'mastercard'), + naranja(value: 'naranja'), + tarjetaShopping(value: 'targeta-shopping'), + unionChinaPay(value: 'union-china-pay'), + visa(value: 'visa'), + mIR(value: 'mir'), + maestro(value: 'maestro'); - const CreditCard({ - required this.value - }); + const CreditCard({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/execution_method.dart b/lib/src/enums/execution_method.dart index 7d2d7016..42954430 100644 --- a/lib/src/enums/execution_method.dart +++ b/lib/src/enums/execution_method.dart @@ -1,18 +1,16 @@ part of '../../enums.dart'; enum ExecutionMethod { - gET(value: 'GET'), - pOST(value: 'POST'), - pUT(value: 'PUT'), - pATCH(value: 'PATCH'), - dELETE(value: 'DELETE'), - oPTIONS(value: 'OPTIONS'); + gET(value: 'GET'), + pOST(value: 'POST'), + pUT(value: 'PUT'), + pATCH(value: 'PATCH'), + dELETE(value: 'DELETE'), + oPTIONS(value: 'OPTIONS'); - const ExecutionMethod({ - required this.value - }); + const ExecutionMethod({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/flag.dart b/lib/src/enums/flag.dart index 27c25cac..a44cb81d 100644 --- a/lib/src/enums/flag.dart +++ b/lib/src/enums/flag.dart @@ -1,207 +1,205 @@ part of '../../enums.dart'; enum Flag { - afghanistan(value: 'af'), - angola(value: 'ao'), - albania(value: 'al'), - andorra(value: 'ad'), - unitedArabEmirates(value: 'ae'), - argentina(value: 'ar'), - armenia(value: 'am'), - antiguaAndBarbuda(value: 'ag'), - australia(value: 'au'), - austria(value: 'at'), - azerbaijan(value: 'az'), - burundi(value: 'bi'), - belgium(value: 'be'), - benin(value: 'bj'), - burkinaFaso(value: 'bf'), - bangladesh(value: 'bd'), - bulgaria(value: 'bg'), - bahrain(value: 'bh'), - bahamas(value: 'bs'), - bosniaAndHerzegovina(value: 'ba'), - belarus(value: 'by'), - belize(value: 'bz'), - bolivia(value: 'bo'), - brazil(value: 'br'), - barbados(value: 'bb'), - bruneiDarussalam(value: 'bn'), - bhutan(value: 'bt'), - botswana(value: 'bw'), - centralAfricanRepublic(value: 'cf'), - canada(value: 'ca'), - switzerland(value: 'ch'), - chile(value: 'cl'), - china(value: 'cn'), - coteDIvoire(value: 'ci'), - cameroon(value: 'cm'), - democraticRepublicOfTheCongo(value: 'cd'), - republicOfTheCongo(value: 'cg'), - colombia(value: 'co'), - comoros(value: 'km'), - capeVerde(value: 'cv'), - costaRica(value: 'cr'), - cuba(value: 'cu'), - cyprus(value: 'cy'), - czechRepublic(value: 'cz'), - germany(value: 'de'), - djibouti(value: 'dj'), - dominica(value: 'dm'), - denmark(value: 'dk'), - dominicanRepublic(value: 'do'), - algeria(value: 'dz'), - ecuador(value: 'ec'), - egypt(value: 'eg'), - eritrea(value: 'er'), - spain(value: 'es'), - estonia(value: 'ee'), - ethiopia(value: 'et'), - finland(value: 'fi'), - fiji(value: 'fj'), - france(value: 'fr'), - micronesiaFederatedStatesOf(value: 'fm'), - gabon(value: 'ga'), - unitedKingdom(value: 'gb'), - georgia(value: 'ge'), - ghana(value: 'gh'), - guinea(value: 'gn'), - gambia(value: 'gm'), - guineaBissau(value: 'gw'), - equatorialGuinea(value: 'gq'), - greece(value: 'gr'), - grenada(value: 'gd'), - guatemala(value: 'gt'), - guyana(value: 'gy'), - honduras(value: 'hn'), - croatia(value: 'hr'), - haiti(value: 'ht'), - hungary(value: 'hu'), - indonesia(value: 'id'), - india(value: 'in'), - ireland(value: 'ie'), - iranIslamicRepublicOf(value: 'ir'), - iraq(value: 'iq'), - iceland(value: 'is'), - israel(value: 'il'), - italy(value: 'it'), - jamaica(value: 'jm'), - jordan(value: 'jo'), - japan(value: 'jp'), - kazakhstan(value: 'kz'), - kenya(value: 'ke'), - kyrgyzstan(value: 'kg'), - cambodia(value: 'kh'), - kiribati(value: 'ki'), - saintKittsAndNevis(value: 'kn'), - southKorea(value: 'kr'), - kuwait(value: 'kw'), - laoPeopleSDemocraticRepublic(value: 'la'), - lebanon(value: 'lb'), - liberia(value: 'lr'), - libya(value: 'ly'), - saintLucia(value: 'lc'), - liechtenstein(value: 'li'), - sriLanka(value: 'lk'), - lesotho(value: 'ls'), - lithuania(value: 'lt'), - luxembourg(value: 'lu'), - latvia(value: 'lv'), - morocco(value: 'ma'), - monaco(value: 'mc'), - moldova(value: 'md'), - madagascar(value: 'mg'), - maldives(value: 'mv'), - mexico(value: 'mx'), - marshallIslands(value: 'mh'), - northMacedonia(value: 'mk'), - mali(value: 'ml'), - malta(value: 'mt'), - myanmar(value: 'mm'), - montenegro(value: 'me'), - mongolia(value: 'mn'), - mozambique(value: 'mz'), - mauritania(value: 'mr'), - mauritius(value: 'mu'), - malawi(value: 'mw'), - malaysia(value: 'my'), - namibia(value: 'na'), - niger(value: 'ne'), - nigeria(value: 'ng'), - nicaragua(value: 'ni'), - netherlands(value: 'nl'), - norway(value: 'no'), - nepal(value: 'np'), - nauru(value: 'nr'), - newZealand(value: 'nz'), - oman(value: 'om'), - pakistan(value: 'pk'), - panama(value: 'pa'), - peru(value: 'pe'), - philippines(value: 'ph'), - palau(value: 'pw'), - papuaNewGuinea(value: 'pg'), - poland(value: 'pl'), - frenchPolynesia(value: 'pf'), - northKorea(value: 'kp'), - portugal(value: 'pt'), - paraguay(value: 'py'), - qatar(value: 'qa'), - romania(value: 'ro'), - russia(value: 'ru'), - rwanda(value: 'rw'), - saudiArabia(value: 'sa'), - sudan(value: 'sd'), - senegal(value: 'sn'), - singapore(value: 'sg'), - solomonIslands(value: 'sb'), - sierraLeone(value: 'sl'), - elSalvador(value: 'sv'), - sanMarino(value: 'sm'), - somalia(value: 'so'), - serbia(value: 'rs'), - southSudan(value: 'ss'), - saoTomeAndPrincipe(value: 'st'), - suriname(value: 'sr'), - slovakia(value: 'sk'), - slovenia(value: 'si'), - sweden(value: 'se'), - eswatini(value: 'sz'), - seychelles(value: 'sc'), - syria(value: 'sy'), - chad(value: 'td'), - togo(value: 'tg'), - thailand(value: 'th'), - tajikistan(value: 'tj'), - turkmenistan(value: 'tm'), - timorLeste(value: 'tl'), - tonga(value: 'to'), - trinidadAndTobago(value: 'tt'), - tunisia(value: 'tn'), - turkey(value: 'tr'), - tuvalu(value: 'tv'), - tanzania(value: 'tz'), - uganda(value: 'ug'), - ukraine(value: 'ua'), - uruguay(value: 'uy'), - unitedStates(value: 'us'), - uzbekistan(value: 'uz'), - vaticanCity(value: 'va'), - saintVincentAndTheGrenadines(value: 'vc'), - venezuela(value: 've'), - vietnam(value: 'vn'), - vanuatu(value: 'vu'), - samoa(value: 'ws'), - yemen(value: 'ye'), - southAfrica(value: 'za'), - zambia(value: 'zm'), - zimbabwe(value: 'zw'); + afghanistan(value: 'af'), + angola(value: 'ao'), + albania(value: 'al'), + andorra(value: 'ad'), + unitedArabEmirates(value: 'ae'), + argentina(value: 'ar'), + armenia(value: 'am'), + antiguaAndBarbuda(value: 'ag'), + australia(value: 'au'), + austria(value: 'at'), + azerbaijan(value: 'az'), + burundi(value: 'bi'), + belgium(value: 'be'), + benin(value: 'bj'), + burkinaFaso(value: 'bf'), + bangladesh(value: 'bd'), + bulgaria(value: 'bg'), + bahrain(value: 'bh'), + bahamas(value: 'bs'), + bosniaAndHerzegovina(value: 'ba'), + belarus(value: 'by'), + belize(value: 'bz'), + bolivia(value: 'bo'), + brazil(value: 'br'), + barbados(value: 'bb'), + bruneiDarussalam(value: 'bn'), + bhutan(value: 'bt'), + botswana(value: 'bw'), + centralAfricanRepublic(value: 'cf'), + canada(value: 'ca'), + switzerland(value: 'ch'), + chile(value: 'cl'), + china(value: 'cn'), + coteDIvoire(value: 'ci'), + cameroon(value: 'cm'), + democraticRepublicOfTheCongo(value: 'cd'), + republicOfTheCongo(value: 'cg'), + colombia(value: 'co'), + comoros(value: 'km'), + capeVerde(value: 'cv'), + costaRica(value: 'cr'), + cuba(value: 'cu'), + cyprus(value: 'cy'), + czechRepublic(value: 'cz'), + germany(value: 'de'), + djibouti(value: 'dj'), + dominica(value: 'dm'), + denmark(value: 'dk'), + dominicanRepublic(value: 'do'), + algeria(value: 'dz'), + ecuador(value: 'ec'), + egypt(value: 'eg'), + eritrea(value: 'er'), + spain(value: 'es'), + estonia(value: 'ee'), + ethiopia(value: 'et'), + finland(value: 'fi'), + fiji(value: 'fj'), + france(value: 'fr'), + micronesiaFederatedStatesOf(value: 'fm'), + gabon(value: 'ga'), + unitedKingdom(value: 'gb'), + georgia(value: 'ge'), + ghana(value: 'gh'), + guinea(value: 'gn'), + gambia(value: 'gm'), + guineaBissau(value: 'gw'), + equatorialGuinea(value: 'gq'), + greece(value: 'gr'), + grenada(value: 'gd'), + guatemala(value: 'gt'), + guyana(value: 'gy'), + honduras(value: 'hn'), + croatia(value: 'hr'), + haiti(value: 'ht'), + hungary(value: 'hu'), + indonesia(value: 'id'), + india(value: 'in'), + ireland(value: 'ie'), + iranIslamicRepublicOf(value: 'ir'), + iraq(value: 'iq'), + iceland(value: 'is'), + israel(value: 'il'), + italy(value: 'it'), + jamaica(value: 'jm'), + jordan(value: 'jo'), + japan(value: 'jp'), + kazakhstan(value: 'kz'), + kenya(value: 'ke'), + kyrgyzstan(value: 'kg'), + cambodia(value: 'kh'), + kiribati(value: 'ki'), + saintKittsAndNevis(value: 'kn'), + southKorea(value: 'kr'), + kuwait(value: 'kw'), + laoPeopleSDemocraticRepublic(value: 'la'), + lebanon(value: 'lb'), + liberia(value: 'lr'), + libya(value: 'ly'), + saintLucia(value: 'lc'), + liechtenstein(value: 'li'), + sriLanka(value: 'lk'), + lesotho(value: 'ls'), + lithuania(value: 'lt'), + luxembourg(value: 'lu'), + latvia(value: 'lv'), + morocco(value: 'ma'), + monaco(value: 'mc'), + moldova(value: 'md'), + madagascar(value: 'mg'), + maldives(value: 'mv'), + mexico(value: 'mx'), + marshallIslands(value: 'mh'), + northMacedonia(value: 'mk'), + mali(value: 'ml'), + malta(value: 'mt'), + myanmar(value: 'mm'), + montenegro(value: 'me'), + mongolia(value: 'mn'), + mozambique(value: 'mz'), + mauritania(value: 'mr'), + mauritius(value: 'mu'), + malawi(value: 'mw'), + malaysia(value: 'my'), + namibia(value: 'na'), + niger(value: 'ne'), + nigeria(value: 'ng'), + nicaragua(value: 'ni'), + netherlands(value: 'nl'), + norway(value: 'no'), + nepal(value: 'np'), + nauru(value: 'nr'), + newZealand(value: 'nz'), + oman(value: 'om'), + pakistan(value: 'pk'), + panama(value: 'pa'), + peru(value: 'pe'), + philippines(value: 'ph'), + palau(value: 'pw'), + papuaNewGuinea(value: 'pg'), + poland(value: 'pl'), + frenchPolynesia(value: 'pf'), + northKorea(value: 'kp'), + portugal(value: 'pt'), + paraguay(value: 'py'), + qatar(value: 'qa'), + romania(value: 'ro'), + russia(value: 'ru'), + rwanda(value: 'rw'), + saudiArabia(value: 'sa'), + sudan(value: 'sd'), + senegal(value: 'sn'), + singapore(value: 'sg'), + solomonIslands(value: 'sb'), + sierraLeone(value: 'sl'), + elSalvador(value: 'sv'), + sanMarino(value: 'sm'), + somalia(value: 'so'), + serbia(value: 'rs'), + southSudan(value: 'ss'), + saoTomeAndPrincipe(value: 'st'), + suriname(value: 'sr'), + slovakia(value: 'sk'), + slovenia(value: 'si'), + sweden(value: 'se'), + eswatini(value: 'sz'), + seychelles(value: 'sc'), + syria(value: 'sy'), + chad(value: 'td'), + togo(value: 'tg'), + thailand(value: 'th'), + tajikistan(value: 'tj'), + turkmenistan(value: 'tm'), + timorLeste(value: 'tl'), + tonga(value: 'to'), + trinidadAndTobago(value: 'tt'), + tunisia(value: 'tn'), + turkey(value: 'tr'), + tuvalu(value: 'tv'), + tanzania(value: 'tz'), + uganda(value: 'ug'), + ukraine(value: 'ua'), + uruguay(value: 'uy'), + unitedStates(value: 'us'), + uzbekistan(value: 'uz'), + vaticanCity(value: 'va'), + saintVincentAndTheGrenadines(value: 'vc'), + venezuela(value: 've'), + vietnam(value: 'vn'), + vanuatu(value: 'vu'), + samoa(value: 'ws'), + yemen(value: 'ye'), + southAfrica(value: 'za'), + zambia(value: 'zm'), + zimbabwe(value: 'zw'); - const Flag({ - required this.value - }); + const Flag({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/image_format.dart b/lib/src/enums/image_format.dart index cff37f49..acc07f27 100644 --- a/lib/src/enums/image_format.dart +++ b/lib/src/enums/image_format.dart @@ -1,18 +1,16 @@ part of '../../enums.dart'; enum ImageFormat { - jpg(value: 'jpg'), - jpeg(value: 'jpeg'), - gif(value: 'gif'), - png(value: 'png'), - webp(value: 'webp'), - avif(value: 'avif'); + jpg(value: 'jpg'), + jpeg(value: 'jpeg'), + gif(value: 'gif'), + png(value: 'png'), + webp(value: 'webp'), + avif(value: 'avif'); - const ImageFormat({ - required this.value - }); + const ImageFormat({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/image_gravity.dart b/lib/src/enums/image_gravity.dart index 79bc4d62..88029044 100644 --- a/lib/src/enums/image_gravity.dart +++ b/lib/src/enums/image_gravity.dart @@ -1,21 +1,19 @@ part of '../../enums.dart'; enum ImageGravity { - center(value: 'center'), - topLeft(value: 'top-left'), - top(value: 'top'), - topRight(value: 'top-right'), - left(value: 'left'), - right(value: 'right'), - bottomLeft(value: 'bottom-left'), - bottom(value: 'bottom'), - bottomRight(value: 'bottom-right'); + center(value: 'center'), + topLeft(value: 'top-left'), + top(value: 'top'), + topRight(value: 'top-right'), + left(value: 'left'), + right(value: 'right'), + bottomLeft(value: 'bottom-left'), + bottom(value: 'bottom'), + bottomRight(value: 'bottom-right'); - const ImageGravity({ - required this.value - }); + const ImageGravity({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/index_type.dart b/lib/src/enums/index_type.dart index 8d86530d..b101d35f 100644 --- a/lib/src/enums/index_type.dart +++ b/lib/src/enums/index_type.dart @@ -1,15 +1,13 @@ part of '../../enums.dart'; enum IndexType { - key(value: 'key'), - fulltext(value: 'fulltext'), - unique(value: 'unique'); + key(value: 'key'), + fulltext(value: 'fulltext'), + unique(value: 'unique'); - const IndexType({ - required this.value - }); + const IndexType({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/message_priority.dart b/lib/src/enums/message_priority.dart index 375913e8..a07e6f76 100644 --- a/lib/src/enums/message_priority.dart +++ b/lib/src/enums/message_priority.dart @@ -1,14 +1,12 @@ part of '../../enums.dart'; enum MessagePriority { - normal(value: 'normal'), - high(value: 'high'); + normal(value: 'normal'), + high(value: 'high'); - const MessagePriority({ - required this.value - }); + const MessagePriority({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/messaging_provider_type.dart b/lib/src/enums/messaging_provider_type.dart index a6859648..c69bf01e 100644 --- a/lib/src/enums/messaging_provider_type.dart +++ b/lib/src/enums/messaging_provider_type.dart @@ -1,15 +1,13 @@ part of '../../enums.dart'; enum MessagingProviderType { - email(value: 'email'), - sms(value: 'sms'), - push(value: 'push'); + email(value: 'email'), + sms(value: 'sms'), + push(value: 'push'); - const MessagingProviderType({ - required this.value - }); + const MessagingProviderType({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/name.dart b/lib/src/enums/name.dart index 638017f7..cb35c288 100644 --- a/lib/src/enums/name.dart +++ b/lib/src/enums/name.dart @@ -1,24 +1,22 @@ part of '../../enums.dart'; enum Name { - v1Database(value: 'v1-database'), - v1Deletes(value: 'v1-deletes'), - v1Audits(value: 'v1-audits'), - v1Mails(value: 'v1-mails'), - v1Functions(value: 'v1-functions'), - v1Usage(value: 'v1-usage'), - v1UsageDump(value: 'v1-usage-dump'), - v1Webhooks(value: 'v1-webhooks'), - v1Certificates(value: 'v1-certificates'), - v1Builds(value: 'v1-builds'), - v1Messaging(value: 'v1-messaging'), - v1Migrations(value: 'v1-migrations'); + v1Database(value: 'v1-database'), + v1Deletes(value: 'v1-deletes'), + v1Audits(value: 'v1-audits'), + v1Mails(value: 'v1-mails'), + v1Functions(value: 'v1-functions'), + v1Usage(value: 'v1-usage'), + v1UsageDump(value: 'v1-usage-dump'), + v1Webhooks(value: 'v1-webhooks'), + v1Certificates(value: 'v1-certificates'), + v1Builds(value: 'v1-builds'), + v1Messaging(value: 'v1-messaging'), + v1Migrations(value: 'v1-migrations'); - const Name({ - required this.value - }); + const Name({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/o_auth_provider.dart b/lib/src/enums/o_auth_provider.dart index b09e9df2..2bc1a82a 100644 --- a/lib/src/enums/o_auth_provider.dart +++ b/lib/src/enums/o_auth_provider.dart @@ -1,51 +1,49 @@ part of '../../enums.dart'; enum OAuthProvider { - amazon(value: 'amazon'), - apple(value: 'apple'), - auth0(value: 'auth0'), - authentik(value: 'authentik'), - autodesk(value: 'autodesk'), - bitbucket(value: 'bitbucket'), - bitly(value: 'bitly'), - box(value: 'box'), - dailymotion(value: 'dailymotion'), - discord(value: 'discord'), - disqus(value: 'disqus'), - dropbox(value: 'dropbox'), - etsy(value: 'etsy'), - facebook(value: 'facebook'), - github(value: 'github'), - gitlab(value: 'gitlab'), - google(value: 'google'), - linkedin(value: 'linkedin'), - microsoft(value: 'microsoft'), - notion(value: 'notion'), - oidc(value: 'oidc'), - okta(value: 'okta'), - paypal(value: 'paypal'), - paypalSandbox(value: 'paypalSandbox'), - podio(value: 'podio'), - salesforce(value: 'salesforce'), - slack(value: 'slack'), - spotify(value: 'spotify'), - stripe(value: 'stripe'), - tradeshift(value: 'tradeshift'), - tradeshiftBox(value: 'tradeshiftBox'), - twitch(value: 'twitch'), - wordpress(value: 'wordpress'), - yahoo(value: 'yahoo'), - yammer(value: 'yammer'), - yandex(value: 'yandex'), - zoho(value: 'zoho'), - zoom(value: 'zoom'), - mock(value: 'mock'); + amazon(value: 'amazon'), + apple(value: 'apple'), + auth0(value: 'auth0'), + authentik(value: 'authentik'), + autodesk(value: 'autodesk'), + bitbucket(value: 'bitbucket'), + bitly(value: 'bitly'), + box(value: 'box'), + dailymotion(value: 'dailymotion'), + discord(value: 'discord'), + disqus(value: 'disqus'), + dropbox(value: 'dropbox'), + etsy(value: 'etsy'), + facebook(value: 'facebook'), + github(value: 'github'), + gitlab(value: 'gitlab'), + google(value: 'google'), + linkedin(value: 'linkedin'), + microsoft(value: 'microsoft'), + notion(value: 'notion'), + oidc(value: 'oidc'), + okta(value: 'okta'), + paypal(value: 'paypal'), + paypalSandbox(value: 'paypalSandbox'), + podio(value: 'podio'), + salesforce(value: 'salesforce'), + slack(value: 'slack'), + spotify(value: 'spotify'), + stripe(value: 'stripe'), + tradeshift(value: 'tradeshift'), + tradeshiftBox(value: 'tradeshiftBox'), + twitch(value: 'twitch'), + wordpress(value: 'wordpress'), + yahoo(value: 'yahoo'), + yammer(value: 'yammer'), + yandex(value: 'yandex'), + zoho(value: 'zoho'), + zoom(value: 'zoom'), + mock(value: 'mock'); - const OAuthProvider({ - required this.value - }); + const OAuthProvider({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/password_hash.dart b/lib/src/enums/password_hash.dart index 510ee260..9d98c26a 100644 --- a/lib/src/enums/password_hash.dart +++ b/lib/src/enums/password_hash.dart @@ -1,23 +1,21 @@ part of '../../enums.dart'; enum PasswordHash { - sha1(value: 'sha1'), - sha224(value: 'sha224'), - sha256(value: 'sha256'), - sha384(value: 'sha384'), - sha512224(value: 'sha512/224'), - sha512256(value: 'sha512/256'), - sha512(value: 'sha512'), - sha3224(value: 'sha3-224'), - sha3256(value: 'sha3-256'), - sha3384(value: 'sha3-384'), - sha3512(value: 'sha3-512'); + sha1(value: 'sha1'), + sha224(value: 'sha224'), + sha256(value: 'sha256'), + sha384(value: 'sha384'), + sha512224(value: 'sha512/224'), + sha512256(value: 'sha512/256'), + sha512(value: 'sha512'), + sha3224(value: 'sha3-224'), + sha3256(value: 'sha3-256'), + sha3384(value: 'sha3-384'), + sha3512(value: 'sha3-512'); - const PasswordHash({ - required this.value - }); + const PasswordHash({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/relation_mutate.dart b/lib/src/enums/relation_mutate.dart index 9f4c1a85..b215a8fa 100644 --- a/lib/src/enums/relation_mutate.dart +++ b/lib/src/enums/relation_mutate.dart @@ -1,15 +1,13 @@ part of '../../enums.dart'; enum RelationMutate { - cascade(value: 'cascade'), - restrict(value: 'restrict'), - setNull(value: 'setNull'); + cascade(value: 'cascade'), + restrict(value: 'restrict'), + setNull(value: 'setNull'); - const RelationMutate({ - required this.value - }); + const RelationMutate({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/relationship_type.dart b/lib/src/enums/relationship_type.dart index 301bc61d..30efc944 100644 --- a/lib/src/enums/relationship_type.dart +++ b/lib/src/enums/relationship_type.dart @@ -1,16 +1,14 @@ part of '../../enums.dart'; enum RelationshipType { - oneToOne(value: 'oneToOne'), - manyToOne(value: 'manyToOne'), - manyToMany(value: 'manyToMany'), - oneToMany(value: 'oneToMany'); + oneToOne(value: 'oneToOne'), + manyToOne(value: 'manyToOne'), + manyToMany(value: 'manyToMany'), + oneToMany(value: 'oneToMany'); - const RelationshipType({ - required this.value - }); + const RelationshipType({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/runtime.dart b/lib/src/enums/runtime.dart index b7dbd129..a71f5a65 100644 --- a/lib/src/enums/runtime.dart +++ b/lib/src/enums/runtime.dart @@ -1,71 +1,69 @@ part of '../../enums.dart'; enum Runtime { - node145(value: 'node-14.5'), - node160(value: 'node-16.0'), - node180(value: 'node-18.0'), - node190(value: 'node-19.0'), - node200(value: 'node-20.0'), - node210(value: 'node-21.0'), - node22(value: 'node-22'), - php80(value: 'php-8.0'), - php81(value: 'php-8.1'), - php82(value: 'php-8.2'), - php83(value: 'php-8.3'), - ruby30(value: 'ruby-3.0'), - ruby31(value: 'ruby-3.1'), - ruby32(value: 'ruby-3.2'), - ruby33(value: 'ruby-3.3'), - python38(value: 'python-3.8'), - python39(value: 'python-3.9'), - python310(value: 'python-3.10'), - python311(value: 'python-3.11'), - python312(value: 'python-3.12'), - pythonMl311(value: 'python-ml-3.11'), - deno121(value: 'deno-1.21'), - deno124(value: 'deno-1.24'), - deno135(value: 'deno-1.35'), - deno140(value: 'deno-1.40'), - deno146(value: 'deno-1.46'), - deno20(value: 'deno-2.0'), - dart215(value: 'dart-2.15'), - dart216(value: 'dart-2.16'), - dart217(value: 'dart-2.17'), - dart218(value: 'dart-2.18'), - dart30(value: 'dart-3.0'), - dart31(value: 'dart-3.1'), - dart33(value: 'dart-3.3'), - dart35(value: 'dart-3.5'), - dotnet60(value: 'dotnet-6.0'), - dotnet70(value: 'dotnet-7.0'), - dotnet80(value: 'dotnet-8.0'), - java80(value: 'java-8.0'), - java110(value: 'java-11.0'), - java170(value: 'java-17.0'), - java180(value: 'java-18.0'), - java210(value: 'java-21.0'), - java22(value: 'java-22'), - swift55(value: 'swift-5.5'), - swift58(value: 'swift-5.8'), - swift59(value: 'swift-5.9'), - swift510(value: 'swift-5.10'), - kotlin16(value: 'kotlin-1.6'), - kotlin18(value: 'kotlin-1.8'), - kotlin19(value: 'kotlin-1.9'), - kotlin20(value: 'kotlin-2.0'), - cpp17(value: 'cpp-17'), - cpp20(value: 'cpp-20'), - bun10(value: 'bun-1.0'), - bun11(value: 'bun-1.1'), - go123(value: 'go-1.23'), - static1(value: 'static-1'), - flutter324(value: 'flutter-3.24'); + node145(value: 'node-14.5'), + node160(value: 'node-16.0'), + node180(value: 'node-18.0'), + node190(value: 'node-19.0'), + node200(value: 'node-20.0'), + node210(value: 'node-21.0'), + node22(value: 'node-22'), + php80(value: 'php-8.0'), + php81(value: 'php-8.1'), + php82(value: 'php-8.2'), + php83(value: 'php-8.3'), + ruby30(value: 'ruby-3.0'), + ruby31(value: 'ruby-3.1'), + ruby32(value: 'ruby-3.2'), + ruby33(value: 'ruby-3.3'), + python38(value: 'python-3.8'), + python39(value: 'python-3.9'), + python310(value: 'python-3.10'), + python311(value: 'python-3.11'), + python312(value: 'python-3.12'), + pythonMl311(value: 'python-ml-3.11'), + deno121(value: 'deno-1.21'), + deno124(value: 'deno-1.24'), + deno135(value: 'deno-1.35'), + deno140(value: 'deno-1.40'), + deno146(value: 'deno-1.46'), + deno20(value: 'deno-2.0'), + dart215(value: 'dart-2.15'), + dart216(value: 'dart-2.16'), + dart217(value: 'dart-2.17'), + dart218(value: 'dart-2.18'), + dart30(value: 'dart-3.0'), + dart31(value: 'dart-3.1'), + dart33(value: 'dart-3.3'), + dart35(value: 'dart-3.5'), + dotnet60(value: 'dotnet-6.0'), + dotnet70(value: 'dotnet-7.0'), + dotnet80(value: 'dotnet-8.0'), + java80(value: 'java-8.0'), + java110(value: 'java-11.0'), + java170(value: 'java-17.0'), + java180(value: 'java-18.0'), + java210(value: 'java-21.0'), + java22(value: 'java-22'), + swift55(value: 'swift-5.5'), + swift58(value: 'swift-5.8'), + swift59(value: 'swift-5.9'), + swift510(value: 'swift-5.10'), + kotlin16(value: 'kotlin-1.6'), + kotlin18(value: 'kotlin-1.8'), + kotlin19(value: 'kotlin-1.9'), + kotlin20(value: 'kotlin-2.0'), + cpp17(value: 'cpp-17'), + cpp20(value: 'cpp-20'), + bun10(value: 'bun-1.0'), + bun11(value: 'bun-1.1'), + go123(value: 'go-1.23'), + static1(value: 'static-1'), + flutter324(value: 'flutter-3.24'); - const Runtime({ - required this.value - }); + const Runtime({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/enums/smtp_encryption.dart b/lib/src/enums/smtp_encryption.dart index 6c880ed6..cb6cee26 100644 --- a/lib/src/enums/smtp_encryption.dart +++ b/lib/src/enums/smtp_encryption.dart @@ -1,15 +1,13 @@ part of '../../enums.dart'; enum SmtpEncryption { - none(value: 'none'), - ssl(value: 'ssl'), - tls(value: 'tls'); + none(value: 'none'), + ssl(value: 'ssl'), + tls(value: 'tls'); - const SmtpEncryption({ - required this.value - }); + const SmtpEncryption({required this.value}); - final String value; + final String value; - String toJson() => value; -} \ No newline at end of file + String toJson() => value; +} diff --git a/lib/src/exception.dart b/lib/src/exception.dart index f579bfb8..679e27b8 100644 --- a/lib/src/exception.dart +++ b/lib/src/exception.dart @@ -13,7 +13,7 @@ class AppwriteException implements Exception { /// Initializes an Appwrite Exception. AppwriteException([this.message = "", this.code, this.type, this.response]); - + /// Returns the error type, message, and code. @override String toString() { diff --git a/lib/src/models/algo_argon2.dart b/lib/src/models/algo_argon2.dart index 759f320d..4145f701 100644 --- a/lib/src/models/algo_argon2.dart +++ b/lib/src/models/algo_argon2.dart @@ -2,37 +2,40 @@ part of '../../models.dart'; /// AlgoArgon2 class AlgoArgon2 implements Model { - /// Algo type. - final String type; - /// Memory used to compute hash. - final int memoryCost; - /// Amount of time consumed to compute hash - final int timeCost; - /// Number of threads used to compute hash. - final int threads; + /// Algo type. + final String type; - AlgoArgon2({ - required this.type, - required this.memoryCost, - required this.timeCost, - required this.threads, - }); + /// Memory used to compute hash. + final int memoryCost; - factory AlgoArgon2.fromMap(Map<String, dynamic> map) { - return AlgoArgon2( - type: map['type'].toString(), - memoryCost: map['memoryCost'], - timeCost: map['timeCost'], - threads: map['threads'], - ); - } + /// Amount of time consumed to compute hash + final int timeCost; - Map<String, dynamic> toMap() { - return { - "type": type, - "memoryCost": memoryCost, - "timeCost": timeCost, - "threads": threads, - }; - } + /// Number of threads used to compute hash. + final int threads; + + AlgoArgon2({ + required this.type, + required this.memoryCost, + required this.timeCost, + required this.threads, + }); + + factory AlgoArgon2.fromMap(Map<String, dynamic> map) { + return AlgoArgon2( + type: map['type'].toString(), + memoryCost: map['memoryCost'], + timeCost: map['timeCost'], + threads: map['threads'], + ); + } + + Map<String, dynamic> toMap() { + return { + "type": type, + "memoryCost": memoryCost, + "timeCost": timeCost, + "threads": threads, + }; + } } diff --git a/lib/src/models/algo_bcrypt.dart b/lib/src/models/algo_bcrypt.dart index c9f67200..2ba0c398 100644 --- a/lib/src/models/algo_bcrypt.dart +++ b/lib/src/models/algo_bcrypt.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoBcrypt class AlgoBcrypt implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoBcrypt({ - required this.type, - }); + AlgoBcrypt({ + required this.type, + }); - factory AlgoBcrypt.fromMap(Map<String, dynamic> map) { - return AlgoBcrypt( - type: map['type'].toString(), - ); - } + factory AlgoBcrypt.fromMap(Map<String, dynamic> map) { + return AlgoBcrypt( + type: map['type'].toString(), + ); + } - Map<String, dynamic> toMap() { - return { - "type": type, - }; - } + Map<String, dynamic> toMap() { + return { + "type": type, + }; + } } diff --git a/lib/src/models/algo_md5.dart b/lib/src/models/algo_md5.dart index 2fabb416..8bdfca6f 100644 --- a/lib/src/models/algo_md5.dart +++ b/lib/src/models/algo_md5.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoMD5 class AlgoMd5 implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoMd5({ - required this.type, - }); + AlgoMd5({ + required this.type, + }); - factory AlgoMd5.fromMap(Map<String, dynamic> map) { - return AlgoMd5( - type: map['type'].toString(), - ); - } + factory AlgoMd5.fromMap(Map<String, dynamic> map) { + return AlgoMd5( + type: map['type'].toString(), + ); + } - Map<String, dynamic> toMap() { - return { - "type": type, - }; - } + Map<String, dynamic> toMap() { + return { + "type": type, + }; + } } diff --git a/lib/src/models/algo_phpass.dart b/lib/src/models/algo_phpass.dart index fdcee07a..4f5f9179 100644 --- a/lib/src/models/algo_phpass.dart +++ b/lib/src/models/algo_phpass.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoPHPass class AlgoPhpass implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoPhpass({ - required this.type, - }); + AlgoPhpass({ + required this.type, + }); - factory AlgoPhpass.fromMap(Map<String, dynamic> map) { - return AlgoPhpass( - type: map['type'].toString(), - ); - } + factory AlgoPhpass.fromMap(Map<String, dynamic> map) { + return AlgoPhpass( + type: map['type'].toString(), + ); + } - Map<String, dynamic> toMap() { - return { - "type": type, - }; - } + Map<String, dynamic> toMap() { + return { + "type": type, + }; + } } diff --git a/lib/src/models/algo_scrypt.dart b/lib/src/models/algo_scrypt.dart index 5c36373d..fec6f65a 100644 --- a/lib/src/models/algo_scrypt.dart +++ b/lib/src/models/algo_scrypt.dart @@ -2,42 +2,46 @@ part of '../../models.dart'; /// AlgoScrypt class AlgoScrypt implements Model { - /// Algo type. - final String type; - /// CPU complexity of computed hash. - final int costCpu; - /// Memory complexity of computed hash. - final int costMemory; - /// Parallelization of computed hash. - final int costParallel; - /// Length used to compute hash. - final int length; - - AlgoScrypt({ - required this.type, - required this.costCpu, - required this.costMemory, - required this.costParallel, - required this.length, - }); - - factory AlgoScrypt.fromMap(Map<String, dynamic> map) { - return AlgoScrypt( - type: map['type'].toString(), - costCpu: map['costCpu'], - costMemory: map['costMemory'], - costParallel: map['costParallel'], - length: map['length'], - ); - } - - Map<String, dynamic> toMap() { - return { - "type": type, - "costCpu": costCpu, - "costMemory": costMemory, - "costParallel": costParallel, - "length": length, - }; - } + /// Algo type. + final String type; + + /// CPU complexity of computed hash. + final int costCpu; + + /// Memory complexity of computed hash. + final int costMemory; + + /// Parallelization of computed hash. + final int costParallel; + + /// Length used to compute hash. + final int length; + + AlgoScrypt({ + required this.type, + required this.costCpu, + required this.costMemory, + required this.costParallel, + required this.length, + }); + + factory AlgoScrypt.fromMap(Map<String, dynamic> map) { + return AlgoScrypt( + type: map['type'].toString(), + costCpu: map['costCpu'], + costMemory: map['costMemory'], + costParallel: map['costParallel'], + length: map['length'], + ); + } + + Map<String, dynamic> toMap() { + return { + "type": type, + "costCpu": costCpu, + "costMemory": costMemory, + "costParallel": costParallel, + "length": length, + }; + } } diff --git a/lib/src/models/algo_scrypt_modified.dart b/lib/src/models/algo_scrypt_modified.dart index b10b14a6..0e80700f 100644 --- a/lib/src/models/algo_scrypt_modified.dart +++ b/lib/src/models/algo_scrypt_modified.dart @@ -2,37 +2,40 @@ part of '../../models.dart'; /// AlgoScryptModified class AlgoScryptModified implements Model { - /// Algo type. - final String type; - /// Salt used to compute hash. - final String salt; - /// Separator used to compute hash. - final String saltSeparator; - /// Key used to compute hash. - final String signerKey; + /// Algo type. + final String type; - AlgoScryptModified({ - required this.type, - required this.salt, - required this.saltSeparator, - required this.signerKey, - }); + /// Salt used to compute hash. + final String salt; - factory AlgoScryptModified.fromMap(Map<String, dynamic> map) { - return AlgoScryptModified( - type: map['type'].toString(), - salt: map['salt'].toString(), - saltSeparator: map['saltSeparator'].toString(), - signerKey: map['signerKey'].toString(), - ); - } + /// Separator used to compute hash. + final String saltSeparator; - Map<String, dynamic> toMap() { - return { - "type": type, - "salt": salt, - "saltSeparator": saltSeparator, - "signerKey": signerKey, - }; - } + /// Key used to compute hash. + final String signerKey; + + AlgoScryptModified({ + required this.type, + required this.salt, + required this.saltSeparator, + required this.signerKey, + }); + + factory AlgoScryptModified.fromMap(Map<String, dynamic> map) { + return AlgoScryptModified( + type: map['type'].toString(), + salt: map['salt'].toString(), + saltSeparator: map['saltSeparator'].toString(), + signerKey: map['signerKey'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "type": type, + "salt": salt, + "saltSeparator": saltSeparator, + "signerKey": signerKey, + }; + } } diff --git a/lib/src/models/algo_sha.dart b/lib/src/models/algo_sha.dart index 5f3e1654..47068be0 100644 --- a/lib/src/models/algo_sha.dart +++ b/lib/src/models/algo_sha.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoSHA class AlgoSha implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoSha({ - required this.type, - }); + AlgoSha({ + required this.type, + }); - factory AlgoSha.fromMap(Map<String, dynamic> map) { - return AlgoSha( - type: map['type'].toString(), - ); - } + factory AlgoSha.fromMap(Map<String, dynamic> map) { + return AlgoSha( + type: map['type'].toString(), + ); + } - Map<String, dynamic> toMap() { - return { - "type": type, - }; - } + Map<String, dynamic> toMap() { + return { + "type": type, + }; + } } diff --git a/lib/src/models/attribute_boolean.dart b/lib/src/models/attribute_boolean.dart index 453f3332..0ca54691 100644 --- a/lib/src/models/attribute_boolean.dart +++ b/lib/src/models/attribute_boolean.dart @@ -2,62 +2,70 @@ part of '../../models.dart'; /// AttributeBoolean class AttributeBoolean implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final bool? xdefault; - - AttributeBoolean({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - this.xdefault, - }); - - factory AttributeBoolean.fromMap(Map<String, dynamic> map) { - return AttributeBoolean( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - xdefault: map['default'], - ); - } - - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "default": xdefault, - }; - } + /// Attribute Key. + final String key; + + /// Attribute type. + final String type; + + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final bool? xdefault; + + AttributeBoolean({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + this.xdefault, + }); + + factory AttributeBoolean.fromMap(Map<String, dynamic> map) { + return AttributeBoolean( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + xdefault: map['default'], + ); + } + + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_datetime.dart b/lib/src/models/attribute_datetime.dart index bf35fcda..1df01f19 100644 --- a/lib/src/models/attribute_datetime.dart +++ b/lib/src/models/attribute_datetime.dart @@ -2,67 +2,76 @@ part of '../../models.dart'; /// AttributeDatetime class AttributeDatetime implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - /// ISO 8601 format. - final String format; - /// Default value for attribute when not provided. Only null is optional - final String? xdefault; + /// Attribute Key. + final String key; - AttributeDatetime({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - required this.format, - this.xdefault, - }); + /// Attribute type. + final String type; - factory AttributeDatetime.fromMap(Map<String, dynamic> map) { - return AttributeDatetime( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "format": format, - "default": xdefault, - }; - } + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + + /// ISO 8601 format. + final String format; + + /// Default value for attribute when not provided. Only null is optional + final String? xdefault; + + AttributeDatetime({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + required this.format, + this.xdefault, + }); + + factory AttributeDatetime.fromMap(Map<String, dynamic> map) { + return AttributeDatetime( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_email.dart b/lib/src/models/attribute_email.dart index 041ca68f..21f8e9a3 100644 --- a/lib/src/models/attribute_email.dart +++ b/lib/src/models/attribute_email.dart @@ -2,67 +2,76 @@ part of '../../models.dart'; /// AttributeEmail class AttributeEmail implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - /// String format. - final String format; - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; + /// Attribute Key. + final String key; - AttributeEmail({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - required this.format, - this.xdefault, - }); + /// Attribute type. + final String type; - factory AttributeEmail.fromMap(Map<String, dynamic> map) { - return AttributeEmail( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "format": format, - "default": xdefault, - }; - } + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + + /// String format. + final String format; + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeEmail({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + required this.format, + this.xdefault, + }); + + factory AttributeEmail.fromMap(Map<String, dynamic> map) { + return AttributeEmail( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_enum.dart b/lib/src/models/attribute_enum.dart index 3aeff75a..746f9864 100644 --- a/lib/src/models/attribute_enum.dart +++ b/lib/src/models/attribute_enum.dart @@ -2,72 +2,82 @@ part of '../../models.dart'; /// AttributeEnum class AttributeEnum implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - /// Array of elements in enumerated type. - final List<String> elements; - /// String format. - final String format; - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; + /// Attribute Key. + final String key; - AttributeEnum({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - required this.elements, - required this.format, - this.xdefault, - }); + /// Attribute type. + final String type; - factory AttributeEnum.fromMap(Map<String, dynamic> map) { - return AttributeEnum( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - elements: map['elements'] ?? [], - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "elements": elements, - "format": format, - "default": xdefault, - }; - } + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + + /// Array of elements in enumerated type. + final List<String> elements; + + /// String format. + final String format; + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeEnum({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + required this.elements, + required this.format, + this.xdefault, + }); + + factory AttributeEnum.fromMap(Map<String, dynamic> map) { + return AttributeEnum( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + elements: map['elements'] ?? [], + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "elements": elements, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_float.dart b/lib/src/models/attribute_float.dart index f109bf3c..c6eecadd 100644 --- a/lib/src/models/attribute_float.dart +++ b/lib/src/models/attribute_float.dart @@ -2,72 +2,82 @@ part of '../../models.dart'; /// AttributeFloat class AttributeFloat implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - /// Minimum value to enforce for new documents. - final double? min; - /// Maximum value to enforce for new documents. - final double? max; - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final double? xdefault; + /// Attribute Key. + final String key; - AttributeFloat({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - this.min, - this.max, - this.xdefault, - }); + /// Attribute type. + final String type; - factory AttributeFloat.fromMap(Map<String, dynamic> map) { - return AttributeFloat( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - min: map['min']?.toDouble(), - max: map['max']?.toDouble(), - xdefault: map['default']?.toDouble(), - ); - } + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "min": min, - "max": max, - "default": xdefault, - }; - } + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + + /// Minimum value to enforce for new documents. + final double? min; + + /// Maximum value to enforce for new documents. + final double? max; + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final double? xdefault; + + AttributeFloat({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + this.min, + this.max, + this.xdefault, + }); + + factory AttributeFloat.fromMap(Map<String, dynamic> map) { + return AttributeFloat( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + min: map['min']?.toDouble(), + max: map['max']?.toDouble(), + xdefault: map['default']?.toDouble(), + ); + } + + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "min": min, + "max": max, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_integer.dart b/lib/src/models/attribute_integer.dart index add418c5..1ef48332 100644 --- a/lib/src/models/attribute_integer.dart +++ b/lib/src/models/attribute_integer.dart @@ -2,72 +2,82 @@ part of '../../models.dart'; /// AttributeInteger class AttributeInteger implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - /// Minimum value to enforce for new documents. - final int? min; - /// Maximum value to enforce for new documents. - final int? max; - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final int? xdefault; + /// Attribute Key. + final String key; - AttributeInteger({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - this.min, - this.max, - this.xdefault, - }); + /// Attribute type. + final String type; - factory AttributeInteger.fromMap(Map<String, dynamic> map) { - return AttributeInteger( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - min: map['min'], - max: map['max'], - xdefault: map['default'], - ); - } + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "min": min, - "max": max, - "default": xdefault, - }; - } + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + + /// Minimum value to enforce for new documents. + final int? min; + + /// Maximum value to enforce for new documents. + final int? max; + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final int? xdefault; + + AttributeInteger({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + this.min, + this.max, + this.xdefault, + }); + + factory AttributeInteger.fromMap(Map<String, dynamic> map) { + return AttributeInteger( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + min: map['min'], + max: map['max'], + xdefault: map['default'], + ); + } + + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "min": min, + "max": max, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_ip.dart b/lib/src/models/attribute_ip.dart index cc2a0499..8c8fcb73 100644 --- a/lib/src/models/attribute_ip.dart +++ b/lib/src/models/attribute_ip.dart @@ -2,67 +2,76 @@ part of '../../models.dart'; /// AttributeIP class AttributeIp implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - /// String format. - final String format; - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; + /// Attribute Key. + final String key; - AttributeIp({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - required this.format, - this.xdefault, - }); + /// Attribute type. + final String type; - factory AttributeIp.fromMap(Map<String, dynamic> map) { - return AttributeIp( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "format": format, - "default": xdefault, - }; - } + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + + /// String format. + final String format; + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeIp({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + required this.format, + this.xdefault, + }); + + factory AttributeIp.fromMap(Map<String, dynamic> map) { + return AttributeIp( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_list.dart b/lib/src/models/attribute_list.dart index b4a75722..4d9846c1 100644 --- a/lib/src/models/attribute_list.dart +++ b/lib/src/models/attribute_list.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Attributes List class AttributeList implements Model { - /// Total number of attributes in the given collection. - final int total; - /// List of attributes. - final List attributes; + /// Total number of attributes in the given collection. + final int total; - AttributeList({ - required this.total, - required this.attributes, - }); + /// List of attributes. + final List attributes; - factory AttributeList.fromMap(Map<String, dynamic> map) { - return AttributeList( - total: map['total'], - attributes: map['attributes'] ?? [], - ); - } + AttributeList({ + required this.total, + required this.attributes, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "attributes": attributes, - }; - } + factory AttributeList.fromMap(Map<String, dynamic> map) { + return AttributeList( + total: map['total'], + attributes: map['attributes'] ?? [], + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "attributes": attributes, + }; + } } diff --git a/lib/src/models/attribute_relationship.dart b/lib/src/models/attribute_relationship.dart index 4b129c6e..903c6290 100644 --- a/lib/src/models/attribute_relationship.dart +++ b/lib/src/models/attribute_relationship.dart @@ -2,87 +2,100 @@ part of '../../models.dart'; /// AttributeRelationship class AttributeRelationship implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - /// The ID of the related collection. - final String relatedCollection; - /// The type of the relationship. - final String relationType; - /// Is the relationship two-way? - final bool twoWay; - /// The key of the two-way relationship. - final String twoWayKey; - /// How deleting the parent document will propagate to child documents. - final String onDelete; - /// Whether this is the parent or child side of the relationship - final String side; - - AttributeRelationship({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - required this.relatedCollection, - required this.relationType, - required this.twoWay, - required this.twoWayKey, - required this.onDelete, - required this.side, - }); - - factory AttributeRelationship.fromMap(Map<String, dynamic> map) { - return AttributeRelationship( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - relatedCollection: map['relatedCollection'].toString(), - relationType: map['relationType'].toString(), - twoWay: map['twoWay'], - twoWayKey: map['twoWayKey'].toString(), - onDelete: map['onDelete'].toString(), - side: map['side'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "relatedCollection": relatedCollection, - "relationType": relationType, - "twoWay": twoWay, - "twoWayKey": twoWayKey, - "onDelete": onDelete, - "side": side, - }; - } + /// Attribute Key. + final String key; + + /// Attribute type. + final String type; + + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + + /// The ID of the related collection. + final String relatedCollection; + + /// The type of the relationship. + final String relationType; + + /// Is the relationship two-way? + final bool twoWay; + + /// The key of the two-way relationship. + final String twoWayKey; + + /// How deleting the parent document will propagate to child documents. + final String onDelete; + + /// Whether this is the parent or child side of the relationship + final String side; + + AttributeRelationship({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + required this.relatedCollection, + required this.relationType, + required this.twoWay, + required this.twoWayKey, + required this.onDelete, + required this.side, + }); + + factory AttributeRelationship.fromMap(Map<String, dynamic> map) { + return AttributeRelationship( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + relatedCollection: map['relatedCollection'].toString(), + relationType: map['relationType'].toString(), + twoWay: map['twoWay'], + twoWayKey: map['twoWayKey'].toString(), + onDelete: map['onDelete'].toString(), + side: map['side'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "relatedCollection": relatedCollection, + "relationType": relationType, + "twoWay": twoWay, + "twoWayKey": twoWayKey, + "onDelete": onDelete, + "side": side, + }; + } } diff --git a/lib/src/models/attribute_string.dart b/lib/src/models/attribute_string.dart index 247708f0..d32b6829 100644 --- a/lib/src/models/attribute_string.dart +++ b/lib/src/models/attribute_string.dart @@ -2,67 +2,76 @@ part of '../../models.dart'; /// AttributeString class AttributeString implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - /// Attribute size. - final int size; - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; + /// Attribute Key. + final String key; - AttributeString({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - required this.size, - this.xdefault, - }); + /// Attribute type. + final String type; - factory AttributeString.fromMap(Map<String, dynamic> map) { - return AttributeString( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - size: map['size'], - xdefault: map['default']?.toString(), - ); - } + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "size": size, - "default": xdefault, - }; - } + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + + /// Attribute size. + final int size; + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeString({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + required this.size, + this.xdefault, + }); + + factory AttributeString.fromMap(Map<String, dynamic> map) { + return AttributeString( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + size: map['size'], + xdefault: map['default']?.toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "size": size, + "default": xdefault, + }; + } } diff --git a/lib/src/models/attribute_url.dart b/lib/src/models/attribute_url.dart index aaac9202..f0bc295e 100644 --- a/lib/src/models/attribute_url.dart +++ b/lib/src/models/attribute_url.dart @@ -2,67 +2,76 @@ part of '../../models.dart'; /// AttributeURL class AttributeUrl implements Model { - /// Attribute Key. - final String key; - /// Attribute type. - final String type; - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - /// Is attribute required? - final bool xrequired; - /// Is attribute an array? - final bool? array; - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - /// String format. - final String format; - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; + /// Attribute Key. + final String key; - AttributeUrl({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - required this.format, - this.xdefault, - }); + /// Attribute type. + final String type; - factory AttributeUrl.fromMap(Map<String, dynamic> map) { - return AttributeUrl( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "format": format, - "default": xdefault, - }; - } + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + + /// Is attribute required? + final bool xrequired; + + /// Is attribute an array? + final bool? array; + + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + + /// String format. + final String format; + + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; + + AttributeUrl({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + required this.format, + this.xdefault, + }); + + factory AttributeUrl.fromMap(Map<String, dynamic> map) { + return AttributeUrl( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "format": format, + "default": xdefault, + }; + } } diff --git a/lib/src/models/bucket.dart b/lib/src/models/bucket.dart index 47279918..e2aa51fe 100644 --- a/lib/src/models/bucket.dart +++ b/lib/src/models/bucket.dart @@ -2,77 +2,88 @@ part of '../../models.dart'; /// Bucket class Bucket implements Model { - /// Bucket ID. - final String $id; - /// Bucket creation time in ISO 8601 format. - final String $createdAt; - /// Bucket update date in ISO 8601 format. - final String $updatedAt; - /// Bucket permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List<String> $permissions; - /// Whether file-level security is enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). - final bool fileSecurity; - /// Bucket name. - final String name; - /// Bucket enabled. - final bool enabled; - /// Maximum file size supported. - final int maximumFileSize; - /// Allowed file extensions. - final List<String> allowedFileExtensions; - /// Compression algorithm choosen for compression. Will be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd). - final String compression; - /// Bucket is encrypted. - final bool encryption; - /// Virus scanning is enabled. - final bool antivirus; + /// Bucket ID. + final String $id; - Bucket({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.fileSecurity, - required this.name, - required this.enabled, - required this.maximumFileSize, - required this.allowedFileExtensions, - required this.compression, - required this.encryption, - required this.antivirus, - }); + /// Bucket creation time in ISO 8601 format. + final String $createdAt; - factory Bucket.fromMap(Map<String, dynamic> map) { - return Bucket( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - fileSecurity: map['fileSecurity'], - name: map['name'].toString(), - enabled: map['enabled'], - maximumFileSize: map['maximumFileSize'], - allowedFileExtensions: map['allowedFileExtensions'] ?? [], - compression: map['compression'].toString(), - encryption: map['encryption'], - antivirus: map['antivirus'], - ); - } + /// Bucket update date in ISO 8601 format. + final String $updatedAt; - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "fileSecurity": fileSecurity, - "name": name, - "enabled": enabled, - "maximumFileSize": maximumFileSize, - "allowedFileExtensions": allowedFileExtensions, - "compression": compression, - "encryption": encryption, - "antivirus": antivirus, - }; - } + /// Bucket permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List<String> $permissions; + + /// Whether file-level security is enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). + final bool fileSecurity; + + /// Bucket name. + final String name; + + /// Bucket enabled. + final bool enabled; + + /// Maximum file size supported. + final int maximumFileSize; + + /// Allowed file extensions. + final List<String> allowedFileExtensions; + + /// Compression algorithm choosen for compression. Will be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd). + final String compression; + + /// Bucket is encrypted. + final bool encryption; + + /// Virus scanning is enabled. + final bool antivirus; + + Bucket({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.fileSecurity, + required this.name, + required this.enabled, + required this.maximumFileSize, + required this.allowedFileExtensions, + required this.compression, + required this.encryption, + required this.antivirus, + }); + + factory Bucket.fromMap(Map<String, dynamic> map) { + return Bucket( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + fileSecurity: map['fileSecurity'], + name: map['name'].toString(), + enabled: map['enabled'], + maximumFileSize: map['maximumFileSize'], + allowedFileExtensions: map['allowedFileExtensions'] ?? [], + compression: map['compression'].toString(), + encryption: map['encryption'], + antivirus: map['antivirus'], + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "fileSecurity": fileSecurity, + "name": name, + "enabled": enabled, + "maximumFileSize": maximumFileSize, + "allowedFileExtensions": allowedFileExtensions, + "compression": compression, + "encryption": encryption, + "antivirus": antivirus, + }; + } } diff --git a/lib/src/models/bucket_list.dart b/lib/src/models/bucket_list.dart index 3b24973f..849aea4a 100644 --- a/lib/src/models/bucket_list.dart +++ b/lib/src/models/bucket_list.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Buckets List class BucketList implements Model { - /// Total number of buckets documents that matched your query. - final int total; - /// List of buckets. - final List<Bucket> buckets; + /// Total number of buckets documents that matched your query. + final int total; - BucketList({ - required this.total, - required this.buckets, - }); + /// List of buckets. + final List<Bucket> buckets; - factory BucketList.fromMap(Map<String, dynamic> map) { - return BucketList( - total: map['total'], - buckets: List<Bucket>.from(map['buckets'].map((p) => Bucket.fromMap(p))), - ); - } + BucketList({ + required this.total, + required this.buckets, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "buckets": buckets.map((p) => p.toMap()).toList(), - }; - } + factory BucketList.fromMap(Map<String, dynamic> map) { + return BucketList( + total: map['total'], + buckets: List<Bucket>.from(map['buckets'].map((p) => Bucket.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "buckets": buckets.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/build.dart b/lib/src/models/build.dart index 64eb21ad..ea4a3137 100644 --- a/lib/src/models/build.dart +++ b/lib/src/models/build.dart @@ -2,62 +2,70 @@ part of '../../models.dart'; /// Build class Build implements Model { - /// Build ID. - final String $id; - /// The deployment that created this build. - final String deploymentId; - /// The build status. There are a few different types and each one means something different. \nFailed - The deployment build has failed. More details can usually be found in buildStderr\nReady - The deployment build was successful and the deployment is ready to be deployed\nProcessing - The deployment is currently waiting to have a build triggered\nBuilding - The deployment is currently being built - final String status; - /// The stdout of the build. - final String stdout; - /// The stderr of the build. - final String stderr; - /// The deployment creation date in ISO 8601 format. - final String startTime; - /// The time the build was finished in ISO 8601 format. - final String endTime; - /// The build duration in seconds. - final int duration; - /// The code size in bytes. - final int size; - - Build({ - required this.$id, - required this.deploymentId, - required this.status, - required this.stdout, - required this.stderr, - required this.startTime, - required this.endTime, - required this.duration, - required this.size, - }); - - factory Build.fromMap(Map<String, dynamic> map) { - return Build( - $id: map['\$id'].toString(), - deploymentId: map['deploymentId'].toString(), - status: map['status'].toString(), - stdout: map['stdout'].toString(), - stderr: map['stderr'].toString(), - startTime: map['startTime'].toString(), - endTime: map['endTime'].toString(), - duration: map['duration'], - size: map['size'], - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "deploymentId": deploymentId, - "status": status, - "stdout": stdout, - "stderr": stderr, - "startTime": startTime, - "endTime": endTime, - "duration": duration, - "size": size, - }; - } + /// Build ID. + final String $id; + + /// The deployment that created this build. + final String deploymentId; + + /// The build status. There are a few different types and each one means something different. \nFailed - The deployment build has failed. More details can usually be found in buildStderr\nReady - The deployment build was successful and the deployment is ready to be deployed\nProcessing - The deployment is currently waiting to have a build triggered\nBuilding - The deployment is currently being built + final String status; + + /// The stdout of the build. + final String stdout; + + /// The stderr of the build. + final String stderr; + + /// The deployment creation date in ISO 8601 format. + final String startTime; + + /// The time the build was finished in ISO 8601 format. + final String endTime; + + /// The build duration in seconds. + final int duration; + + /// The code size in bytes. + final int size; + + Build({ + required this.$id, + required this.deploymentId, + required this.status, + required this.stdout, + required this.stderr, + required this.startTime, + required this.endTime, + required this.duration, + required this.size, + }); + + factory Build.fromMap(Map<String, dynamic> map) { + return Build( + $id: map['\$id'].toString(), + deploymentId: map['deploymentId'].toString(), + status: map['status'].toString(), + stdout: map['stdout'].toString(), + stderr: map['stderr'].toString(), + startTime: map['startTime'].toString(), + endTime: map['endTime'].toString(), + duration: map['duration'], + size: map['size'], + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "deploymentId": deploymentId, + "status": status, + "stdout": stdout, + "stderr": stderr, + "startTime": startTime, + "endTime": endTime, + "duration": duration, + "size": size, + }; + } } diff --git a/lib/src/models/collection.dart b/lib/src/models/collection.dart index 7cd47f7d..ef572743 100644 --- a/lib/src/models/collection.dart +++ b/lib/src/models/collection.dart @@ -2,67 +2,76 @@ part of '../../models.dart'; /// Collection class Collection implements Model { - /// Collection ID. - final String $id; - /// Collection creation date in ISO 8601 format. - final String $createdAt; - /// Collection update date in ISO 8601 format. - final String $updatedAt; - /// Collection permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List<String> $permissions; - /// Database ID. - final String databaseId; - /// Collection name. - final String name; - /// Collection enabled. Can be 'enabled' or 'disabled'. When disabled, the collection is inaccessible to users, but remains accessible to Server SDKs using API keys. - final bool enabled; - /// Whether document-level permissions are enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). - final bool documentSecurity; - /// Collection attributes. - final List attributes; - /// Collection indexes. - final List<Index> indexes; + /// Collection ID. + final String $id; - Collection({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.databaseId, - required this.name, - required this.enabled, - required this.documentSecurity, - required this.attributes, - required this.indexes, - }); + /// Collection creation date in ISO 8601 format. + final String $createdAt; - factory Collection.fromMap(Map<String, dynamic> map) { - return Collection( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - databaseId: map['databaseId'].toString(), - name: map['name'].toString(), - enabled: map['enabled'], - documentSecurity: map['documentSecurity'], - attributes: map['attributes'] ?? [], - indexes: List<Index>.from(map['indexes'].map((p) => Index.fromMap(p))), - ); - } + /// Collection update date in ISO 8601 format. + final String $updatedAt; - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "databaseId": databaseId, - "name": name, - "enabled": enabled, - "documentSecurity": documentSecurity, - "attributes": attributes, - "indexes": indexes.map((p) => p.toMap()).toList(), - }; - } + /// Collection permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List<String> $permissions; + + /// Database ID. + final String databaseId; + + /// Collection name. + final String name; + + /// Collection enabled. Can be 'enabled' or 'disabled'. When disabled, the collection is inaccessible to users, but remains accessible to Server SDKs using API keys. + final bool enabled; + + /// Whether document-level permissions are enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). + final bool documentSecurity; + + /// Collection attributes. + final List attributes; + + /// Collection indexes. + final List<Index> indexes; + + Collection({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.databaseId, + required this.name, + required this.enabled, + required this.documentSecurity, + required this.attributes, + required this.indexes, + }); + + factory Collection.fromMap(Map<String, dynamic> map) { + return Collection( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + databaseId: map['databaseId'].toString(), + name: map['name'].toString(), + enabled: map['enabled'], + documentSecurity: map['documentSecurity'], + attributes: map['attributes'] ?? [], + indexes: List<Index>.from(map['indexes'].map((p) => Index.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "databaseId": databaseId, + "name": name, + "enabled": enabled, + "documentSecurity": documentSecurity, + "attributes": attributes, + "indexes": indexes.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/collection_list.dart b/lib/src/models/collection_list.dart index a354146f..3f50e4b6 100644 --- a/lib/src/models/collection_list.dart +++ b/lib/src/models/collection_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Collections List class CollectionList implements Model { - /// Total number of collections documents that matched your query. - final int total; - /// List of collections. - final List<Collection> collections; + /// Total number of collections documents that matched your query. + final int total; - CollectionList({ - required this.total, - required this.collections, - }); + /// List of collections. + final List<Collection> collections; - factory CollectionList.fromMap(Map<String, dynamic> map) { - return CollectionList( - total: map['total'], - collections: List<Collection>.from(map['collections'].map((p) => Collection.fromMap(p))), - ); - } + CollectionList({ + required this.total, + required this.collections, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "collections": collections.map((p) => p.toMap()).toList(), - }; - } + factory CollectionList.fromMap(Map<String, dynamic> map) { + return CollectionList( + total: map['total'], + collections: List<Collection>.from( + map['collections'].map((p) => Collection.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "collections": collections.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/continent.dart b/lib/src/models/continent.dart index e1772f0d..990b1064 100644 --- a/lib/src/models/continent.dart +++ b/lib/src/models/continent.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Continent class Continent implements Model { - /// Continent name. - final String name; - /// Continent two letter code. - final String code; + /// Continent name. + final String name; - Continent({ - required this.name, - required this.code, - }); + /// Continent two letter code. + final String code; - factory Continent.fromMap(Map<String, dynamic> map) { - return Continent( - name: map['name'].toString(), - code: map['code'].toString(), - ); - } + Continent({ + required this.name, + required this.code, + }); - Map<String, dynamic> toMap() { - return { - "name": name, - "code": code, - }; - } + factory Continent.fromMap(Map<String, dynamic> map) { + return Continent( + name: map['name'].toString(), + code: map['code'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "name": name, + "code": code, + }; + } } diff --git a/lib/src/models/continent_list.dart b/lib/src/models/continent_list.dart index d0830aad..fb4ee6f6 100644 --- a/lib/src/models/continent_list.dart +++ b/lib/src/models/continent_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Continents List class ContinentList implements Model { - /// Total number of continents documents that matched your query. - final int total; - /// List of continents. - final List<Continent> continents; + /// Total number of continents documents that matched your query. + final int total; - ContinentList({ - required this.total, - required this.continents, - }); + /// List of continents. + final List<Continent> continents; - factory ContinentList.fromMap(Map<String, dynamic> map) { - return ContinentList( - total: map['total'], - continents: List<Continent>.from(map['continents'].map((p) => Continent.fromMap(p))), - ); - } + ContinentList({ + required this.total, + required this.continents, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "continents": continents.map((p) => p.toMap()).toList(), - }; - } + factory ContinentList.fromMap(Map<String, dynamic> map) { + return ContinentList( + total: map['total'], + continents: List<Continent>.from( + map['continents'].map((p) => Continent.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "continents": continents.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/country.dart b/lib/src/models/country.dart index b8757434..d11c55db 100644 --- a/lib/src/models/country.dart +++ b/lib/src/models/country.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Country class Country implements Model { - /// Country name. - final String name; - /// Country two-character ISO 3166-1 alpha code. - final String code; + /// Country name. + final String name; - Country({ - required this.name, - required this.code, - }); + /// Country two-character ISO 3166-1 alpha code. + final String code; - factory Country.fromMap(Map<String, dynamic> map) { - return Country( - name: map['name'].toString(), - code: map['code'].toString(), - ); - } + Country({ + required this.name, + required this.code, + }); - Map<String, dynamic> toMap() { - return { - "name": name, - "code": code, - }; - } + factory Country.fromMap(Map<String, dynamic> map) { + return Country( + name: map['name'].toString(), + code: map['code'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "name": name, + "code": code, + }; + } } diff --git a/lib/src/models/country_list.dart b/lib/src/models/country_list.dart index 7fa08533..a62f926d 100644 --- a/lib/src/models/country_list.dart +++ b/lib/src/models/country_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Countries List class CountryList implements Model { - /// Total number of countries documents that matched your query. - final int total; - /// List of countries. - final List<Country> countries; + /// Total number of countries documents that matched your query. + final int total; - CountryList({ - required this.total, - required this.countries, - }); + /// List of countries. + final List<Country> countries; - factory CountryList.fromMap(Map<String, dynamic> map) { - return CountryList( - total: map['total'], - countries: List<Country>.from(map['countries'].map((p) => Country.fromMap(p))), - ); - } + CountryList({ + required this.total, + required this.countries, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "countries": countries.map((p) => p.toMap()).toList(), - }; - } + factory CountryList.fromMap(Map<String, dynamic> map) { + return CountryList( + total: map['total'], + countries: + List<Country>.from(map['countries'].map((p) => Country.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "countries": countries.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/currency.dart b/lib/src/models/currency.dart index 11aba951..27eef0c1 100644 --- a/lib/src/models/currency.dart +++ b/lib/src/models/currency.dart @@ -2,52 +2,58 @@ part of '../../models.dart'; /// Currency class Currency implements Model { - /// Currency symbol. - final String symbol; - /// Currency name. - final String name; - /// Currency native symbol. - final String symbolNative; - /// Number of decimal digits. - final int decimalDigits; - /// Currency digit rounding. - final double rounding; - /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format. - final String code; - /// Currency plural name - final String namePlural; - - Currency({ - required this.symbol, - required this.name, - required this.symbolNative, - required this.decimalDigits, - required this.rounding, - required this.code, - required this.namePlural, - }); - - factory Currency.fromMap(Map<String, dynamic> map) { - return Currency( - symbol: map['symbol'].toString(), - name: map['name'].toString(), - symbolNative: map['symbolNative'].toString(), - decimalDigits: map['decimalDigits'], - rounding: map['rounding'].toDouble(), - code: map['code'].toString(), - namePlural: map['namePlural'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "symbol": symbol, - "name": name, - "symbolNative": symbolNative, - "decimalDigits": decimalDigits, - "rounding": rounding, - "code": code, - "namePlural": namePlural, - }; - } + /// Currency symbol. + final String symbol; + + /// Currency name. + final String name; + + /// Currency native symbol. + final String symbolNative; + + /// Number of decimal digits. + final int decimalDigits; + + /// Currency digit rounding. + final double rounding; + + /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format. + final String code; + + /// Currency plural name + final String namePlural; + + Currency({ + required this.symbol, + required this.name, + required this.symbolNative, + required this.decimalDigits, + required this.rounding, + required this.code, + required this.namePlural, + }); + + factory Currency.fromMap(Map<String, dynamic> map) { + return Currency( + symbol: map['symbol'].toString(), + name: map['name'].toString(), + symbolNative: map['symbolNative'].toString(), + decimalDigits: map['decimalDigits'], + rounding: map['rounding'].toDouble(), + code: map['code'].toString(), + namePlural: map['namePlural'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "symbol": symbol, + "name": name, + "symbolNative": symbolNative, + "decimalDigits": decimalDigits, + "rounding": rounding, + "code": code, + "namePlural": namePlural, + }; + } } diff --git a/lib/src/models/currency_list.dart b/lib/src/models/currency_list.dart index cf925bc5..e912ca0a 100644 --- a/lib/src/models/currency_list.dart +++ b/lib/src/models/currency_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Currencies List class CurrencyList implements Model { - /// Total number of currencies documents that matched your query. - final int total; - /// List of currencies. - final List<Currency> currencies; + /// Total number of currencies documents that matched your query. + final int total; - CurrencyList({ - required this.total, - required this.currencies, - }); + /// List of currencies. + final List<Currency> currencies; - factory CurrencyList.fromMap(Map<String, dynamic> map) { - return CurrencyList( - total: map['total'], - currencies: List<Currency>.from(map['currencies'].map((p) => Currency.fromMap(p))), - ); - } + CurrencyList({ + required this.total, + required this.currencies, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "currencies": currencies.map((p) => p.toMap()).toList(), - }; - } + factory CurrencyList.fromMap(Map<String, dynamic> map) { + return CurrencyList( + total: map['total'], + currencies: List<Currency>.from( + map['currencies'].map((p) => Currency.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "currencies": currencies.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/database.dart b/lib/src/models/database.dart index 8eb9253b..298a46a3 100644 --- a/lib/src/models/database.dart +++ b/lib/src/models/database.dart @@ -2,42 +2,46 @@ part of '../../models.dart'; /// Database class Database implements Model { - /// Database ID. - final String $id; - /// Database name. - final String name; - /// Database creation date in ISO 8601 format. - final String $createdAt; - /// Database update date in ISO 8601 format. - final String $updatedAt; - /// If database is enabled. Can be 'enabled' or 'disabled'. When disabled, the database is inaccessible to users, but remains accessible to Server SDKs using API keys. - final bool enabled; - - Database({ - required this.$id, - required this.name, - required this.$createdAt, - required this.$updatedAt, - required this.enabled, - }); - - factory Database.fromMap(Map<String, dynamic> map) { - return Database( - $id: map['\$id'].toString(), - name: map['name'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - enabled: map['enabled'], - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "name": name, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "enabled": enabled, - }; - } + /// Database ID. + final String $id; + + /// Database name. + final String name; + + /// Database creation date in ISO 8601 format. + final String $createdAt; + + /// Database update date in ISO 8601 format. + final String $updatedAt; + + /// If database is enabled. Can be 'enabled' or 'disabled'. When disabled, the database is inaccessible to users, but remains accessible to Server SDKs using API keys. + final bool enabled; + + Database({ + required this.$id, + required this.name, + required this.$createdAt, + required this.$updatedAt, + required this.enabled, + }); + + factory Database.fromMap(Map<String, dynamic> map) { + return Database( + $id: map['\$id'].toString(), + name: map['name'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + enabled: map['enabled'], + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "name": name, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "enabled": enabled, + }; + } } diff --git a/lib/src/models/database_list.dart b/lib/src/models/database_list.dart index ff79d8c9..0ac639f0 100644 --- a/lib/src/models/database_list.dart +++ b/lib/src/models/database_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Databases List class DatabaseList implements Model { - /// Total number of databases documents that matched your query. - final int total; - /// List of databases. - final List<Database> databases; + /// Total number of databases documents that matched your query. + final int total; - DatabaseList({ - required this.total, - required this.databases, - }); + /// List of databases. + final List<Database> databases; - factory DatabaseList.fromMap(Map<String, dynamic> map) { - return DatabaseList( - total: map['total'], - databases: List<Database>.from(map['databases'].map((p) => Database.fromMap(p))), - ); - } + DatabaseList({ + required this.total, + required this.databases, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "databases": databases.map((p) => p.toMap()).toList(), - }; - } + factory DatabaseList.fromMap(Map<String, dynamic> map) { + return DatabaseList( + total: map['total'], + databases: + List<Database>.from(map['databases'].map((p) => Database.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "databases": databases.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/deployment.dart b/lib/src/models/deployment.dart index 67e67d6c..f01fb11e 100644 --- a/lib/src/models/deployment.dart +++ b/lib/src/models/deployment.dart @@ -2,137 +2,160 @@ part of '../../models.dart'; /// Deployment class Deployment implements Model { - /// Deployment ID. - final String $id; - /// Deployment creation date in ISO 8601 format. - final String $createdAt; - /// Deployment update date in ISO 8601 format. - final String $updatedAt; - /// Type of deployment. - final String type; - /// Resource ID. - final String resourceId; - /// Resource type. - final String resourceType; - /// The entrypoint file to use to execute the deployment code. - final String entrypoint; - /// The code size in bytes. - final int size; - /// The build output size in bytes. - final int buildSize; - /// The current build ID. - final String buildId; - /// Whether the deployment should be automatically activated. - final bool activate; - /// The deployment status. Possible values are "processing", "building", "waiting", "ready", and "failed". - final String status; - /// The build logs. - final String buildLogs; - /// The current build time in seconds. - final int buildTime; - /// The name of the vcs provider repository - final String providerRepositoryName; - /// The name of the vcs provider repository owner - final String providerRepositoryOwner; - /// The url of the vcs provider repository - final String providerRepositoryUrl; - /// The branch of the vcs repository - final String providerBranch; - /// The commit hash of the vcs commit - final String providerCommitHash; - /// The url of vcs commit author - final String providerCommitAuthorUrl; - /// The name of vcs commit author - final String providerCommitAuthor; - /// The commit message - final String providerCommitMessage; - /// The url of the vcs commit - final String providerCommitUrl; - /// The branch of the vcs repository - final String providerBranchUrl; - - Deployment({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.type, - required this.resourceId, - required this.resourceType, - required this.entrypoint, - required this.size, - required this.buildSize, - required this.buildId, - required this.activate, - required this.status, - required this.buildLogs, - required this.buildTime, - required this.providerRepositoryName, - required this.providerRepositoryOwner, - required this.providerRepositoryUrl, - required this.providerBranch, - required this.providerCommitHash, - required this.providerCommitAuthorUrl, - required this.providerCommitAuthor, - required this.providerCommitMessage, - required this.providerCommitUrl, - required this.providerBranchUrl, - }); - - factory Deployment.fromMap(Map<String, dynamic> map) { - return Deployment( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - type: map['type'].toString(), - resourceId: map['resourceId'].toString(), - resourceType: map['resourceType'].toString(), - entrypoint: map['entrypoint'].toString(), - size: map['size'], - buildSize: map['buildSize'], - buildId: map['buildId'].toString(), - activate: map['activate'], - status: map['status'].toString(), - buildLogs: map['buildLogs'].toString(), - buildTime: map['buildTime'], - providerRepositoryName: map['providerRepositoryName'].toString(), - providerRepositoryOwner: map['providerRepositoryOwner'].toString(), - providerRepositoryUrl: map['providerRepositoryUrl'].toString(), - providerBranch: map['providerBranch'].toString(), - providerCommitHash: map['providerCommitHash'].toString(), - providerCommitAuthorUrl: map['providerCommitAuthorUrl'].toString(), - providerCommitAuthor: map['providerCommitAuthor'].toString(), - providerCommitMessage: map['providerCommitMessage'].toString(), - providerCommitUrl: map['providerCommitUrl'].toString(), - providerBranchUrl: map['providerBranchUrl'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "type": type, - "resourceId": resourceId, - "resourceType": resourceType, - "entrypoint": entrypoint, - "size": size, - "buildSize": buildSize, - "buildId": buildId, - "activate": activate, - "status": status, - "buildLogs": buildLogs, - "buildTime": buildTime, - "providerRepositoryName": providerRepositoryName, - "providerRepositoryOwner": providerRepositoryOwner, - "providerRepositoryUrl": providerRepositoryUrl, - "providerBranch": providerBranch, - "providerCommitHash": providerCommitHash, - "providerCommitAuthorUrl": providerCommitAuthorUrl, - "providerCommitAuthor": providerCommitAuthor, - "providerCommitMessage": providerCommitMessage, - "providerCommitUrl": providerCommitUrl, - "providerBranchUrl": providerBranchUrl, - }; - } + /// Deployment ID. + final String $id; + + /// Deployment creation date in ISO 8601 format. + final String $createdAt; + + /// Deployment update date in ISO 8601 format. + final String $updatedAt; + + /// Type of deployment. + final String type; + + /// Resource ID. + final String resourceId; + + /// Resource type. + final String resourceType; + + /// The entrypoint file to use to execute the deployment code. + final String entrypoint; + + /// The code size in bytes. + final int size; + + /// The build output size in bytes. + final int buildSize; + + /// The current build ID. + final String buildId; + + /// Whether the deployment should be automatically activated. + final bool activate; + + /// The deployment status. Possible values are "processing", "building", "waiting", "ready", and "failed". + final String status; + + /// The build logs. + final String buildLogs; + + /// The current build time in seconds. + final int buildTime; + + /// The name of the vcs provider repository + final String providerRepositoryName; + + /// The name of the vcs provider repository owner + final String providerRepositoryOwner; + + /// The url of the vcs provider repository + final String providerRepositoryUrl; + + /// The branch of the vcs repository + final String providerBranch; + + /// The commit hash of the vcs commit + final String providerCommitHash; + + /// The url of vcs commit author + final String providerCommitAuthorUrl; + + /// The name of vcs commit author + final String providerCommitAuthor; + + /// The commit message + final String providerCommitMessage; + + /// The url of the vcs commit + final String providerCommitUrl; + + /// The branch of the vcs repository + final String providerBranchUrl; + + Deployment({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.type, + required this.resourceId, + required this.resourceType, + required this.entrypoint, + required this.size, + required this.buildSize, + required this.buildId, + required this.activate, + required this.status, + required this.buildLogs, + required this.buildTime, + required this.providerRepositoryName, + required this.providerRepositoryOwner, + required this.providerRepositoryUrl, + required this.providerBranch, + required this.providerCommitHash, + required this.providerCommitAuthorUrl, + required this.providerCommitAuthor, + required this.providerCommitMessage, + required this.providerCommitUrl, + required this.providerBranchUrl, + }); + + factory Deployment.fromMap(Map<String, dynamic> map) { + return Deployment( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + type: map['type'].toString(), + resourceId: map['resourceId'].toString(), + resourceType: map['resourceType'].toString(), + entrypoint: map['entrypoint'].toString(), + size: map['size'], + buildSize: map['buildSize'], + buildId: map['buildId'].toString(), + activate: map['activate'], + status: map['status'].toString(), + buildLogs: map['buildLogs'].toString(), + buildTime: map['buildTime'], + providerRepositoryName: map['providerRepositoryName'].toString(), + providerRepositoryOwner: map['providerRepositoryOwner'].toString(), + providerRepositoryUrl: map['providerRepositoryUrl'].toString(), + providerBranch: map['providerBranch'].toString(), + providerCommitHash: map['providerCommitHash'].toString(), + providerCommitAuthorUrl: map['providerCommitAuthorUrl'].toString(), + providerCommitAuthor: map['providerCommitAuthor'].toString(), + providerCommitMessage: map['providerCommitMessage'].toString(), + providerCommitUrl: map['providerCommitUrl'].toString(), + providerBranchUrl: map['providerBranchUrl'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "type": type, + "resourceId": resourceId, + "resourceType": resourceType, + "entrypoint": entrypoint, + "size": size, + "buildSize": buildSize, + "buildId": buildId, + "activate": activate, + "status": status, + "buildLogs": buildLogs, + "buildTime": buildTime, + "providerRepositoryName": providerRepositoryName, + "providerRepositoryOwner": providerRepositoryOwner, + "providerRepositoryUrl": providerRepositoryUrl, + "providerBranch": providerBranch, + "providerCommitHash": providerCommitHash, + "providerCommitAuthorUrl": providerCommitAuthorUrl, + "providerCommitAuthor": providerCommitAuthor, + "providerCommitMessage": providerCommitMessage, + "providerCommitUrl": providerCommitUrl, + "providerBranchUrl": providerBranchUrl, + }; + } } diff --git a/lib/src/models/deployment_list.dart b/lib/src/models/deployment_list.dart index 3eaa589e..03e03c98 100644 --- a/lib/src/models/deployment_list.dart +++ b/lib/src/models/deployment_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Deployments List class DeploymentList implements Model { - /// Total number of deployments documents that matched your query. - final int total; - /// List of deployments. - final List<Deployment> deployments; + /// Total number of deployments documents that matched your query. + final int total; - DeploymentList({ - required this.total, - required this.deployments, - }); + /// List of deployments. + final List<Deployment> deployments; - factory DeploymentList.fromMap(Map<String, dynamic> map) { - return DeploymentList( - total: map['total'], - deployments: List<Deployment>.from(map['deployments'].map((p) => Deployment.fromMap(p))), - ); - } + DeploymentList({ + required this.total, + required this.deployments, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "deployments": deployments.map((p) => p.toMap()).toList(), - }; - } + factory DeploymentList.fromMap(Map<String, dynamic> map) { + return DeploymentList( + total: map['total'], + deployments: List<Deployment>.from( + map['deployments'].map((p) => Deployment.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "deployments": deployments.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/document.dart b/lib/src/models/document.dart index 42721317..f8164b61 100644 --- a/lib/src/models/document.dart +++ b/lib/src/models/document.dart @@ -2,53 +2,58 @@ part of '../../models.dart'; /// Document class Document implements Model { - /// Document ID. - final String $id; - /// Collection ID. - final String $collectionId; - /// Database ID. - final String $databaseId; - /// Document creation date in ISO 8601 format. - final String $createdAt; - /// Document update date in ISO 8601 format. - final String $updatedAt; - /// Document permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List<String> $permissions; - final Map<String, dynamic> data; - - Document({ - required this.$id, - required this.$collectionId, - required this.$databaseId, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.data, - }); - - factory Document.fromMap(Map<String, dynamic> map) { - return Document( - $id: map['\$id'].toString(), - $collectionId: map['\$collectionId'].toString(), - $databaseId: map['\$databaseId'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - data: map, - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$collectionId": $collectionId, - "\$databaseId": $databaseId, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "data": data, - }; - } - - T convertTo<T>(T Function(Map) fromJson) => fromJson(data); + /// Document ID. + final String $id; + + /// Collection ID. + final String $collectionId; + + /// Database ID. + final String $databaseId; + + /// Document creation date in ISO 8601 format. + final String $createdAt; + + /// Document update date in ISO 8601 format. + final String $updatedAt; + + /// Document permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List<String> $permissions; + final Map<String, dynamic> data; + + Document({ + required this.$id, + required this.$collectionId, + required this.$databaseId, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.data, + }); + + factory Document.fromMap(Map<String, dynamic> map) { + return Document( + $id: map['\$id'].toString(), + $collectionId: map['\$collectionId'].toString(), + $databaseId: map['\$databaseId'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + data: map, + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$collectionId": $collectionId, + "\$databaseId": $databaseId, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "data": data, + }; + } + + T convertTo<T>(T Function(Map) fromJson) => fromJson(data); } diff --git a/lib/src/models/document_list.dart b/lib/src/models/document_list.dart index 9d3de14b..b4fd20eb 100644 --- a/lib/src/models/document_list.dart +++ b/lib/src/models/document_list.dart @@ -2,30 +2,32 @@ part of '../../models.dart'; /// Documents List class DocumentList implements Model { - /// Total number of documents documents that matched your query. - final int total; - /// List of documents. - final List<Document> documents; + /// Total number of documents documents that matched your query. + final int total; - DocumentList({ - required this.total, - required this.documents, - }); + /// List of documents. + final List<Document> documents; - factory DocumentList.fromMap(Map<String, dynamic> map) { - return DocumentList( - total: map['total'], - documents: List<Document>.from(map['documents'].map((p) => Document.fromMap(p))), - ); - } + DocumentList({ + required this.total, + required this.documents, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "documents": documents.map((p) => p.toMap()).toList(), - }; - } + factory DocumentList.fromMap(Map<String, dynamic> map) { + return DocumentList( + total: map['total'], + documents: + List<Document>.from(map['documents'].map((p) => Document.fromMap(p))), + ); + } - List<T> convertTo<T>(T Function(Map) fromJson) => - documents.map((d) => d.convertTo<T>(fromJson)).toList(); + Map<String, dynamic> toMap() { + return { + "total": total, + "documents": documents.map((p) => p.toMap()).toList(), + }; + } + + List<T> convertTo<T>(T Function(Map) fromJson) => + documents.map((d) => d.convertTo<T>(fromJson)).toList(); } diff --git a/lib/src/models/execution.dart b/lib/src/models/execution.dart index 9373a245..9f9b8917 100644 --- a/lib/src/models/execution.dart +++ b/lib/src/models/execution.dart @@ -2,102 +2,120 @@ part of '../../models.dart'; /// Execution class Execution implements Model { - /// Execution ID. - final String $id; - /// Execution creation date in ISO 8601 format. - final String $createdAt; - /// Execution upate date in ISO 8601 format. - final String $updatedAt; - /// Execution roles. - final List<String> $permissions; - /// Function ID. - final String functionId; - /// The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`. - final String trigger; - /// The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`. - final String status; - /// HTTP request method type. - final String requestMethod; - /// HTTP request path and query. - final String requestPath; - /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. - final List<Headers> requestHeaders; - /// HTTP response status code. - final int responseStatusCode; - /// HTTP response body. This will return empty unless execution is created as synchronous. - final String responseBody; - /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. - final List<Headers> responseHeaders; - /// Function logs. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. - final String logs; - /// Function errors. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. - final String errors; - /// Function execution duration in seconds. - final double duration; - /// The scheduled time for execution. If left empty, execution will be queued immediately. - final String? scheduledAt; - - Execution({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.functionId, - required this.trigger, - required this.status, - required this.requestMethod, - required this.requestPath, - required this.requestHeaders, - required this.responseStatusCode, - required this.responseBody, - required this.responseHeaders, - required this.logs, - required this.errors, - required this.duration, - this.scheduledAt, - }); - - factory Execution.fromMap(Map<String, dynamic> map) { - return Execution( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - functionId: map['functionId'].toString(), - trigger: map['trigger'].toString(), - status: map['status'].toString(), - requestMethod: map['requestMethod'].toString(), - requestPath: map['requestPath'].toString(), - requestHeaders: List<Headers>.from(map['requestHeaders'].map((p) => Headers.fromMap(p))), - responseStatusCode: map['responseStatusCode'], - responseBody: map['responseBody'].toString(), - responseHeaders: List<Headers>.from(map['responseHeaders'].map((p) => Headers.fromMap(p))), - logs: map['logs'].toString(), - errors: map['errors'].toString(), - duration: map['duration'].toDouble(), - scheduledAt: map['scheduledAt']?.toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "functionId": functionId, - "trigger": trigger, - "status": status, - "requestMethod": requestMethod, - "requestPath": requestPath, - "requestHeaders": requestHeaders.map((p) => p.toMap()).toList(), - "responseStatusCode": responseStatusCode, - "responseBody": responseBody, - "responseHeaders": responseHeaders.map((p) => p.toMap()).toList(), - "logs": logs, - "errors": errors, - "duration": duration, - "scheduledAt": scheduledAt, - }; - } + /// Execution ID. + final String $id; + + /// Execution creation date in ISO 8601 format. + final String $createdAt; + + /// Execution upate date in ISO 8601 format. + final String $updatedAt; + + /// Execution roles. + final List<String> $permissions; + + /// Function ID. + final String functionId; + + /// The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`. + final String trigger; + + /// The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`. + final String status; + + /// HTTP request method type. + final String requestMethod; + + /// HTTP request path and query. + final String requestPath; + + /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. + final List<Headers> requestHeaders; + + /// HTTP response status code. + final int responseStatusCode; + + /// HTTP response body. This will return empty unless execution is created as synchronous. + final String responseBody; + + /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. + final List<Headers> responseHeaders; + + /// Function logs. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. + final String logs; + + /// Function errors. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. + final String errors; + + /// Function execution duration in seconds. + final double duration; + + /// The scheduled time for execution. If left empty, execution will be queued immediately. + final String? scheduledAt; + + Execution({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.functionId, + required this.trigger, + required this.status, + required this.requestMethod, + required this.requestPath, + required this.requestHeaders, + required this.responseStatusCode, + required this.responseBody, + required this.responseHeaders, + required this.logs, + required this.errors, + required this.duration, + this.scheduledAt, + }); + + factory Execution.fromMap(Map<String, dynamic> map) { + return Execution( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + functionId: map['functionId'].toString(), + trigger: map['trigger'].toString(), + status: map['status'].toString(), + requestMethod: map['requestMethod'].toString(), + requestPath: map['requestPath'].toString(), + requestHeaders: List<Headers>.from( + map['requestHeaders'].map((p) => Headers.fromMap(p))), + responseStatusCode: map['responseStatusCode'], + responseBody: map['responseBody'].toString(), + responseHeaders: List<Headers>.from( + map['responseHeaders'].map((p) => Headers.fromMap(p))), + logs: map['logs'].toString(), + errors: map['errors'].toString(), + duration: map['duration'].toDouble(), + scheduledAt: map['scheduledAt']?.toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "functionId": functionId, + "trigger": trigger, + "status": status, + "requestMethod": requestMethod, + "requestPath": requestPath, + "requestHeaders": requestHeaders.map((p) => p.toMap()).toList(), + "responseStatusCode": responseStatusCode, + "responseBody": responseBody, + "responseHeaders": responseHeaders.map((p) => p.toMap()).toList(), + "logs": logs, + "errors": errors, + "duration": duration, + "scheduledAt": scheduledAt, + }; + } } diff --git a/lib/src/models/execution_list.dart b/lib/src/models/execution_list.dart index 00333204..32e40531 100644 --- a/lib/src/models/execution_list.dart +++ b/lib/src/models/execution_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Executions List class ExecutionList implements Model { - /// Total number of executions documents that matched your query. - final int total; - /// List of executions. - final List<Execution> executions; + /// Total number of executions documents that matched your query. + final int total; - ExecutionList({ - required this.total, - required this.executions, - }); + /// List of executions. + final List<Execution> executions; - factory ExecutionList.fromMap(Map<String, dynamic> map) { - return ExecutionList( - total: map['total'], - executions: List<Execution>.from(map['executions'].map((p) => Execution.fromMap(p))), - ); - } + ExecutionList({ + required this.total, + required this.executions, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "executions": executions.map((p) => p.toMap()).toList(), - }; - } + factory ExecutionList.fromMap(Map<String, dynamic> map) { + return ExecutionList( + total: map['total'], + executions: List<Execution>.from( + map['executions'].map((p) => Execution.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "executions": executions.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/file.dart b/lib/src/models/file.dart index 2dac8960..4bca1fe3 100644 --- a/lib/src/models/file.dart +++ b/lib/src/models/file.dart @@ -2,72 +2,82 @@ part of '../../models.dart'; /// File class File implements Model { - /// File ID. - final String $id; - /// Bucket ID. - final String bucketId; - /// File creation date in ISO 8601 format. - final String $createdAt; - /// File update date in ISO 8601 format. - final String $updatedAt; - /// File permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List<String> $permissions; - /// File name. - final String name; - /// File MD5 signature. - final String signature; - /// File mime type. - final String mimeType; - /// File original size in bytes. - final int sizeOriginal; - /// Total number of chunks available - final int chunksTotal; - /// Total number of chunks uploaded - final int chunksUploaded; + /// File ID. + final String $id; - File({ - required this.$id, - required this.bucketId, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.name, - required this.signature, - required this.mimeType, - required this.sizeOriginal, - required this.chunksTotal, - required this.chunksUploaded, - }); + /// Bucket ID. + final String bucketId; - factory File.fromMap(Map<String, dynamic> map) { - return File( - $id: map['\$id'].toString(), - bucketId: map['bucketId'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - name: map['name'].toString(), - signature: map['signature'].toString(), - mimeType: map['mimeType'].toString(), - sizeOriginal: map['sizeOriginal'], - chunksTotal: map['chunksTotal'], - chunksUploaded: map['chunksUploaded'], - ); - } + /// File creation date in ISO 8601 format. + final String $createdAt; - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "bucketId": bucketId, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "name": name, - "signature": signature, - "mimeType": mimeType, - "sizeOriginal": sizeOriginal, - "chunksTotal": chunksTotal, - "chunksUploaded": chunksUploaded, - }; - } + /// File update date in ISO 8601 format. + final String $updatedAt; + + /// File permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List<String> $permissions; + + /// File name. + final String name; + + /// File MD5 signature. + final String signature; + + /// File mime type. + final String mimeType; + + /// File original size in bytes. + final int sizeOriginal; + + /// Total number of chunks available + final int chunksTotal; + + /// Total number of chunks uploaded + final int chunksUploaded; + + File({ + required this.$id, + required this.bucketId, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.name, + required this.signature, + required this.mimeType, + required this.sizeOriginal, + required this.chunksTotal, + required this.chunksUploaded, + }); + + factory File.fromMap(Map<String, dynamic> map) { + return File( + $id: map['\$id'].toString(), + bucketId: map['bucketId'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: map['\$permissions'] ?? [], + name: map['name'].toString(), + signature: map['signature'].toString(), + mimeType: map['mimeType'].toString(), + sizeOriginal: map['sizeOriginal'], + chunksTotal: map['chunksTotal'], + chunksUploaded: map['chunksUploaded'], + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "bucketId": bucketId, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "name": name, + "signature": signature, + "mimeType": mimeType, + "sizeOriginal": sizeOriginal, + "chunksTotal": chunksTotal, + "chunksUploaded": chunksUploaded, + }; + } } diff --git a/lib/src/models/file_list.dart b/lib/src/models/file_list.dart index b0872489..3b695c93 100644 --- a/lib/src/models/file_list.dart +++ b/lib/src/models/file_list.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Files List class FileList implements Model { - /// Total number of files documents that matched your query. - final int total; - /// List of files. - final List<File> files; + /// Total number of files documents that matched your query. + final int total; - FileList({ - required this.total, - required this.files, - }); + /// List of files. + final List<File> files; - factory FileList.fromMap(Map<String, dynamic> map) { - return FileList( - total: map['total'], - files: List<File>.from(map['files'].map((p) => File.fromMap(p))), - ); - } + FileList({ + required this.total, + required this.files, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "files": files.map((p) => p.toMap()).toList(), - }; - } + factory FileList.fromMap(Map<String, dynamic> map) { + return FileList( + total: map['total'], + files: List<File>.from(map['files'].map((p) => File.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "files": files.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/function.dart b/lib/src/models/function.dart index bf8c22aa..83b5a60d 100644 --- a/lib/src/models/function.dart +++ b/lib/src/models/function.dart @@ -2,137 +2,160 @@ part of '../../models.dart'; /// Function class Func implements Model { - /// Function ID. - final String $id; - /// Function creation date in ISO 8601 format. - final String $createdAt; - /// Function update date in ISO 8601 format. - final String $updatedAt; - /// Execution permissions. - final List<String> execute; - /// Function name. - final String name; - /// Function enabled. - final bool enabled; - /// Is the function deployed with the latest configuration? This is set to false if you've changed an environment variables, entrypoint, commands, or other settings that needs redeploy to be applied. When the value is false, redeploy the function to update it with the latest configuration. - final bool live; - /// Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project. - final bool logging; - /// Function execution runtime. - final String runtime; - /// Function's active deployment ID. - final String deployment; - /// Allowed permission scopes. - final List<String> scopes; - /// Function variables. - final List<Variable> vars; - /// Function trigger events. - final List<String> events; - /// Function execution schedule in CRON format. - final String schedule; - /// Function execution timeout in seconds. - final int timeout; - /// The entrypoint file used to execute the deployment. - final String entrypoint; - /// The build command used to build the deployment. - final String commands; - /// Version of Open Runtimes used for the function. - final String version; - /// Function VCS (Version Control System) installation id. - final String installationId; - /// VCS (Version Control System) Repository ID - final String providerRepositoryId; - /// VCS (Version Control System) branch name - final String providerBranch; - /// Path to function in VCS (Version Control System) repository - final String providerRootDirectory; - /// Is VCS (Version Control System) connection is in silent mode? When in silence mode, no comments will be posted on the repository pull or merge requests - final bool providerSilentMode; - /// Machine specification for builds and executions. - final String specification; - - Func({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.execute, - required this.name, - required this.enabled, - required this.live, - required this.logging, - required this.runtime, - required this.deployment, - required this.scopes, - required this.vars, - required this.events, - required this.schedule, - required this.timeout, - required this.entrypoint, - required this.commands, - required this.version, - required this.installationId, - required this.providerRepositoryId, - required this.providerBranch, - required this.providerRootDirectory, - required this.providerSilentMode, - required this.specification, - }); - - factory Func.fromMap(Map<String, dynamic> map) { - return Func( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - execute: map['execute'] ?? [], - name: map['name'].toString(), - enabled: map['enabled'], - live: map['live'], - logging: map['logging'], - runtime: map['runtime'].toString(), - deployment: map['deployment'].toString(), - scopes: map['scopes'] ?? [], - vars: List<Variable>.from(map['vars'].map((p) => Variable.fromMap(p))), - events: map['events'] ?? [], - schedule: map['schedule'].toString(), - timeout: map['timeout'], - entrypoint: map['entrypoint'].toString(), - commands: map['commands'].toString(), - version: map['version'].toString(), - installationId: map['installationId'].toString(), - providerRepositoryId: map['providerRepositoryId'].toString(), - providerBranch: map['providerBranch'].toString(), - providerRootDirectory: map['providerRootDirectory'].toString(), - providerSilentMode: map['providerSilentMode'], - specification: map['specification'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "execute": execute, - "name": name, - "enabled": enabled, - "live": live, - "logging": logging, - "runtime": runtime, - "deployment": deployment, - "scopes": scopes, - "vars": vars.map((p) => p.toMap()).toList(), - "events": events, - "schedule": schedule, - "timeout": timeout, - "entrypoint": entrypoint, - "commands": commands, - "version": version, - "installationId": installationId, - "providerRepositoryId": providerRepositoryId, - "providerBranch": providerBranch, - "providerRootDirectory": providerRootDirectory, - "providerSilentMode": providerSilentMode, - "specification": specification, - }; - } + /// Function ID. + final String $id; + + /// Function creation date in ISO 8601 format. + final String $createdAt; + + /// Function update date in ISO 8601 format. + final String $updatedAt; + + /// Execution permissions. + final List<String> execute; + + /// Function name. + final String name; + + /// Function enabled. + final bool enabled; + + /// Is the function deployed with the latest configuration? This is set to false if you've changed an environment variables, entrypoint, commands, or other settings that needs redeploy to be applied. When the value is false, redeploy the function to update it with the latest configuration. + final bool live; + + /// Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project. + final bool logging; + + /// Function execution runtime. + final String runtime; + + /// Function's active deployment ID. + final String deployment; + + /// Allowed permission scopes. + final List<String> scopes; + + /// Function variables. + final List<Variable> vars; + + /// Function trigger events. + final List<String> events; + + /// Function execution schedule in CRON format. + final String schedule; + + /// Function execution timeout in seconds. + final int timeout; + + /// The entrypoint file used to execute the deployment. + final String entrypoint; + + /// The build command used to build the deployment. + final String commands; + + /// Version of Open Runtimes used for the function. + final String version; + + /// Function VCS (Version Control System) installation id. + final String installationId; + + /// VCS (Version Control System) Repository ID + final String providerRepositoryId; + + /// VCS (Version Control System) branch name + final String providerBranch; + + /// Path to function in VCS (Version Control System) repository + final String providerRootDirectory; + + /// Is VCS (Version Control System) connection is in silent mode? When in silence mode, no comments will be posted on the repository pull or merge requests + final bool providerSilentMode; + + /// Machine specification for builds and executions. + final String specification; + + Func({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.execute, + required this.name, + required this.enabled, + required this.live, + required this.logging, + required this.runtime, + required this.deployment, + required this.scopes, + required this.vars, + required this.events, + required this.schedule, + required this.timeout, + required this.entrypoint, + required this.commands, + required this.version, + required this.installationId, + required this.providerRepositoryId, + required this.providerBranch, + required this.providerRootDirectory, + required this.providerSilentMode, + required this.specification, + }); + + factory Func.fromMap(Map<String, dynamic> map) { + return Func( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + execute: map['execute'] ?? [], + name: map['name'].toString(), + enabled: map['enabled'], + live: map['live'], + logging: map['logging'], + runtime: map['runtime'].toString(), + deployment: map['deployment'].toString(), + scopes: map['scopes'] ?? [], + vars: List<Variable>.from(map['vars'].map((p) => Variable.fromMap(p))), + events: map['events'] ?? [], + schedule: map['schedule'].toString(), + timeout: map['timeout'], + entrypoint: map['entrypoint'].toString(), + commands: map['commands'].toString(), + version: map['version'].toString(), + installationId: map['installationId'].toString(), + providerRepositoryId: map['providerRepositoryId'].toString(), + providerBranch: map['providerBranch'].toString(), + providerRootDirectory: map['providerRootDirectory'].toString(), + providerSilentMode: map['providerSilentMode'], + specification: map['specification'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "execute": execute, + "name": name, + "enabled": enabled, + "live": live, + "logging": logging, + "runtime": runtime, + "deployment": deployment, + "scopes": scopes, + "vars": vars.map((p) => p.toMap()).toList(), + "events": events, + "schedule": schedule, + "timeout": timeout, + "entrypoint": entrypoint, + "commands": commands, + "version": version, + "installationId": installationId, + "providerRepositoryId": providerRepositoryId, + "providerBranch": providerBranch, + "providerRootDirectory": providerRootDirectory, + "providerSilentMode": providerSilentMode, + "specification": specification, + }; + } } diff --git a/lib/src/models/function_list.dart b/lib/src/models/function_list.dart index 83a8f93b..5c53b276 100644 --- a/lib/src/models/function_list.dart +++ b/lib/src/models/function_list.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Functions List class FunctionList implements Model { - /// Total number of functions documents that matched your query. - final int total; - /// List of functions. - final List<Func> functions; + /// Total number of functions documents that matched your query. + final int total; - FunctionList({ - required this.total, - required this.functions, - }); + /// List of functions. + final List<Func> functions; - factory FunctionList.fromMap(Map<String, dynamic> map) { - return FunctionList( - total: map['total'], - functions: List<Func>.from(map['functions'].map((p) => Func.fromMap(p))), - ); - } + FunctionList({ + required this.total, + required this.functions, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "functions": functions.map((p) => p.toMap()).toList(), - }; - } + factory FunctionList.fromMap(Map<String, dynamic> map) { + return FunctionList( + total: map['total'], + functions: List<Func>.from(map['functions'].map((p) => Func.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "functions": functions.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/headers.dart b/lib/src/models/headers.dart index f03c5ce4..22494998 100644 --- a/lib/src/models/headers.dart +++ b/lib/src/models/headers.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Headers class Headers implements Model { - /// Header name. - final String name; - /// Header value. - final String value; + /// Header name. + final String name; - Headers({ - required this.name, - required this.value, - }); + /// Header value. + final String value; - factory Headers.fromMap(Map<String, dynamic> map) { - return Headers( - name: map['name'].toString(), - value: map['value'].toString(), - ); - } + Headers({ + required this.name, + required this.value, + }); - Map<String, dynamic> toMap() { - return { - "name": name, - "value": value, - }; - } + factory Headers.fromMap(Map<String, dynamic> map) { + return Headers( + name: map['name'].toString(), + value: map['value'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "name": name, + "value": value, + }; + } } diff --git a/lib/src/models/health_antivirus.dart b/lib/src/models/health_antivirus.dart index 48b8ad32..aabc7d85 100644 --- a/lib/src/models/health_antivirus.dart +++ b/lib/src/models/health_antivirus.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Health Antivirus class HealthAntivirus implements Model { - /// Antivirus version. - final String version; - /// Antivirus status. Possible values can are: `disabled`, `offline`, `online` - final String status; + /// Antivirus version. + final String version; - HealthAntivirus({ - required this.version, - required this.status, - }); + /// Antivirus status. Possible values can are: `disabled`, `offline`, `online` + final String status; - factory HealthAntivirus.fromMap(Map<String, dynamic> map) { - return HealthAntivirus( - version: map['version'].toString(), - status: map['status'].toString(), - ); - } + HealthAntivirus({ + required this.version, + required this.status, + }); - Map<String, dynamic> toMap() { - return { - "version": version, - "status": status, - }; - } + factory HealthAntivirus.fromMap(Map<String, dynamic> map) { + return HealthAntivirus( + version: map['version'].toString(), + status: map['status'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "version": version, + "status": status, + }; + } } diff --git a/lib/src/models/health_certificate.dart b/lib/src/models/health_certificate.dart index 3409d8e7..d412eba9 100644 --- a/lib/src/models/health_certificate.dart +++ b/lib/src/models/health_certificate.dart @@ -2,47 +2,52 @@ part of '../../models.dart'; /// Health Certificate class HealthCertificate implements Model { - /// Certificate name - final String name; - /// Subject SN - final String subjectSN; - /// Issuer organisation - final String issuerOrganisation; - /// Valid from - final String validFrom; - /// Valid to - final String validTo; - /// Signature type SN - final String signatureTypeSN; - - HealthCertificate({ - required this.name, - required this.subjectSN, - required this.issuerOrganisation, - required this.validFrom, - required this.validTo, - required this.signatureTypeSN, - }); - - factory HealthCertificate.fromMap(Map<String, dynamic> map) { - return HealthCertificate( - name: map['name'].toString(), - subjectSN: map['subjectSN'].toString(), - issuerOrganisation: map['issuerOrganisation'].toString(), - validFrom: map['validFrom'].toString(), - validTo: map['validTo'].toString(), - signatureTypeSN: map['signatureTypeSN'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "name": name, - "subjectSN": subjectSN, - "issuerOrganisation": issuerOrganisation, - "validFrom": validFrom, - "validTo": validTo, - "signatureTypeSN": signatureTypeSN, - }; - } + /// Certificate name + final String name; + + /// Subject SN + final String subjectSN; + + /// Issuer organisation + final String issuerOrganisation; + + /// Valid from + final String validFrom; + + /// Valid to + final String validTo; + + /// Signature type SN + final String signatureTypeSN; + + HealthCertificate({ + required this.name, + required this.subjectSN, + required this.issuerOrganisation, + required this.validFrom, + required this.validTo, + required this.signatureTypeSN, + }); + + factory HealthCertificate.fromMap(Map<String, dynamic> map) { + return HealthCertificate( + name: map['name'].toString(), + subjectSN: map['subjectSN'].toString(), + issuerOrganisation: map['issuerOrganisation'].toString(), + validFrom: map['validFrom'].toString(), + validTo: map['validTo'].toString(), + signatureTypeSN: map['signatureTypeSN'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "name": name, + "subjectSN": subjectSN, + "issuerOrganisation": issuerOrganisation, + "validFrom": validFrom, + "validTo": validTo, + "signatureTypeSN": signatureTypeSN, + }; + } } diff --git a/lib/src/models/health_queue.dart b/lib/src/models/health_queue.dart index 95da1235..8b3aa1b6 100644 --- a/lib/src/models/health_queue.dart +++ b/lib/src/models/health_queue.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// Health Queue class HealthQueue implements Model { - /// Amount of actions in the queue. - final int size; + /// Amount of actions in the queue. + final int size; - HealthQueue({ - required this.size, - }); + HealthQueue({ + required this.size, + }); - factory HealthQueue.fromMap(Map<String, dynamic> map) { - return HealthQueue( - size: map['size'], - ); - } + factory HealthQueue.fromMap(Map<String, dynamic> map) { + return HealthQueue( + size: map['size'], + ); + } - Map<String, dynamic> toMap() { - return { - "size": size, - }; - } + Map<String, dynamic> toMap() { + return { + "size": size, + }; + } } diff --git a/lib/src/models/health_status.dart b/lib/src/models/health_status.dart index 57526c24..b22b2c8a 100644 --- a/lib/src/models/health_status.dart +++ b/lib/src/models/health_status.dart @@ -2,32 +2,34 @@ part of '../../models.dart'; /// Health Status class HealthStatus implements Model { - /// Name of the service. - final String name; - /// Duration in milliseconds how long the health check took. - final int ping; - /// Service status. Possible values can are: `pass`, `fail` - final String status; + /// Name of the service. + final String name; - HealthStatus({ - required this.name, - required this.ping, - required this.status, - }); + /// Duration in milliseconds how long the health check took. + final int ping; - factory HealthStatus.fromMap(Map<String, dynamic> map) { - return HealthStatus( - name: map['name'].toString(), - ping: map['ping'], - status: map['status'].toString(), - ); - } + /// Service status. Possible values can are: `pass`, `fail` + final String status; - Map<String, dynamic> toMap() { - return { - "name": name, - "ping": ping, - "status": status, - }; - } + HealthStatus({ + required this.name, + required this.ping, + required this.status, + }); + + factory HealthStatus.fromMap(Map<String, dynamic> map) { + return HealthStatus( + name: map['name'].toString(), + ping: map['ping'], + status: map['status'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "name": name, + "ping": ping, + "status": status, + }; + } } diff --git a/lib/src/models/health_time.dart b/lib/src/models/health_time.dart index 0b8b4a35..0ed15f0a 100644 --- a/lib/src/models/health_time.dart +++ b/lib/src/models/health_time.dart @@ -2,32 +2,34 @@ part of '../../models.dart'; /// Health Time class HealthTime implements Model { - /// Current unix timestamp on trustful remote server. - final int remoteTime; - /// Current unix timestamp of local server where Appwrite runs. - final int localTime; - /// Difference of unix remote and local timestamps in milliseconds. - final int diff; + /// Current unix timestamp on trustful remote server. + final int remoteTime; - HealthTime({ - required this.remoteTime, - required this.localTime, - required this.diff, - }); + /// Current unix timestamp of local server where Appwrite runs. + final int localTime; - factory HealthTime.fromMap(Map<String, dynamic> map) { - return HealthTime( - remoteTime: map['remoteTime'], - localTime: map['localTime'], - diff: map['diff'], - ); - } + /// Difference of unix remote and local timestamps in milliseconds. + final int diff; - Map<String, dynamic> toMap() { - return { - "remoteTime": remoteTime, - "localTime": localTime, - "diff": diff, - }; - } + HealthTime({ + required this.remoteTime, + required this.localTime, + required this.diff, + }); + + factory HealthTime.fromMap(Map<String, dynamic> map) { + return HealthTime( + remoteTime: map['remoteTime'], + localTime: map['localTime'], + diff: map['diff'], + ); + } + + Map<String, dynamic> toMap() { + return { + "remoteTime": remoteTime, + "localTime": localTime, + "diff": diff, + }; + } } diff --git a/lib/src/models/identity.dart b/lib/src/models/identity.dart index 632dc3db..807bdfd0 100644 --- a/lib/src/models/identity.dart +++ b/lib/src/models/identity.dart @@ -2,67 +2,76 @@ part of '../../models.dart'; /// Identity class Identity implements Model { - /// Identity ID. - final String $id; - /// Identity creation date in ISO 8601 format. - final String $createdAt; - /// Identity update date in ISO 8601 format. - final String $updatedAt; - /// User ID. - final String userId; - /// Identity Provider. - final String provider; - /// ID of the User in the Identity Provider. - final String providerUid; - /// Email of the User in the Identity Provider. - final String providerEmail; - /// Identity Provider Access Token. - final String providerAccessToken; - /// The date of when the access token expires in ISO 8601 format. - final String providerAccessTokenExpiry; - /// Identity Provider Refresh Token. - final String providerRefreshToken; + /// Identity ID. + final String $id; - Identity({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.userId, - required this.provider, - required this.providerUid, - required this.providerEmail, - required this.providerAccessToken, - required this.providerAccessTokenExpiry, - required this.providerRefreshToken, - }); + /// Identity creation date in ISO 8601 format. + final String $createdAt; - factory Identity.fromMap(Map<String, dynamic> map) { - return Identity( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - userId: map['userId'].toString(), - provider: map['provider'].toString(), - providerUid: map['providerUid'].toString(), - providerEmail: map['providerEmail'].toString(), - providerAccessToken: map['providerAccessToken'].toString(), - providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), - providerRefreshToken: map['providerRefreshToken'].toString(), - ); - } + /// Identity update date in ISO 8601 format. + final String $updatedAt; - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "userId": userId, - "provider": provider, - "providerUid": providerUid, - "providerEmail": providerEmail, - "providerAccessToken": providerAccessToken, - "providerAccessTokenExpiry": providerAccessTokenExpiry, - "providerRefreshToken": providerRefreshToken, - }; - } + /// User ID. + final String userId; + + /// Identity Provider. + final String provider; + + /// ID of the User in the Identity Provider. + final String providerUid; + + /// Email of the User in the Identity Provider. + final String providerEmail; + + /// Identity Provider Access Token. + final String providerAccessToken; + + /// The date of when the access token expires in ISO 8601 format. + final String providerAccessTokenExpiry; + + /// Identity Provider Refresh Token. + final String providerRefreshToken; + + Identity({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.userId, + required this.provider, + required this.providerUid, + required this.providerEmail, + required this.providerAccessToken, + required this.providerAccessTokenExpiry, + required this.providerRefreshToken, + }); + + factory Identity.fromMap(Map<String, dynamic> map) { + return Identity( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + userId: map['userId'].toString(), + provider: map['provider'].toString(), + providerUid: map['providerUid'].toString(), + providerEmail: map['providerEmail'].toString(), + providerAccessToken: map['providerAccessToken'].toString(), + providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), + providerRefreshToken: map['providerRefreshToken'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "userId": userId, + "provider": provider, + "providerUid": providerUid, + "providerEmail": providerEmail, + "providerAccessToken": providerAccessToken, + "providerAccessTokenExpiry": providerAccessTokenExpiry, + "providerRefreshToken": providerRefreshToken, + }; + } } diff --git a/lib/src/models/identity_list.dart b/lib/src/models/identity_list.dart index b38c9775..eab513d8 100644 --- a/lib/src/models/identity_list.dart +++ b/lib/src/models/identity_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Identities List class IdentityList implements Model { - /// Total number of identities documents that matched your query. - final int total; - /// List of identities. - final List<Identity> identities; + /// Total number of identities documents that matched your query. + final int total; - IdentityList({ - required this.total, - required this.identities, - }); + /// List of identities. + final List<Identity> identities; - factory IdentityList.fromMap(Map<String, dynamic> map) { - return IdentityList( - total: map['total'], - identities: List<Identity>.from(map['identities'].map((p) => Identity.fromMap(p))), - ); - } + IdentityList({ + required this.total, + required this.identities, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "identities": identities.map((p) => p.toMap()).toList(), - }; - } + factory IdentityList.fromMap(Map<String, dynamic> map) { + return IdentityList( + total: map['total'], + identities: List<Identity>.from( + map['identities'].map((p) => Identity.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "identities": identities.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/index.dart b/lib/src/models/index.dart index 2f0353d5..322f1228 100644 --- a/lib/src/models/index.dart +++ b/lib/src/models/index.dart @@ -2,57 +2,64 @@ part of '../../models.dart'; /// Index class Index implements Model { - /// Index Key. - final String key; - /// Index type. - final String type; - /// Index status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - /// Error message. Displays error generated on failure of creating or deleting an index. - final String error; - /// Index attributes. - final List<String> attributes; - /// Index orders. - final List<String>? orders; - /// Index creation date in ISO 8601 format. - final String $createdAt; - /// Index update date in ISO 8601 format. - final String $updatedAt; - - Index({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.attributes, - this.orders, - required this.$createdAt, - required this.$updatedAt, - }); - - factory Index.fromMap(Map<String, dynamic> map) { - return Index( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - attributes: map['attributes'] ?? [], - orders: map['orders'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "attributes": attributes, - "orders": orders, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - }; - } + /// Index Key. + final String key; + + /// Index type. + final String type; + + /// Index status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + + /// Error message. Displays error generated on failure of creating or deleting an index. + final String error; + + /// Index attributes. + final List<String> attributes; + + /// Index orders. + final List<String>? orders; + + /// Index creation date in ISO 8601 format. + final String $createdAt; + + /// Index update date in ISO 8601 format. + final String $updatedAt; + + Index({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.attributes, + this.orders, + required this.$createdAt, + required this.$updatedAt, + }); + + factory Index.fromMap(Map<String, dynamic> map) { + return Index( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + attributes: map['attributes'] ?? [], + orders: map['orders'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "attributes": attributes, + "orders": orders, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + }; + } } diff --git a/lib/src/models/index_list.dart b/lib/src/models/index_list.dart index 32bd33e0..4b9ec280 100644 --- a/lib/src/models/index_list.dart +++ b/lib/src/models/index_list.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Indexes List class IndexList implements Model { - /// Total number of indexes documents that matched your query. - final int total; - /// List of indexes. - final List<Index> indexes; + /// Total number of indexes documents that matched your query. + final int total; - IndexList({ - required this.total, - required this.indexes, - }); + /// List of indexes. + final List<Index> indexes; - factory IndexList.fromMap(Map<String, dynamic> map) { - return IndexList( - total: map['total'], - indexes: List<Index>.from(map['indexes'].map((p) => Index.fromMap(p))), - ); - } + IndexList({ + required this.total, + required this.indexes, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "indexes": indexes.map((p) => p.toMap()).toList(), - }; - } + factory IndexList.fromMap(Map<String, dynamic> map) { + return IndexList( + total: map['total'], + indexes: List<Index>.from(map['indexes'].map((p) => Index.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "indexes": indexes.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/jwt.dart b/lib/src/models/jwt.dart index 1b4ff7de..e2e31bd2 100644 --- a/lib/src/models/jwt.dart +++ b/lib/src/models/jwt.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// JWT class Jwt implements Model { - /// JWT encoded string. - final String jwt; + /// JWT encoded string. + final String jwt; - Jwt({ - required this.jwt, - }); + Jwt({ + required this.jwt, + }); - factory Jwt.fromMap(Map<String, dynamic> map) { - return Jwt( - jwt: map['jwt'].toString(), - ); - } + factory Jwt.fromMap(Map<String, dynamic> map) { + return Jwt( + jwt: map['jwt'].toString(), + ); + } - Map<String, dynamic> toMap() { - return { - "jwt": jwt, - }; - } + Map<String, dynamic> toMap() { + return { + "jwt": jwt, + }; + } } diff --git a/lib/src/models/language.dart b/lib/src/models/language.dart index 6d26c461..b6ec6121 100644 --- a/lib/src/models/language.dart +++ b/lib/src/models/language.dart @@ -2,32 +2,34 @@ part of '../../models.dart'; /// Language class Language implements Model { - /// Language name. - final String name; - /// Language two-character ISO 639-1 codes. - final String code; - /// Language native name. - final String nativeName; + /// Language name. + final String name; - Language({ - required this.name, - required this.code, - required this.nativeName, - }); + /// Language two-character ISO 639-1 codes. + final String code; - factory Language.fromMap(Map<String, dynamic> map) { - return Language( - name: map['name'].toString(), - code: map['code'].toString(), - nativeName: map['nativeName'].toString(), - ); - } + /// Language native name. + final String nativeName; - Map<String, dynamic> toMap() { - return { - "name": name, - "code": code, - "nativeName": nativeName, - }; - } + Language({ + required this.name, + required this.code, + required this.nativeName, + }); + + factory Language.fromMap(Map<String, dynamic> map) { + return Language( + name: map['name'].toString(), + code: map['code'].toString(), + nativeName: map['nativeName'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "name": name, + "code": code, + "nativeName": nativeName, + }; + } } diff --git a/lib/src/models/language_list.dart b/lib/src/models/language_list.dart index c6977a0e..29f49481 100644 --- a/lib/src/models/language_list.dart +++ b/lib/src/models/language_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Languages List class LanguageList implements Model { - /// Total number of languages documents that matched your query. - final int total; - /// List of languages. - final List<Language> languages; + /// Total number of languages documents that matched your query. + final int total; - LanguageList({ - required this.total, - required this.languages, - }); + /// List of languages. + final List<Language> languages; - factory LanguageList.fromMap(Map<String, dynamic> map) { - return LanguageList( - total: map['total'], - languages: List<Language>.from(map['languages'].map((p) => Language.fromMap(p))), - ); - } + LanguageList({ + required this.total, + required this.languages, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "languages": languages.map((p) => p.toMap()).toList(), - }; - } + factory LanguageList.fromMap(Map<String, dynamic> map) { + return LanguageList( + total: map['total'], + languages: + List<Language>.from(map['languages'].map((p) => Language.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "languages": languages.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/locale.dart b/lib/src/models/locale.dart index 0f0fd7f2..084475bf 100644 --- a/lib/src/models/locale.dart +++ b/lib/src/models/locale.dart @@ -2,52 +2,58 @@ part of '../../models.dart'; /// Locale class Locale implements Model { - /// User IP address. - final String ip; - /// Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format - final String countryCode; - /// Country name. This field support localization. - final String country; - /// Continent code. A two character continent code "AF" for Africa, "AN" for Antarctica, "AS" for Asia, "EU" for Europe, "NA" for North America, "OC" for Oceania, and "SA" for South America. - final String continentCode; - /// Continent name. This field support localization. - final String continent; - /// True if country is part of the European Union. - final bool eu; - /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format - final String currency; - - Locale({ - required this.ip, - required this.countryCode, - required this.country, - required this.continentCode, - required this.continent, - required this.eu, - required this.currency, - }); - - factory Locale.fromMap(Map<String, dynamic> map) { - return Locale( - ip: map['ip'].toString(), - countryCode: map['countryCode'].toString(), - country: map['country'].toString(), - continentCode: map['continentCode'].toString(), - continent: map['continent'].toString(), - eu: map['eu'], - currency: map['currency'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "ip": ip, - "countryCode": countryCode, - "country": country, - "continentCode": continentCode, - "continent": continent, - "eu": eu, - "currency": currency, - }; - } + /// User IP address. + final String ip; + + /// Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format + final String countryCode; + + /// Country name. This field support localization. + final String country; + + /// Continent code. A two character continent code "AF" for Africa, "AN" for Antarctica, "AS" for Asia, "EU" for Europe, "NA" for North America, "OC" for Oceania, and "SA" for South America. + final String continentCode; + + /// Continent name. This field support localization. + final String continent; + + /// True if country is part of the European Union. + final bool eu; + + /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format + final String currency; + + Locale({ + required this.ip, + required this.countryCode, + required this.country, + required this.continentCode, + required this.continent, + required this.eu, + required this.currency, + }); + + factory Locale.fromMap(Map<String, dynamic> map) { + return Locale( + ip: map['ip'].toString(), + countryCode: map['countryCode'].toString(), + country: map['country'].toString(), + continentCode: map['continentCode'].toString(), + continent: map['continent'].toString(), + eu: map['eu'], + currency: map['currency'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "ip": ip, + "countryCode": countryCode, + "country": country, + "continentCode": continentCode, + "continent": continent, + "eu": eu, + "currency": currency, + }; + } } diff --git a/lib/src/models/locale_code.dart b/lib/src/models/locale_code.dart index eebce199..678e40c4 100644 --- a/lib/src/models/locale_code.dart +++ b/lib/src/models/locale_code.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// LocaleCode class LocaleCode implements Model { - /// Locale codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) - final String code; - /// Locale name - final String name; + /// Locale codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) + final String code; - LocaleCode({ - required this.code, - required this.name, - }); + /// Locale name + final String name; - factory LocaleCode.fromMap(Map<String, dynamic> map) { - return LocaleCode( - code: map['code'].toString(), - name: map['name'].toString(), - ); - } + LocaleCode({ + required this.code, + required this.name, + }); - Map<String, dynamic> toMap() { - return { - "code": code, - "name": name, - }; - } + factory LocaleCode.fromMap(Map<String, dynamic> map) { + return LocaleCode( + code: map['code'].toString(), + name: map['name'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "code": code, + "name": name, + }; + } } diff --git a/lib/src/models/locale_code_list.dart b/lib/src/models/locale_code_list.dart index 090b332d..c3f4e4be 100644 --- a/lib/src/models/locale_code_list.dart +++ b/lib/src/models/locale_code_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Locale codes list class LocaleCodeList implements Model { - /// Total number of localeCodes documents that matched your query. - final int total; - /// List of localeCodes. - final List<LocaleCode> localeCodes; + /// Total number of localeCodes documents that matched your query. + final int total; - LocaleCodeList({ - required this.total, - required this.localeCodes, - }); + /// List of localeCodes. + final List<LocaleCode> localeCodes; - factory LocaleCodeList.fromMap(Map<String, dynamic> map) { - return LocaleCodeList( - total: map['total'], - localeCodes: List<LocaleCode>.from(map['localeCodes'].map((p) => LocaleCode.fromMap(p))), - ); - } + LocaleCodeList({ + required this.total, + required this.localeCodes, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "localeCodes": localeCodes.map((p) => p.toMap()).toList(), - }; - } + factory LocaleCodeList.fromMap(Map<String, dynamic> map) { + return LocaleCodeList( + total: map['total'], + localeCodes: List<LocaleCode>.from( + map['localeCodes'].map((p) => LocaleCode.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "localeCodes": localeCodes.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/log.dart b/lib/src/models/log.dart index 41cda2ca..7fb3f364 100644 --- a/lib/src/models/log.dart +++ b/lib/src/models/log.dart @@ -2,122 +2,142 @@ part of '../../models.dart'; /// Log class Log implements Model { - /// Event name. - final String event; - /// User ID. - final String userId; - /// User Email. - final String userEmail; - /// User Name. - final String userName; - /// API mode when event triggered. - final String mode; - /// IP session in use when the session was created. - final String ip; - /// Log creation date in ISO 8601 format. - final String time; - /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). - final String osCode; - /// Operating system name. - final String osName; - /// Operating system version. - final String osVersion; - /// Client type. - final String clientType; - /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). - final String clientCode; - /// Client name. - final String clientName; - /// Client version. - final String clientVersion; - /// Client engine name. - final String clientEngine; - /// Client engine name. - final String clientEngineVersion; - /// Device name. - final String deviceName; - /// Device brand name. - final String deviceBrand; - /// Device model name. - final String deviceModel; - /// Country two-character ISO 3166-1 alpha code. - final String countryCode; - /// Country name. - final String countryName; - - Log({ - required this.event, - required this.userId, - required this.userEmail, - required this.userName, - required this.mode, - required this.ip, - required this.time, - required this.osCode, - required this.osName, - required this.osVersion, - required this.clientType, - required this.clientCode, - required this.clientName, - required this.clientVersion, - required this.clientEngine, - required this.clientEngineVersion, - required this.deviceName, - required this.deviceBrand, - required this.deviceModel, - required this.countryCode, - required this.countryName, - }); - - factory Log.fromMap(Map<String, dynamic> map) { - return Log( - event: map['event'].toString(), - userId: map['userId'].toString(), - userEmail: map['userEmail'].toString(), - userName: map['userName'].toString(), - mode: map['mode'].toString(), - ip: map['ip'].toString(), - time: map['time'].toString(), - osCode: map['osCode'].toString(), - osName: map['osName'].toString(), - osVersion: map['osVersion'].toString(), - clientType: map['clientType'].toString(), - clientCode: map['clientCode'].toString(), - clientName: map['clientName'].toString(), - clientVersion: map['clientVersion'].toString(), - clientEngine: map['clientEngine'].toString(), - clientEngineVersion: map['clientEngineVersion'].toString(), - deviceName: map['deviceName'].toString(), - deviceBrand: map['deviceBrand'].toString(), - deviceModel: map['deviceModel'].toString(), - countryCode: map['countryCode'].toString(), - countryName: map['countryName'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "event": event, - "userId": userId, - "userEmail": userEmail, - "userName": userName, - "mode": mode, - "ip": ip, - "time": time, - "osCode": osCode, - "osName": osName, - "osVersion": osVersion, - "clientType": clientType, - "clientCode": clientCode, - "clientName": clientName, - "clientVersion": clientVersion, - "clientEngine": clientEngine, - "clientEngineVersion": clientEngineVersion, - "deviceName": deviceName, - "deviceBrand": deviceBrand, - "deviceModel": deviceModel, - "countryCode": countryCode, - "countryName": countryName, - }; - } + /// Event name. + final String event; + + /// User ID. + final String userId; + + /// User Email. + final String userEmail; + + /// User Name. + final String userName; + + /// API mode when event triggered. + final String mode; + + /// IP session in use when the session was created. + final String ip; + + /// Log creation date in ISO 8601 format. + final String time; + + /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). + final String osCode; + + /// Operating system name. + final String osName; + + /// Operating system version. + final String osVersion; + + /// Client type. + final String clientType; + + /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). + final String clientCode; + + /// Client name. + final String clientName; + + /// Client version. + final String clientVersion; + + /// Client engine name. + final String clientEngine; + + /// Client engine name. + final String clientEngineVersion; + + /// Device name. + final String deviceName; + + /// Device brand name. + final String deviceBrand; + + /// Device model name. + final String deviceModel; + + /// Country two-character ISO 3166-1 alpha code. + final String countryCode; + + /// Country name. + final String countryName; + + Log({ + required this.event, + required this.userId, + required this.userEmail, + required this.userName, + required this.mode, + required this.ip, + required this.time, + required this.osCode, + required this.osName, + required this.osVersion, + required this.clientType, + required this.clientCode, + required this.clientName, + required this.clientVersion, + required this.clientEngine, + required this.clientEngineVersion, + required this.deviceName, + required this.deviceBrand, + required this.deviceModel, + required this.countryCode, + required this.countryName, + }); + + factory Log.fromMap(Map<String, dynamic> map) { + return Log( + event: map['event'].toString(), + userId: map['userId'].toString(), + userEmail: map['userEmail'].toString(), + userName: map['userName'].toString(), + mode: map['mode'].toString(), + ip: map['ip'].toString(), + time: map['time'].toString(), + osCode: map['osCode'].toString(), + osName: map['osName'].toString(), + osVersion: map['osVersion'].toString(), + clientType: map['clientType'].toString(), + clientCode: map['clientCode'].toString(), + clientName: map['clientName'].toString(), + clientVersion: map['clientVersion'].toString(), + clientEngine: map['clientEngine'].toString(), + clientEngineVersion: map['clientEngineVersion'].toString(), + deviceName: map['deviceName'].toString(), + deviceBrand: map['deviceBrand'].toString(), + deviceModel: map['deviceModel'].toString(), + countryCode: map['countryCode'].toString(), + countryName: map['countryName'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "event": event, + "userId": userId, + "userEmail": userEmail, + "userName": userName, + "mode": mode, + "ip": ip, + "time": time, + "osCode": osCode, + "osName": osName, + "osVersion": osVersion, + "clientType": clientType, + "clientCode": clientCode, + "clientName": clientName, + "clientVersion": clientVersion, + "clientEngine": clientEngine, + "clientEngineVersion": clientEngineVersion, + "deviceName": deviceName, + "deviceBrand": deviceBrand, + "deviceModel": deviceModel, + "countryCode": countryCode, + "countryName": countryName, + }; + } } diff --git a/lib/src/models/log_list.dart b/lib/src/models/log_list.dart index 9af5b1cd..a686897c 100644 --- a/lib/src/models/log_list.dart +++ b/lib/src/models/log_list.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Logs List class LogList implements Model { - /// Total number of logs documents that matched your query. - final int total; - /// List of logs. - final List<Log> logs; + /// Total number of logs documents that matched your query. + final int total; - LogList({ - required this.total, - required this.logs, - }); + /// List of logs. + final List<Log> logs; - factory LogList.fromMap(Map<String, dynamic> map) { - return LogList( - total: map['total'], - logs: List<Log>.from(map['logs'].map((p) => Log.fromMap(p))), - ); - } + LogList({ + required this.total, + required this.logs, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "logs": logs.map((p) => p.toMap()).toList(), - }; - } + factory LogList.fromMap(Map<String, dynamic> map) { + return LogList( + total: map['total'], + logs: List<Log>.from(map['logs'].map((p) => Log.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "logs": logs.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/membership.dart b/lib/src/models/membership.dart index 62c5b64b..1dd1186d 100644 --- a/lib/src/models/membership.dart +++ b/lib/src/models/membership.dart @@ -2,82 +2,94 @@ part of '../../models.dart'; /// Membership class Membership implements Model { - /// Membership ID. - final String $id; - /// Membership creation date in ISO 8601 format. - final String $createdAt; - /// Membership update date in ISO 8601 format. - final String $updatedAt; - /// User ID. - final String userId; - /// User name. Hide this attribute by toggling membership privacy in the Console. - final String userName; - /// User email address. Hide this attribute by toggling membership privacy in the Console. - final String userEmail; - /// Team ID. - final String teamId; - /// Team name. - final String teamName; - /// Date, the user has been invited to join the team in ISO 8601 format. - final String invited; - /// Date, the user has accepted the invitation to join the team in ISO 8601 format. - final String joined; - /// User confirmation status, true if the user has joined the team or false otherwise. - final bool confirm; - /// Multi factor authentication status, true if the user has MFA enabled or false otherwise. Hide this attribute by toggling membership privacy in the Console. - final bool mfa; - /// User list of roles - final List<String> roles; - - Membership({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.userId, - required this.userName, - required this.userEmail, - required this.teamId, - required this.teamName, - required this.invited, - required this.joined, - required this.confirm, - required this.mfa, - required this.roles, - }); - - factory Membership.fromMap(Map<String, dynamic> map) { - return Membership( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - userId: map['userId'].toString(), - userName: map['userName'].toString(), - userEmail: map['userEmail'].toString(), - teamId: map['teamId'].toString(), - teamName: map['teamName'].toString(), - invited: map['invited'].toString(), - joined: map['joined'].toString(), - confirm: map['confirm'], - mfa: map['mfa'], - roles: map['roles'] ?? [], - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "userId": userId, - "userName": userName, - "userEmail": userEmail, - "teamId": teamId, - "teamName": teamName, - "invited": invited, - "joined": joined, - "confirm": confirm, - "mfa": mfa, - "roles": roles, - }; - } + /// Membership ID. + final String $id; + + /// Membership creation date in ISO 8601 format. + final String $createdAt; + + /// Membership update date in ISO 8601 format. + final String $updatedAt; + + /// User ID. + final String userId; + + /// User name. Hide this attribute by toggling membership privacy in the Console. + final String userName; + + /// User email address. Hide this attribute by toggling membership privacy in the Console. + final String userEmail; + + /// Team ID. + final String teamId; + + /// Team name. + final String teamName; + + /// Date, the user has been invited to join the team in ISO 8601 format. + final String invited; + + /// Date, the user has accepted the invitation to join the team in ISO 8601 format. + final String joined; + + /// User confirmation status, true if the user has joined the team or false otherwise. + final bool confirm; + + /// Multi factor authentication status, true if the user has MFA enabled or false otherwise. Hide this attribute by toggling membership privacy in the Console. + final bool mfa; + + /// User list of roles + final List<String> roles; + + Membership({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.userId, + required this.userName, + required this.userEmail, + required this.teamId, + required this.teamName, + required this.invited, + required this.joined, + required this.confirm, + required this.mfa, + required this.roles, + }); + + factory Membership.fromMap(Map<String, dynamic> map) { + return Membership( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + userId: map['userId'].toString(), + userName: map['userName'].toString(), + userEmail: map['userEmail'].toString(), + teamId: map['teamId'].toString(), + teamName: map['teamName'].toString(), + invited: map['invited'].toString(), + joined: map['joined'].toString(), + confirm: map['confirm'], + mfa: map['mfa'], + roles: map['roles'] ?? [], + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "userId": userId, + "userName": userName, + "userEmail": userEmail, + "teamId": teamId, + "teamName": teamName, + "invited": invited, + "joined": joined, + "confirm": confirm, + "mfa": mfa, + "roles": roles, + }; + } } diff --git a/lib/src/models/membership_list.dart b/lib/src/models/membership_list.dart index 1da7cd60..ee65133b 100644 --- a/lib/src/models/membership_list.dart +++ b/lib/src/models/membership_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Memberships List class MembershipList implements Model { - /// Total number of memberships documents that matched your query. - final int total; - /// List of memberships. - final List<Membership> memberships; + /// Total number of memberships documents that matched your query. + final int total; - MembershipList({ - required this.total, - required this.memberships, - }); + /// List of memberships. + final List<Membership> memberships; - factory MembershipList.fromMap(Map<String, dynamic> map) { - return MembershipList( - total: map['total'], - memberships: List<Membership>.from(map['memberships'].map((p) => Membership.fromMap(p))), - ); - } + MembershipList({ + required this.total, + required this.memberships, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "memberships": memberships.map((p) => p.toMap()).toList(), - }; - } + factory MembershipList.fromMap(Map<String, dynamic> map) { + return MembershipList( + total: map['total'], + memberships: List<Membership>.from( + map['memberships'].map((p) => Membership.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "memberships": memberships.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/message.dart b/lib/src/models/message.dart index fcf1cba4..9664cebb 100644 --- a/lib/src/models/message.dart +++ b/lib/src/models/message.dart @@ -2,82 +2,94 @@ part of '../../models.dart'; /// Message class Message implements Model { - /// Message ID. - final String $id; - /// Message creation time in ISO 8601 format. - final String $createdAt; - /// Message update date in ISO 8601 format. - final String $updatedAt; - /// Message provider type. - final String providerType; - /// Topic IDs set as recipients. - final List<String> topics; - /// User IDs set as recipients. - final List<String> users; - /// Target IDs set as recipients. - final List<String> targets; - /// The scheduled time for message. - final String? scheduledAt; - /// The time when the message was delivered. - final String? deliveredAt; - /// Delivery errors if any. - final List<String>? deliveryErrors; - /// Number of recipients the message was delivered to. - final int deliveredTotal; - /// Data of the message. - final Map<String, dynamic> data; - /// Status of delivery. - final String status; - - Message({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.providerType, - required this.topics, - required this.users, - required this.targets, - this.scheduledAt, - this.deliveredAt, - this.deliveryErrors, - required this.deliveredTotal, - required this.data, - required this.status, - }); - - factory Message.fromMap(Map<String, dynamic> map) { - return Message( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - providerType: map['providerType'].toString(), - topics: map['topics'] ?? [], - users: map['users'] ?? [], - targets: map['targets'] ?? [], - scheduledAt: map['scheduledAt']?.toString(), - deliveredAt: map['deliveredAt']?.toString(), - deliveryErrors: map['deliveryErrors'], - deliveredTotal: map['deliveredTotal'], - data: map['data'], - status: map['status'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "providerType": providerType, - "topics": topics, - "users": users, - "targets": targets, - "scheduledAt": scheduledAt, - "deliveredAt": deliveredAt, - "deliveryErrors": deliveryErrors, - "deliveredTotal": deliveredTotal, - "data": data, - "status": status, - }; - } + /// Message ID. + final String $id; + + /// Message creation time in ISO 8601 format. + final String $createdAt; + + /// Message update date in ISO 8601 format. + final String $updatedAt; + + /// Message provider type. + final String providerType; + + /// Topic IDs set as recipients. + final List<String> topics; + + /// User IDs set as recipients. + final List<String> users; + + /// Target IDs set as recipients. + final List<String> targets; + + /// The scheduled time for message. + final String? scheduledAt; + + /// The time when the message was delivered. + final String? deliveredAt; + + /// Delivery errors if any. + final List<String>? deliveryErrors; + + /// Number of recipients the message was delivered to. + final int deliveredTotal; + + /// Data of the message. + final Map<String, dynamic> data; + + /// Status of delivery. + final String status; + + Message({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.providerType, + required this.topics, + required this.users, + required this.targets, + this.scheduledAt, + this.deliveredAt, + this.deliveryErrors, + required this.deliveredTotal, + required this.data, + required this.status, + }); + + factory Message.fromMap(Map<String, dynamic> map) { + return Message( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + providerType: map['providerType'].toString(), + topics: map['topics'] ?? [], + users: map['users'] ?? [], + targets: map['targets'] ?? [], + scheduledAt: map['scheduledAt']?.toString(), + deliveredAt: map['deliveredAt']?.toString(), + deliveryErrors: map['deliveryErrors'], + deliveredTotal: map['deliveredTotal'], + data: map['data'], + status: map['status'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "providerType": providerType, + "topics": topics, + "users": users, + "targets": targets, + "scheduledAt": scheduledAt, + "deliveredAt": deliveredAt, + "deliveryErrors": deliveryErrors, + "deliveredTotal": deliveredTotal, + "data": data, + "status": status, + }; + } } diff --git a/lib/src/models/message_list.dart b/lib/src/models/message_list.dart index 79389744..4960c39d 100644 --- a/lib/src/models/message_list.dart +++ b/lib/src/models/message_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Message list class MessageList implements Model { - /// Total number of messages documents that matched your query. - final int total; - /// List of messages. - final List<Message> messages; + /// Total number of messages documents that matched your query. + final int total; - MessageList({ - required this.total, - required this.messages, - }); + /// List of messages. + final List<Message> messages; - factory MessageList.fromMap(Map<String, dynamic> map) { - return MessageList( - total: map['total'], - messages: List<Message>.from(map['messages'].map((p) => Message.fromMap(p))), - ); - } + MessageList({ + required this.total, + required this.messages, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "messages": messages.map((p) => p.toMap()).toList(), - }; - } + factory MessageList.fromMap(Map<String, dynamic> map) { + return MessageList( + total: map['total'], + messages: + List<Message>.from(map['messages'].map((p) => Message.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "messages": messages.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/mfa_challenge.dart b/lib/src/models/mfa_challenge.dart index 043ff286..96bf3c65 100644 --- a/lib/src/models/mfa_challenge.dart +++ b/lib/src/models/mfa_challenge.dart @@ -2,37 +2,40 @@ part of '../../models.dart'; /// MFA Challenge class MfaChallenge implements Model { - /// Token ID. - final String $id; - /// Token creation date in ISO 8601 format. - final String $createdAt; - /// User ID. - final String userId; - /// Token expiration date in ISO 8601 format. - final String expire; + /// Token ID. + final String $id; - MfaChallenge({ - required this.$id, - required this.$createdAt, - required this.userId, - required this.expire, - }); + /// Token creation date in ISO 8601 format. + final String $createdAt; - factory MfaChallenge.fromMap(Map<String, dynamic> map) { - return MfaChallenge( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - userId: map['userId'].toString(), - expire: map['expire'].toString(), - ); - } + /// User ID. + final String userId; - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "userId": userId, - "expire": expire, - }; - } + /// Token expiration date in ISO 8601 format. + final String expire; + + MfaChallenge({ + required this.$id, + required this.$createdAt, + required this.userId, + required this.expire, + }); + + factory MfaChallenge.fromMap(Map<String, dynamic> map) { + return MfaChallenge( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + userId: map['userId'].toString(), + expire: map['expire'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "userId": userId, + "expire": expire, + }; + } } diff --git a/lib/src/models/mfa_factors.dart b/lib/src/models/mfa_factors.dart index f453e870..c930a23e 100644 --- a/lib/src/models/mfa_factors.dart +++ b/lib/src/models/mfa_factors.dart @@ -2,37 +2,40 @@ part of '../../models.dart'; /// MFAFactors class MfaFactors implements Model { - /// Can TOTP be used for MFA challenge for this account. - final bool totp; - /// Can phone (SMS) be used for MFA challenge for this account. - final bool phone; - /// Can email be used for MFA challenge for this account. - final bool email; - /// Can recovery code be used for MFA challenge for this account. - final bool recoveryCode; + /// Can TOTP be used for MFA challenge for this account. + final bool totp; - MfaFactors({ - required this.totp, - required this.phone, - required this.email, - required this.recoveryCode, - }); + /// Can phone (SMS) be used for MFA challenge for this account. + final bool phone; - factory MfaFactors.fromMap(Map<String, dynamic> map) { - return MfaFactors( - totp: map['totp'], - phone: map['phone'], - email: map['email'], - recoveryCode: map['recoveryCode'], - ); - } + /// Can email be used for MFA challenge for this account. + final bool email; - Map<String, dynamic> toMap() { - return { - "totp": totp, - "phone": phone, - "email": email, - "recoveryCode": recoveryCode, - }; - } + /// Can recovery code be used for MFA challenge for this account. + final bool recoveryCode; + + MfaFactors({ + required this.totp, + required this.phone, + required this.email, + required this.recoveryCode, + }); + + factory MfaFactors.fromMap(Map<String, dynamic> map) { + return MfaFactors( + totp: map['totp'], + phone: map['phone'], + email: map['email'], + recoveryCode: map['recoveryCode'], + ); + } + + Map<String, dynamic> toMap() { + return { + "totp": totp, + "phone": phone, + "email": email, + "recoveryCode": recoveryCode, + }; + } } diff --git a/lib/src/models/mfa_recovery_codes.dart b/lib/src/models/mfa_recovery_codes.dart index cd835186..c304de00 100644 --- a/lib/src/models/mfa_recovery_codes.dart +++ b/lib/src/models/mfa_recovery_codes.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// MFA Recovery Codes class MfaRecoveryCodes implements Model { - /// Recovery codes. - final List<String> recoveryCodes; + /// Recovery codes. + final List<String> recoveryCodes; - MfaRecoveryCodes({ - required this.recoveryCodes, - }); + MfaRecoveryCodes({ + required this.recoveryCodes, + }); - factory MfaRecoveryCodes.fromMap(Map<String, dynamic> map) { - return MfaRecoveryCodes( - recoveryCodes: map['recoveryCodes'] ?? [], - ); - } + factory MfaRecoveryCodes.fromMap(Map<String, dynamic> map) { + return MfaRecoveryCodes( + recoveryCodes: map['recoveryCodes'] ?? [], + ); + } - Map<String, dynamic> toMap() { - return { - "recoveryCodes": recoveryCodes, - }; - } + Map<String, dynamic> toMap() { + return { + "recoveryCodes": recoveryCodes, + }; + } } diff --git a/lib/src/models/mfa_type.dart b/lib/src/models/mfa_type.dart index 87064007..0573166e 100644 --- a/lib/src/models/mfa_type.dart +++ b/lib/src/models/mfa_type.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// MFAType class MfaType implements Model { - /// Secret token used for TOTP factor. - final String secret; - /// URI for authenticator apps. - final String uri; + /// Secret token used for TOTP factor. + final String secret; - MfaType({ - required this.secret, - required this.uri, - }); + /// URI for authenticator apps. + final String uri; - factory MfaType.fromMap(Map<String, dynamic> map) { - return MfaType( - secret: map['secret'].toString(), - uri: map['uri'].toString(), - ); - } + MfaType({ + required this.secret, + required this.uri, + }); - Map<String, dynamic> toMap() { - return { - "secret": secret, - "uri": uri, - }; - } + factory MfaType.fromMap(Map<String, dynamic> map) { + return MfaType( + secret: map['secret'].toString(), + uri: map['uri'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "secret": secret, + "uri": uri, + }; + } } diff --git a/lib/src/models/model.dart b/lib/src/models/model.dart index 48e5b84a..f810a35b 100644 --- a/lib/src/models/model.dart +++ b/lib/src/models/model.dart @@ -2,4 +2,4 @@ part of '../../models.dart'; abstract class Model { Map<String, dynamic> toMap(); -} \ No newline at end of file +} diff --git a/lib/src/models/phone.dart b/lib/src/models/phone.dart index 24f7260d..40f7bcd2 100644 --- a/lib/src/models/phone.dart +++ b/lib/src/models/phone.dart @@ -2,32 +2,34 @@ part of '../../models.dart'; /// Phone class Phone implements Model { - /// Phone code. - final String code; - /// Country two-character ISO 3166-1 alpha code. - final String countryCode; - /// Country name. - final String countryName; + /// Phone code. + final String code; - Phone({ - required this.code, - required this.countryCode, - required this.countryName, - }); + /// Country two-character ISO 3166-1 alpha code. + final String countryCode; - factory Phone.fromMap(Map<String, dynamic> map) { - return Phone( - code: map['code'].toString(), - countryCode: map['countryCode'].toString(), - countryName: map['countryName'].toString(), - ); - } + /// Country name. + final String countryName; - Map<String, dynamic> toMap() { - return { - "code": code, - "countryCode": countryCode, - "countryName": countryName, - }; - } + Phone({ + required this.code, + required this.countryCode, + required this.countryName, + }); + + factory Phone.fromMap(Map<String, dynamic> map) { + return Phone( + code: map['code'].toString(), + countryCode: map['countryCode'].toString(), + countryName: map['countryName'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "code": code, + "countryCode": countryCode, + "countryName": countryName, + }; + } } diff --git a/lib/src/models/phone_list.dart b/lib/src/models/phone_list.dart index 55e6108e..1ae5a351 100644 --- a/lib/src/models/phone_list.dart +++ b/lib/src/models/phone_list.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Phones List class PhoneList implements Model { - /// Total number of phones documents that matched your query. - final int total; - /// List of phones. - final List<Phone> phones; + /// Total number of phones documents that matched your query. + final int total; - PhoneList({ - required this.total, - required this.phones, - }); + /// List of phones. + final List<Phone> phones; - factory PhoneList.fromMap(Map<String, dynamic> map) { - return PhoneList( - total: map['total'], - phones: List<Phone>.from(map['phones'].map((p) => Phone.fromMap(p))), - ); - } + PhoneList({ + required this.total, + required this.phones, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "phones": phones.map((p) => p.toMap()).toList(), - }; - } + factory PhoneList.fromMap(Map<String, dynamic> map) { + return PhoneList( + total: map['total'], + phones: List<Phone>.from(map['phones'].map((p) => Phone.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "phones": phones.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/preferences.dart b/lib/src/models/preferences.dart index 3c62f86d..3549cff0 100644 --- a/lib/src/models/preferences.dart +++ b/lib/src/models/preferences.dart @@ -2,23 +2,23 @@ part of '../../models.dart'; /// Preferences class Preferences implements Model { - final Map<String, dynamic> data; + final Map<String, dynamic> data; - Preferences({ - required this.data, - }); + Preferences({ + required this.data, + }); - factory Preferences.fromMap(Map<String, dynamic> map) { - return Preferences( - data: map, - ); - } + factory Preferences.fromMap(Map<String, dynamic> map) { + return Preferences( + data: map, + ); + } - Map<String, dynamic> toMap() { - return { - "data": data, - }; - } + Map<String, dynamic> toMap() { + return { + "data": data, + }; + } - T convertTo<T>(T Function(Map) fromJson) => fromJson(data); + T convertTo<T>(T Function(Map) fromJson) => fromJson(data); } diff --git a/lib/src/models/provider.dart b/lib/src/models/provider.dart index ba0855de..1a762f85 100644 --- a/lib/src/models/provider.dart +++ b/lib/src/models/provider.dart @@ -2,62 +2,70 @@ part of '../../models.dart'; /// Provider class Provider implements Model { - /// Provider ID. - final String $id; - /// Provider creation time in ISO 8601 format. - final String $createdAt; - /// Provider update date in ISO 8601 format. - final String $updatedAt; - /// The name for the provider instance. - final String name; - /// The name of the provider service. - final String provider; - /// Is provider enabled? - final bool enabled; - /// Type of provider. - final String type; - /// Provider credentials. - final Map<String, dynamic> credentials; - /// Provider options. - final Map<String, dynamic>? options; - - Provider({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.provider, - required this.enabled, - required this.type, - required this.credentials, - this.options, - }); - - factory Provider.fromMap(Map<String, dynamic> map) { - return Provider( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - provider: map['provider'].toString(), - enabled: map['enabled'], - type: map['type'].toString(), - credentials: map['credentials'], - options: map['options'], - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "provider": provider, - "enabled": enabled, - "type": type, - "credentials": credentials, - "options": options, - }; - } + /// Provider ID. + final String $id; + + /// Provider creation time in ISO 8601 format. + final String $createdAt; + + /// Provider update date in ISO 8601 format. + final String $updatedAt; + + /// The name for the provider instance. + final String name; + + /// The name of the provider service. + final String provider; + + /// Is provider enabled? + final bool enabled; + + /// Type of provider. + final String type; + + /// Provider credentials. + final Map<String, dynamic> credentials; + + /// Provider options. + final Map<String, dynamic>? options; + + Provider({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.provider, + required this.enabled, + required this.type, + required this.credentials, + this.options, + }); + + factory Provider.fromMap(Map<String, dynamic> map) { + return Provider( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + provider: map['provider'].toString(), + enabled: map['enabled'], + type: map['type'].toString(), + credentials: map['credentials'], + options: map['options'], + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "provider": provider, + "enabled": enabled, + "type": type, + "credentials": credentials, + "options": options, + }; + } } diff --git a/lib/src/models/provider_list.dart b/lib/src/models/provider_list.dart index 228578b7..a4f980f6 100644 --- a/lib/src/models/provider_list.dart +++ b/lib/src/models/provider_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Provider list class ProviderList implements Model { - /// Total number of providers documents that matched your query. - final int total; - /// List of providers. - final List<Provider> providers; + /// Total number of providers documents that matched your query. + final int total; - ProviderList({ - required this.total, - required this.providers, - }); + /// List of providers. + final List<Provider> providers; - factory ProviderList.fromMap(Map<String, dynamic> map) { - return ProviderList( - total: map['total'], - providers: List<Provider>.from(map['providers'].map((p) => Provider.fromMap(p))), - ); - } + ProviderList({ + required this.total, + required this.providers, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "providers": providers.map((p) => p.toMap()).toList(), - }; - } + factory ProviderList.fromMap(Map<String, dynamic> map) { + return ProviderList( + total: map['total'], + providers: + List<Provider>.from(map['providers'].map((p) => Provider.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "providers": providers.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/runtime.dart b/lib/src/models/runtime.dart index 75f2ccca..249690f8 100644 --- a/lib/src/models/runtime.dart +++ b/lib/src/models/runtime.dart @@ -2,57 +2,64 @@ part of '../../models.dart'; /// Runtime class Runtime implements Model { - /// Runtime ID. - final String $id; - /// Parent runtime key. - final String key; - /// Runtime Name. - final String name; - /// Runtime version. - final String version; - /// Base Docker image used to build the runtime. - final String base; - /// Image name of Docker Hub. - final String image; - /// Name of the logo image. - final String logo; - /// List of supported architectures. - final List<String> supports; - - Runtime({ - required this.$id, - required this.key, - required this.name, - required this.version, - required this.base, - required this.image, - required this.logo, - required this.supports, - }); - - factory Runtime.fromMap(Map<String, dynamic> map) { - return Runtime( - $id: map['\$id'].toString(), - key: map['key'].toString(), - name: map['name'].toString(), - version: map['version'].toString(), - base: map['base'].toString(), - image: map['image'].toString(), - logo: map['logo'].toString(), - supports: map['supports'] ?? [], - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "key": key, - "name": name, - "version": version, - "base": base, - "image": image, - "logo": logo, - "supports": supports, - }; - } + /// Runtime ID. + final String $id; + + /// Parent runtime key. + final String key; + + /// Runtime Name. + final String name; + + /// Runtime version. + final String version; + + /// Base Docker image used to build the runtime. + final String base; + + /// Image name of Docker Hub. + final String image; + + /// Name of the logo image. + final String logo; + + /// List of supported architectures. + final List<String> supports; + + Runtime({ + required this.$id, + required this.key, + required this.name, + required this.version, + required this.base, + required this.image, + required this.logo, + required this.supports, + }); + + factory Runtime.fromMap(Map<String, dynamic> map) { + return Runtime( + $id: map['\$id'].toString(), + key: map['key'].toString(), + name: map['name'].toString(), + version: map['version'].toString(), + base: map['base'].toString(), + image: map['image'].toString(), + logo: map['logo'].toString(), + supports: map['supports'] ?? [], + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "key": key, + "name": name, + "version": version, + "base": base, + "image": image, + "logo": logo, + "supports": supports, + }; + } } diff --git a/lib/src/models/runtime_list.dart b/lib/src/models/runtime_list.dart index 4d7e33ce..7845cd8b 100644 --- a/lib/src/models/runtime_list.dart +++ b/lib/src/models/runtime_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Runtimes List class RuntimeList implements Model { - /// Total number of runtimes documents that matched your query. - final int total; - /// List of runtimes. - final List<Runtime> runtimes; + /// Total number of runtimes documents that matched your query. + final int total; - RuntimeList({ - required this.total, - required this.runtimes, - }); + /// List of runtimes. + final List<Runtime> runtimes; - factory RuntimeList.fromMap(Map<String, dynamic> map) { - return RuntimeList( - total: map['total'], - runtimes: List<Runtime>.from(map['runtimes'].map((p) => Runtime.fromMap(p))), - ); - } + RuntimeList({ + required this.total, + required this.runtimes, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "runtimes": runtimes.map((p) => p.toMap()).toList(), - }; - } + factory RuntimeList.fromMap(Map<String, dynamic> map) { + return RuntimeList( + total: map['total'], + runtimes: + List<Runtime>.from(map['runtimes'].map((p) => Runtime.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "runtimes": runtimes.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/session.dart b/lib/src/models/session.dart index b67bf22f..11732bd1 100644 --- a/lib/src/models/session.dart +++ b/lib/src/models/session.dart @@ -2,162 +2,190 @@ part of '../../models.dart'; /// Session class Session implements Model { - /// Session ID. - final String $id; - /// Session creation date in ISO 8601 format. - final String $createdAt; - /// Session update date in ISO 8601 format. - final String $updatedAt; - /// User ID. - final String userId; - /// Session expiration date in ISO 8601 format. - final String expire; - /// Session Provider. - final String provider; - /// Session Provider User ID. - final String providerUid; - /// Session Provider Access Token. - final String providerAccessToken; - /// The date of when the access token expires in ISO 8601 format. - final String providerAccessTokenExpiry; - /// Session Provider Refresh Token. - final String providerRefreshToken; - /// IP in use when the session was created. - final String ip; - /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). - final String osCode; - /// Operating system name. - final String osName; - /// Operating system version. - final String osVersion; - /// Client type. - final String clientType; - /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). - final String clientCode; - /// Client name. - final String clientName; - /// Client version. - final String clientVersion; - /// Client engine name. - final String clientEngine; - /// Client engine name. - final String clientEngineVersion; - /// Device name. - final String deviceName; - /// Device brand name. - final String deviceBrand; - /// Device model name. - final String deviceModel; - /// Country two-character ISO 3166-1 alpha code. - final String countryCode; - /// Country name. - final String countryName; - /// Returns true if this the current user session. - final bool current; - /// Returns a list of active session factors. - final List<String> factors; - /// Secret used to authenticate the user. Only included if the request was made with an API key - final String secret; - /// Most recent date in ISO 8601 format when the session successfully passed MFA challenge. - final String mfaUpdatedAt; - - Session({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.userId, - required this.expire, - required this.provider, - required this.providerUid, - required this.providerAccessToken, - required this.providerAccessTokenExpiry, - required this.providerRefreshToken, - required this.ip, - required this.osCode, - required this.osName, - required this.osVersion, - required this.clientType, - required this.clientCode, - required this.clientName, - required this.clientVersion, - required this.clientEngine, - required this.clientEngineVersion, - required this.deviceName, - required this.deviceBrand, - required this.deviceModel, - required this.countryCode, - required this.countryName, - required this.current, - required this.factors, - required this.secret, - required this.mfaUpdatedAt, - }); - - factory Session.fromMap(Map<String, dynamic> map) { - return Session( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - userId: map['userId'].toString(), - expire: map['expire'].toString(), - provider: map['provider'].toString(), - providerUid: map['providerUid'].toString(), - providerAccessToken: map['providerAccessToken'].toString(), - providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), - providerRefreshToken: map['providerRefreshToken'].toString(), - ip: map['ip'].toString(), - osCode: map['osCode'].toString(), - osName: map['osName'].toString(), - osVersion: map['osVersion'].toString(), - clientType: map['clientType'].toString(), - clientCode: map['clientCode'].toString(), - clientName: map['clientName'].toString(), - clientVersion: map['clientVersion'].toString(), - clientEngine: map['clientEngine'].toString(), - clientEngineVersion: map['clientEngineVersion'].toString(), - deviceName: map['deviceName'].toString(), - deviceBrand: map['deviceBrand'].toString(), - deviceModel: map['deviceModel'].toString(), - countryCode: map['countryCode'].toString(), - countryName: map['countryName'].toString(), - current: map['current'], - factors: map['factors'] ?? [], - secret: map['secret'].toString(), - mfaUpdatedAt: map['mfaUpdatedAt'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "userId": userId, - "expire": expire, - "provider": provider, - "providerUid": providerUid, - "providerAccessToken": providerAccessToken, - "providerAccessTokenExpiry": providerAccessTokenExpiry, - "providerRefreshToken": providerRefreshToken, - "ip": ip, - "osCode": osCode, - "osName": osName, - "osVersion": osVersion, - "clientType": clientType, - "clientCode": clientCode, - "clientName": clientName, - "clientVersion": clientVersion, - "clientEngine": clientEngine, - "clientEngineVersion": clientEngineVersion, - "deviceName": deviceName, - "deviceBrand": deviceBrand, - "deviceModel": deviceModel, - "countryCode": countryCode, - "countryName": countryName, - "current": current, - "factors": factors, - "secret": secret, - "mfaUpdatedAt": mfaUpdatedAt, - }; - } + /// Session ID. + final String $id; + + /// Session creation date in ISO 8601 format. + final String $createdAt; + + /// Session update date in ISO 8601 format. + final String $updatedAt; + + /// User ID. + final String userId; + + /// Session expiration date in ISO 8601 format. + final String expire; + + /// Session Provider. + final String provider; + + /// Session Provider User ID. + final String providerUid; + + /// Session Provider Access Token. + final String providerAccessToken; + + /// The date of when the access token expires in ISO 8601 format. + final String providerAccessTokenExpiry; + + /// Session Provider Refresh Token. + final String providerRefreshToken; + + /// IP in use when the session was created. + final String ip; + + /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). + final String osCode; + + /// Operating system name. + final String osName; + + /// Operating system version. + final String osVersion; + + /// Client type. + final String clientType; + + /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). + final String clientCode; + + /// Client name. + final String clientName; + + /// Client version. + final String clientVersion; + + /// Client engine name. + final String clientEngine; + + /// Client engine name. + final String clientEngineVersion; + + /// Device name. + final String deviceName; + + /// Device brand name. + final String deviceBrand; + + /// Device model name. + final String deviceModel; + + /// Country two-character ISO 3166-1 alpha code. + final String countryCode; + + /// Country name. + final String countryName; + + /// Returns true if this the current user session. + final bool current; + + /// Returns a list of active session factors. + final List<String> factors; + + /// Secret used to authenticate the user. Only included if the request was made with an API key + final String secret; + + /// Most recent date in ISO 8601 format when the session successfully passed MFA challenge. + final String mfaUpdatedAt; + + Session({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.userId, + required this.expire, + required this.provider, + required this.providerUid, + required this.providerAccessToken, + required this.providerAccessTokenExpiry, + required this.providerRefreshToken, + required this.ip, + required this.osCode, + required this.osName, + required this.osVersion, + required this.clientType, + required this.clientCode, + required this.clientName, + required this.clientVersion, + required this.clientEngine, + required this.clientEngineVersion, + required this.deviceName, + required this.deviceBrand, + required this.deviceModel, + required this.countryCode, + required this.countryName, + required this.current, + required this.factors, + required this.secret, + required this.mfaUpdatedAt, + }); + + factory Session.fromMap(Map<String, dynamic> map) { + return Session( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + userId: map['userId'].toString(), + expire: map['expire'].toString(), + provider: map['provider'].toString(), + providerUid: map['providerUid'].toString(), + providerAccessToken: map['providerAccessToken'].toString(), + providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), + providerRefreshToken: map['providerRefreshToken'].toString(), + ip: map['ip'].toString(), + osCode: map['osCode'].toString(), + osName: map['osName'].toString(), + osVersion: map['osVersion'].toString(), + clientType: map['clientType'].toString(), + clientCode: map['clientCode'].toString(), + clientName: map['clientName'].toString(), + clientVersion: map['clientVersion'].toString(), + clientEngine: map['clientEngine'].toString(), + clientEngineVersion: map['clientEngineVersion'].toString(), + deviceName: map['deviceName'].toString(), + deviceBrand: map['deviceBrand'].toString(), + deviceModel: map['deviceModel'].toString(), + countryCode: map['countryCode'].toString(), + countryName: map['countryName'].toString(), + current: map['current'], + factors: map['factors'] ?? [], + secret: map['secret'].toString(), + mfaUpdatedAt: map['mfaUpdatedAt'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "userId": userId, + "expire": expire, + "provider": provider, + "providerUid": providerUid, + "providerAccessToken": providerAccessToken, + "providerAccessTokenExpiry": providerAccessTokenExpiry, + "providerRefreshToken": providerRefreshToken, + "ip": ip, + "osCode": osCode, + "osName": osName, + "osVersion": osVersion, + "clientType": clientType, + "clientCode": clientCode, + "clientName": clientName, + "clientVersion": clientVersion, + "clientEngine": clientEngine, + "clientEngineVersion": clientEngineVersion, + "deviceName": deviceName, + "deviceBrand": deviceBrand, + "deviceModel": deviceModel, + "countryCode": countryCode, + "countryName": countryName, + "current": current, + "factors": factors, + "secret": secret, + "mfaUpdatedAt": mfaUpdatedAt, + }; + } } diff --git a/lib/src/models/session_list.dart b/lib/src/models/session_list.dart index ee4841a2..e4739c9b 100644 --- a/lib/src/models/session_list.dart +++ b/lib/src/models/session_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Sessions List class SessionList implements Model { - /// Total number of sessions documents that matched your query. - final int total; - /// List of sessions. - final List<Session> sessions; + /// Total number of sessions documents that matched your query. + final int total; - SessionList({ - required this.total, - required this.sessions, - }); + /// List of sessions. + final List<Session> sessions; - factory SessionList.fromMap(Map<String, dynamic> map) { - return SessionList( - total: map['total'], - sessions: List<Session>.from(map['sessions'].map((p) => Session.fromMap(p))), - ); - } + SessionList({ + required this.total, + required this.sessions, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "sessions": sessions.map((p) => p.toMap()).toList(), - }; - } + factory SessionList.fromMap(Map<String, dynamic> map) { + return SessionList( + total: map['total'], + sessions: + List<Session>.from(map['sessions'].map((p) => Session.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "sessions": sessions.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/specification.dart b/lib/src/models/specification.dart index 49e4c597..cf2fb838 100644 --- a/lib/src/models/specification.dart +++ b/lib/src/models/specification.dart @@ -2,37 +2,40 @@ part of '../../models.dart'; /// Specification class Specification implements Model { - /// Memory size in MB. - final int memory; - /// Number of CPUs. - final double cpus; - /// Is size enabled. - final bool enabled; - /// Size slug. - final String slug; + /// Memory size in MB. + final int memory; - Specification({ - required this.memory, - required this.cpus, - required this.enabled, - required this.slug, - }); + /// Number of CPUs. + final double cpus; - factory Specification.fromMap(Map<String, dynamic> map) { - return Specification( - memory: map['memory'], - cpus: map['cpus'].toDouble(), - enabled: map['enabled'], - slug: map['slug'].toString(), - ); - } + /// Is size enabled. + final bool enabled; - Map<String, dynamic> toMap() { - return { - "memory": memory, - "cpus": cpus, - "enabled": enabled, - "slug": slug, - }; - } + /// Size slug. + final String slug; + + Specification({ + required this.memory, + required this.cpus, + required this.enabled, + required this.slug, + }); + + factory Specification.fromMap(Map<String, dynamic> map) { + return Specification( + memory: map['memory'], + cpus: map['cpus'].toDouble(), + enabled: map['enabled'], + slug: map['slug'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "memory": memory, + "cpus": cpus, + "enabled": enabled, + "slug": slug, + }; + } } diff --git a/lib/src/models/specification_list.dart b/lib/src/models/specification_list.dart index 494fd398..c66d5ac3 100644 --- a/lib/src/models/specification_list.dart +++ b/lib/src/models/specification_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Specifications List class SpecificationList implements Model { - /// Total number of specifications documents that matched your query. - final int total; - /// List of specifications. - final List<Specification> specifications; + /// Total number of specifications documents that matched your query. + final int total; - SpecificationList({ - required this.total, - required this.specifications, - }); + /// List of specifications. + final List<Specification> specifications; - factory SpecificationList.fromMap(Map<String, dynamic> map) { - return SpecificationList( - total: map['total'], - specifications: List<Specification>.from(map['specifications'].map((p) => Specification.fromMap(p))), - ); - } + SpecificationList({ + required this.total, + required this.specifications, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "specifications": specifications.map((p) => p.toMap()).toList(), - }; - } + factory SpecificationList.fromMap(Map<String, dynamic> map) { + return SpecificationList( + total: map['total'], + specifications: List<Specification>.from( + map['specifications'].map((p) => Specification.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "specifications": specifications.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/subscriber.dart b/lib/src/models/subscriber.dart index 97bdb018..0c926297 100644 --- a/lib/src/models/subscriber.dart +++ b/lib/src/models/subscriber.dart @@ -2,62 +2,70 @@ part of '../../models.dart'; /// Subscriber class Subscriber implements Model { - /// Subscriber ID. - final String $id; - /// Subscriber creation time in ISO 8601 format. - final String $createdAt; - /// Subscriber update date in ISO 8601 format. - final String $updatedAt; - /// Target ID. - final String targetId; - /// Target. - final Target target; - /// Topic ID. - final String userId; - /// User Name. - final String userName; - /// Topic ID. - final String topicId; - /// The target provider type. Can be one of the following: `email`, `sms` or `push`. - final String providerType; - - Subscriber({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.targetId, - required this.target, - required this.userId, - required this.userName, - required this.topicId, - required this.providerType, - }); - - factory Subscriber.fromMap(Map<String, dynamic> map) { - return Subscriber( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - targetId: map['targetId'].toString(), - target: Target.fromMap(map['target']), - userId: map['userId'].toString(), - userName: map['userName'].toString(), - topicId: map['topicId'].toString(), - providerType: map['providerType'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "targetId": targetId, - "target": target.toMap(), - "userId": userId, - "userName": userName, - "topicId": topicId, - "providerType": providerType, - }; - } + /// Subscriber ID. + final String $id; + + /// Subscriber creation time in ISO 8601 format. + final String $createdAt; + + /// Subscriber update date in ISO 8601 format. + final String $updatedAt; + + /// Target ID. + final String targetId; + + /// Target. + final Target target; + + /// Topic ID. + final String userId; + + /// User Name. + final String userName; + + /// Topic ID. + final String topicId; + + /// The target provider type. Can be one of the following: `email`, `sms` or `push`. + final String providerType; + + Subscriber({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.targetId, + required this.target, + required this.userId, + required this.userName, + required this.topicId, + required this.providerType, + }); + + factory Subscriber.fromMap(Map<String, dynamic> map) { + return Subscriber( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + targetId: map['targetId'].toString(), + target: Target.fromMap(map['target']), + userId: map['userId'].toString(), + userName: map['userName'].toString(), + topicId: map['topicId'].toString(), + providerType: map['providerType'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "targetId": targetId, + "target": target.toMap(), + "userId": userId, + "userName": userName, + "topicId": topicId, + "providerType": providerType, + }; + } } diff --git a/lib/src/models/subscriber_list.dart b/lib/src/models/subscriber_list.dart index c9a87d1f..14577a7e 100644 --- a/lib/src/models/subscriber_list.dart +++ b/lib/src/models/subscriber_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Subscriber list class SubscriberList implements Model { - /// Total number of subscribers documents that matched your query. - final int total; - /// List of subscribers. - final List<Subscriber> subscribers; + /// Total number of subscribers documents that matched your query. + final int total; - SubscriberList({ - required this.total, - required this.subscribers, - }); + /// List of subscribers. + final List<Subscriber> subscribers; - factory SubscriberList.fromMap(Map<String, dynamic> map) { - return SubscriberList( - total: map['total'], - subscribers: List<Subscriber>.from(map['subscribers'].map((p) => Subscriber.fromMap(p))), - ); - } + SubscriberList({ + required this.total, + required this.subscribers, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "subscribers": subscribers.map((p) => p.toMap()).toList(), - }; - } + factory SubscriberList.fromMap(Map<String, dynamic> map) { + return SubscriberList( + total: map['total'], + subscribers: List<Subscriber>.from( + map['subscribers'].map((p) => Subscriber.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "subscribers": subscribers.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/target.dart b/lib/src/models/target.dart index 6f754c8d..4be8b545 100644 --- a/lib/src/models/target.dart +++ b/lib/src/models/target.dart @@ -2,62 +2,70 @@ part of '../../models.dart'; /// Target class Target implements Model { - /// Target ID. - final String $id; - /// Target creation time in ISO 8601 format. - final String $createdAt; - /// Target update date in ISO 8601 format. - final String $updatedAt; - /// Target Name. - final String name; - /// User ID. - final String userId; - /// Provider ID. - final String? providerId; - /// The target provider type. Can be one of the following: `email`, `sms` or `push`. - final String providerType; - /// The target identifier. - final String identifier; - /// Is the target expired. - final bool expired; - - Target({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.userId, - this.providerId, - required this.providerType, - required this.identifier, - required this.expired, - }); - - factory Target.fromMap(Map<String, dynamic> map) { - return Target( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - userId: map['userId'].toString(), - providerId: map['providerId']?.toString(), - providerType: map['providerType'].toString(), - identifier: map['identifier'].toString(), - expired: map['expired'], - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "userId": userId, - "providerId": providerId, - "providerType": providerType, - "identifier": identifier, - "expired": expired, - }; - } + /// Target ID. + final String $id; + + /// Target creation time in ISO 8601 format. + final String $createdAt; + + /// Target update date in ISO 8601 format. + final String $updatedAt; + + /// Target Name. + final String name; + + /// User ID. + final String userId; + + /// Provider ID. + final String? providerId; + + /// The target provider type. Can be one of the following: `email`, `sms` or `push`. + final String providerType; + + /// The target identifier. + final String identifier; + + /// Is the target expired. + final bool expired; + + Target({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.userId, + this.providerId, + required this.providerType, + required this.identifier, + required this.expired, + }); + + factory Target.fromMap(Map<String, dynamic> map) { + return Target( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + userId: map['userId'].toString(), + providerId: map['providerId']?.toString(), + providerType: map['providerType'].toString(), + identifier: map['identifier'].toString(), + expired: map['expired'], + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "userId": userId, + "providerId": providerId, + "providerType": providerType, + "identifier": identifier, + "expired": expired, + }; + } } diff --git a/lib/src/models/target_list.dart b/lib/src/models/target_list.dart index bdd8ff58..8b0ef79d 100644 --- a/lib/src/models/target_list.dart +++ b/lib/src/models/target_list.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Target list class TargetList implements Model { - /// Total number of targets documents that matched your query. - final int total; - /// List of targets. - final List<Target> targets; + /// Total number of targets documents that matched your query. + final int total; - TargetList({ - required this.total, - required this.targets, - }); + /// List of targets. + final List<Target> targets; - factory TargetList.fromMap(Map<String, dynamic> map) { - return TargetList( - total: map['total'], - targets: List<Target>.from(map['targets'].map((p) => Target.fromMap(p))), - ); - } + TargetList({ + required this.total, + required this.targets, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "targets": targets.map((p) => p.toMap()).toList(), - }; - } + factory TargetList.fromMap(Map<String, dynamic> map) { + return TargetList( + total: map['total'], + targets: List<Target>.from(map['targets'].map((p) => Target.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "targets": targets.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/team.dart b/lib/src/models/team.dart index a55d13c9..43df33a8 100644 --- a/lib/src/models/team.dart +++ b/lib/src/models/team.dart @@ -2,47 +2,52 @@ part of '../../models.dart'; /// Team class Team implements Model { - /// Team ID. - final String $id; - /// Team creation date in ISO 8601 format. - final String $createdAt; - /// Team update date in ISO 8601 format. - final String $updatedAt; - /// Team name. - final String name; - /// Total number of team members. - final int total; - /// Team preferences as a key-value object - final Preferences prefs; - - Team({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.total, - required this.prefs, - }); - - factory Team.fromMap(Map<String, dynamic> map) { - return Team( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - total: map['total'], - prefs: Preferences.fromMap(map['prefs']), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "total": total, - "prefs": prefs.toMap(), - }; - } + /// Team ID. + final String $id; + + /// Team creation date in ISO 8601 format. + final String $createdAt; + + /// Team update date in ISO 8601 format. + final String $updatedAt; + + /// Team name. + final String name; + + /// Total number of team members. + final int total; + + /// Team preferences as a key-value object + final Preferences prefs; + + Team({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.total, + required this.prefs, + }); + + factory Team.fromMap(Map<String, dynamic> map) { + return Team( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + total: map['total'], + prefs: Preferences.fromMap(map['prefs']), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "total": total, + "prefs": prefs.toMap(), + }; + } } diff --git a/lib/src/models/team_list.dart b/lib/src/models/team_list.dart index 23147a1a..817e944f 100644 --- a/lib/src/models/team_list.dart +++ b/lib/src/models/team_list.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Teams List class TeamList implements Model { - /// Total number of teams documents that matched your query. - final int total; - /// List of teams. - final List<Team> teams; + /// Total number of teams documents that matched your query. + final int total; - TeamList({ - required this.total, - required this.teams, - }); + /// List of teams. + final List<Team> teams; - factory TeamList.fromMap(Map<String, dynamic> map) { - return TeamList( - total: map['total'], - teams: List<Team>.from(map['teams'].map((p) => Team.fromMap(p))), - ); - } + TeamList({ + required this.total, + required this.teams, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "teams": teams.map((p) => p.toMap()).toList(), - }; - } + factory TeamList.fromMap(Map<String, dynamic> map) { + return TeamList( + total: map['total'], + teams: List<Team>.from(map['teams'].map((p) => Team.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "teams": teams.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/token.dart b/lib/src/models/token.dart index 217006c0..35115467 100644 --- a/lib/src/models/token.dart +++ b/lib/src/models/token.dart @@ -2,47 +2,52 @@ part of '../../models.dart'; /// Token class Token implements Model { - /// Token ID. - final String $id; - /// Token creation date in ISO 8601 format. - final String $createdAt; - /// User ID. - final String userId; - /// Token secret key. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. - final String secret; - /// Token expiration date in ISO 8601 format. - final String expire; - /// Security phrase of a token. Empty if security phrase was not requested when creating a token. It includes randomly generated phrase which is also sent in the external resource such as email. - final String phrase; - - Token({ - required this.$id, - required this.$createdAt, - required this.userId, - required this.secret, - required this.expire, - required this.phrase, - }); - - factory Token.fromMap(Map<String, dynamic> map) { - return Token( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - userId: map['userId'].toString(), - secret: map['secret'].toString(), - expire: map['expire'].toString(), - phrase: map['phrase'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "userId": userId, - "secret": secret, - "expire": expire, - "phrase": phrase, - }; - } + /// Token ID. + final String $id; + + /// Token creation date in ISO 8601 format. + final String $createdAt; + + /// User ID. + final String userId; + + /// Token secret key. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. + final String secret; + + /// Token expiration date in ISO 8601 format. + final String expire; + + /// Security phrase of a token. Empty if security phrase was not requested when creating a token. It includes randomly generated phrase which is also sent in the external resource such as email. + final String phrase; + + Token({ + required this.$id, + required this.$createdAt, + required this.userId, + required this.secret, + required this.expire, + required this.phrase, + }); + + factory Token.fromMap(Map<String, dynamic> map) { + return Token( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + userId: map['userId'].toString(), + secret: map['secret'].toString(), + expire: map['expire'].toString(), + phrase: map['phrase'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "userId": userId, + "secret": secret, + "expire": expire, + "phrase": phrase, + }; + } } diff --git a/lib/src/models/topic.dart b/lib/src/models/topic.dart index 06ab80db..9714abba 100644 --- a/lib/src/models/topic.dart +++ b/lib/src/models/topic.dart @@ -2,57 +2,64 @@ part of '../../models.dart'; /// Topic class Topic implements Model { - /// Topic ID. - final String $id; - /// Topic creation time in ISO 8601 format. - final String $createdAt; - /// Topic update date in ISO 8601 format. - final String $updatedAt; - /// The name of the topic. - final String name; - /// Total count of email subscribers subscribed to the topic. - final int emailTotal; - /// Total count of SMS subscribers subscribed to the topic. - final int smsTotal; - /// Total count of push subscribers subscribed to the topic. - final int pushTotal; - /// Subscribe permissions. - final List<String> subscribe; - - Topic({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.emailTotal, - required this.smsTotal, - required this.pushTotal, - required this.subscribe, - }); - - factory Topic.fromMap(Map<String, dynamic> map) { - return Topic( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - emailTotal: map['emailTotal'], - smsTotal: map['smsTotal'], - pushTotal: map['pushTotal'], - subscribe: map['subscribe'] ?? [], - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "emailTotal": emailTotal, - "smsTotal": smsTotal, - "pushTotal": pushTotal, - "subscribe": subscribe, - }; - } + /// Topic ID. + final String $id; + + /// Topic creation time in ISO 8601 format. + final String $createdAt; + + /// Topic update date in ISO 8601 format. + final String $updatedAt; + + /// The name of the topic. + final String name; + + /// Total count of email subscribers subscribed to the topic. + final int emailTotal; + + /// Total count of SMS subscribers subscribed to the topic. + final int smsTotal; + + /// Total count of push subscribers subscribed to the topic. + final int pushTotal; + + /// Subscribe permissions. + final List<String> subscribe; + + Topic({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.emailTotal, + required this.smsTotal, + required this.pushTotal, + required this.subscribe, + }); + + factory Topic.fromMap(Map<String, dynamic> map) { + return Topic( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + emailTotal: map['emailTotal'], + smsTotal: map['smsTotal'], + pushTotal: map['pushTotal'], + subscribe: map['subscribe'] ?? [], + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "emailTotal": emailTotal, + "smsTotal": smsTotal, + "pushTotal": pushTotal, + "subscribe": subscribe, + }; + } } diff --git a/lib/src/models/topic_list.dart b/lib/src/models/topic_list.dart index 0248a3c0..be78a61f 100644 --- a/lib/src/models/topic_list.dart +++ b/lib/src/models/topic_list.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Topic list class TopicList implements Model { - /// Total number of topics documents that matched your query. - final int total; - /// List of topics. - final List<Topic> topics; + /// Total number of topics documents that matched your query. + final int total; - TopicList({ - required this.total, - required this.topics, - }); + /// List of topics. + final List<Topic> topics; - factory TopicList.fromMap(Map<String, dynamic> map) { - return TopicList( - total: map['total'], - topics: List<Topic>.from(map['topics'].map((p) => Topic.fromMap(p))), - ); - } + TopicList({ + required this.total, + required this.topics, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "topics": topics.map((p) => p.toMap()).toList(), - }; - } + factory TopicList.fromMap(Map<String, dynamic> map) { + return TopicList( + total: map['total'], + topics: List<Topic>.from(map['topics'].map((p) => Topic.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "topics": topics.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/user.dart b/lib/src/models/user.dart index ccc22c65..e5942793 100644 --- a/lib/src/models/user.dart +++ b/lib/src/models/user.dart @@ -2,112 +2,130 @@ part of '../../models.dart'; /// User class User implements Model { - /// User ID. - final String $id; - /// User creation date in ISO 8601 format. - final String $createdAt; - /// User update date in ISO 8601 format. - final String $updatedAt; - /// User name. - final String name; - /// Hashed user password. - final String? password; - /// Password hashing algorithm. - final String? hash; - /// Password hashing algorithm configuration. - final Map? hashOptions; - /// User registration date in ISO 8601 format. - final String registration; - /// User status. Pass `true` for enabled and `false` for disabled. - final bool status; - /// Labels for the user. - final List<String> labels; - /// Password update time in ISO 8601 format. - final String passwordUpdate; - /// User email address. - final String email; - /// User phone number in E.164 format. - final String phone; - /// Email verification status. - final bool emailVerification; - /// Phone verification status. - final bool phoneVerification; - /// Multi factor authentication status. - final bool mfa; - /// User preferences as a key-value object - final Preferences prefs; - /// A user-owned message receiver. A single user may have multiple e.g. emails, phones, and a browser. Each target is registered with a single provider. - final List<Target> targets; - /// Most recent access date in ISO 8601 format. This attribute is only updated again after 24 hours. - final String accessedAt; - - User({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - this.password, - this.hash, - this.hashOptions, - required this.registration, - required this.status, - required this.labels, - required this.passwordUpdate, - required this.email, - required this.phone, - required this.emailVerification, - required this.phoneVerification, - required this.mfa, - required this.prefs, - required this.targets, - required this.accessedAt, - }); - - factory User.fromMap(Map<String, dynamic> map) { - return User( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - password: map['password']?.toString(), - hash: map['hash']?.toString(), - hashOptions: map['hashOptions'], - registration: map['registration'].toString(), - status: map['status'], - labels: map['labels'] ?? [], - passwordUpdate: map['passwordUpdate'].toString(), - email: map['email'].toString(), - phone: map['phone'].toString(), - emailVerification: map['emailVerification'], - phoneVerification: map['phoneVerification'], - mfa: map['mfa'], - prefs: Preferences.fromMap(map['prefs']), - targets: List<Target>.from(map['targets'].map((p) => Target.fromMap(p))), - accessedAt: map['accessedAt'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "password": password, - "hash": hash, - "hashOptions": hashOptions, - "registration": registration, - "status": status, - "labels": labels, - "passwordUpdate": passwordUpdate, - "email": email, - "phone": phone, - "emailVerification": emailVerification, - "phoneVerification": phoneVerification, - "mfa": mfa, - "prefs": prefs.toMap(), - "targets": targets.map((p) => p.toMap()).toList(), - "accessedAt": accessedAt, - }; - } + /// User ID. + final String $id; + + /// User creation date in ISO 8601 format. + final String $createdAt; + + /// User update date in ISO 8601 format. + final String $updatedAt; + + /// User name. + final String name; + + /// Hashed user password. + final String? password; + + /// Password hashing algorithm. + final String? hash; + + /// Password hashing algorithm configuration. + final Map? hashOptions; + + /// User registration date in ISO 8601 format. + final String registration; + + /// User status. Pass `true` for enabled and `false` for disabled. + final bool status; + + /// Labels for the user. + final List<String> labels; + + /// Password update time in ISO 8601 format. + final String passwordUpdate; + + /// User email address. + final String email; + + /// User phone number in E.164 format. + final String phone; + + /// Email verification status. + final bool emailVerification; + + /// Phone verification status. + final bool phoneVerification; + + /// Multi factor authentication status. + final bool mfa; + + /// User preferences as a key-value object + final Preferences prefs; + + /// A user-owned message receiver. A single user may have multiple e.g. emails, phones, and a browser. Each target is registered with a single provider. + final List<Target> targets; + + /// Most recent access date in ISO 8601 format. This attribute is only updated again after 24 hours. + final String accessedAt; + + User({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + this.password, + this.hash, + this.hashOptions, + required this.registration, + required this.status, + required this.labels, + required this.passwordUpdate, + required this.email, + required this.phone, + required this.emailVerification, + required this.phoneVerification, + required this.mfa, + required this.prefs, + required this.targets, + required this.accessedAt, + }); + + factory User.fromMap(Map<String, dynamic> map) { + return User( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + password: map['password']?.toString(), + hash: map['hash']?.toString(), + hashOptions: map['hashOptions'], + registration: map['registration'].toString(), + status: map['status'], + labels: map['labels'] ?? [], + passwordUpdate: map['passwordUpdate'].toString(), + email: map['email'].toString(), + phone: map['phone'].toString(), + emailVerification: map['emailVerification'], + phoneVerification: map['phoneVerification'], + mfa: map['mfa'], + prefs: Preferences.fromMap(map['prefs']), + targets: List<Target>.from(map['targets'].map((p) => Target.fromMap(p))), + accessedAt: map['accessedAt'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "password": password, + "hash": hash, + "hashOptions": hashOptions, + "registration": registration, + "status": status, + "labels": labels, + "passwordUpdate": passwordUpdate, + "email": email, + "phone": phone, + "emailVerification": emailVerification, + "phoneVerification": phoneVerification, + "mfa": mfa, + "prefs": prefs.toMap(), + "targets": targets.map((p) => p.toMap()).toList(), + "accessedAt": accessedAt, + }; + } } diff --git a/lib/src/models/user_list.dart b/lib/src/models/user_list.dart index 53f47dac..a9a78f63 100644 --- a/lib/src/models/user_list.dart +++ b/lib/src/models/user_list.dart @@ -2,27 +2,28 @@ part of '../../models.dart'; /// Users List class UserList implements Model { - /// Total number of users documents that matched your query. - final int total; - /// List of users. - final List<User> users; + /// Total number of users documents that matched your query. + final int total; - UserList({ - required this.total, - required this.users, - }); + /// List of users. + final List<User> users; - factory UserList.fromMap(Map<String, dynamic> map) { - return UserList( - total: map['total'], - users: List<User>.from(map['users'].map((p) => User.fromMap(p))), - ); - } + UserList({ + required this.total, + required this.users, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "users": users.map((p) => p.toMap()).toList(), - }; - } + factory UserList.fromMap(Map<String, dynamic> map) { + return UserList( + total: map['total'], + users: List<User>.from(map['users'].map((p) => User.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "users": users.map((p) => p.toMap()).toList(), + }; + } } diff --git a/lib/src/models/variable.dart b/lib/src/models/variable.dart index 83526877..a233010a 100644 --- a/lib/src/models/variable.dart +++ b/lib/src/models/variable.dart @@ -2,52 +2,58 @@ part of '../../models.dart'; /// Variable class Variable implements Model { - /// Variable ID. - final String $id; - /// Variable creation date in ISO 8601 format. - final String $createdAt; - /// Variable creation date in ISO 8601 format. - final String $updatedAt; - /// Variable key. - final String key; - /// Variable value. - final String value; - /// Service to which the variable belongs. Possible values are "project", "function" - final String resourceType; - /// ID of resource to which the variable belongs. If resourceType is "project", it is empty. If resourceType is "function", it is ID of the function. - final String resourceId; - - Variable({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.key, - required this.value, - required this.resourceType, - required this.resourceId, - }); - - factory Variable.fromMap(Map<String, dynamic> map) { - return Variable( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - key: map['key'].toString(), - value: map['value'].toString(), - resourceType: map['resourceType'].toString(), - resourceId: map['resourceId'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "key": key, - "value": value, - "resourceType": resourceType, - "resourceId": resourceId, - }; - } + /// Variable ID. + final String $id; + + /// Variable creation date in ISO 8601 format. + final String $createdAt; + + /// Variable creation date in ISO 8601 format. + final String $updatedAt; + + /// Variable key. + final String key; + + /// Variable value. + final String value; + + /// Service to which the variable belongs. Possible values are "project", "function" + final String resourceType; + + /// ID of resource to which the variable belongs. If resourceType is "project", it is empty. If resourceType is "function", it is ID of the function. + final String resourceId; + + Variable({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.key, + required this.value, + required this.resourceType, + required this.resourceId, + }); + + factory Variable.fromMap(Map<String, dynamic> map) { + return Variable( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + key: map['key'].toString(), + value: map['value'].toString(), + resourceType: map['resourceType'].toString(), + resourceId: map['resourceId'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "key": key, + "value": value, + "resourceType": resourceType, + "resourceId": resourceId, + }; + } } diff --git a/lib/src/models/variable_list.dart b/lib/src/models/variable_list.dart index cf795822..b2f550a6 100644 --- a/lib/src/models/variable_list.dart +++ b/lib/src/models/variable_list.dart @@ -2,27 +2,29 @@ part of '../../models.dart'; /// Variables List class VariableList implements Model { - /// Total number of variables documents that matched your query. - final int total; - /// List of variables. - final List<Variable> variables; + /// Total number of variables documents that matched your query. + final int total; - VariableList({ - required this.total, - required this.variables, - }); + /// List of variables. + final List<Variable> variables; - factory VariableList.fromMap(Map<String, dynamic> map) { - return VariableList( - total: map['total'], - variables: List<Variable>.from(map['variables'].map((p) => Variable.fromMap(p))), - ); - } + VariableList({ + required this.total, + required this.variables, + }); - Map<String, dynamic> toMap() { - return { - "total": total, - "variables": variables.map((p) => p.toMap()).toList(), - }; - } + factory VariableList.fromMap(Map<String, dynamic> map) { + return VariableList( + total: map['total'], + variables: + List<Variable>.from(map['variables'].map((p) => Variable.fromMap(p))), + ); + } + + Map<String, dynamic> toMap() { + return { + "total": total, + "variables": variables.map((p) => p.toMap()).toList(), + }; + } } From 3a346a242c00eeda3f10de3524706259dc878e6f Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 28 Jan 2025 18:30:51 +0000 Subject: [PATCH 7/7] fix: pong response & chunked upload --- LICENSE | 2 +- README.md | 2 +- docs/examples/account/update-mfa-challenge.md | 2 +- lib/client_browser.dart | 2 +- lib/client_io.dart | 2 +- lib/dart_appwrite.dart | 2 +- lib/id.dart | 3 +- lib/query.dart | 45 +- lib/role.dart | 106 +- lib/services/account.dart | 2239 +++++++------- lib/services/avatars.dart | 404 ++- lib/services/databases.dart | 2367 +++++++-------- lib/services/functions.dart | 1272 ++++---- lib/services/graphql.dart | 94 +- lib/services/health.dart | 929 +++--- lib/services/locale.dart | 270 +- lib/services/messaging.dart | 2637 ++++++++--------- lib/services/storage.dart | 732 +++-- lib/services/teams.dart | 688 ++--- lib/services/users.dart | 2072 ++++++------- lib/src/client.dart | 10 +- lib/src/client_base.dart | 9 +- lib/src/client_browser.dart | 110 +- lib/src/client_io.dart | 110 +- lib/src/client_mixin.dart | 33 +- lib/src/enums/authentication_factor.dart | 18 +- lib/src/enums/authenticator_type.dart | 12 +- lib/src/enums/browser.dart | 38 +- lib/src/enums/compression.dart | 16 +- lib/src/enums/credit_card.dart | 42 +- lib/src/enums/execution_method.dart | 22 +- lib/src/enums/flag.dart | 400 +-- lib/src/enums/image_format.dart | 23 +- lib/src/enums/image_gravity.dart | 28 +- lib/src/enums/index_type.dart | 16 +- lib/src/enums/message_priority.dart | 14 +- lib/src/enums/messaging_provider_type.dart | 16 +- lib/src/enums/name.dart | 34 +- lib/src/enums/o_auth_provider.dart | 88 +- lib/src/enums/password_hash.dart | 32 +- lib/src/enums/relation_mutate.dart | 16 +- lib/src/enums/relationship_type.dart | 18 +- lib/src/enums/runtime.dart | 128 +- lib/src/enums/smtp_encryption.dart | 16 +- lib/src/exception.dart | 2 +- lib/src/models/algo_argon2.dart | 65 +- lib/src/models/algo_bcrypt.dart | 32 +- lib/src/models/algo_md5.dart | 32 +- lib/src/models/algo_phpass.dart | 32 +- lib/src/models/algo_scrypt.dart | 82 +- lib/src/models/algo_scrypt_modified.dart | 65 +- lib/src/models/algo_sha.dart | 32 +- lib/src/models/attribute_boolean.dart | 126 +- lib/src/models/attribute_datetime.dart | 131 +- lib/src/models/attribute_email.dart | 131 +- lib/src/models/attribute_enum.dart | 142 +- lib/src/models/attribute_float.dart | 142 +- lib/src/models/attribute_integer.dart | 142 +- lib/src/models/attribute_ip.dart | 131 +- lib/src/models/attribute_list.dart | 43 +- lib/src/models/attribute_relationship.dart | 181 +- lib/src/models/attribute_string.dart | 131 +- lib/src/models/attribute_url.dart | 131 +- lib/src/models/bucket.dart | 153 +- lib/src/models/bucket_list.dart | 43 +- lib/src/models/build.dart | 126 +- lib/src/models/collection.dart | 131 +- lib/src/models/collection_list.dart | 44 +- lib/src/models/continent.dart | 43 +- lib/src/models/continent_list.dart | 44 +- lib/src/models/country.dart | 43 +- lib/src/models/country_list.dart | 44 +- lib/src/models/currency.dart | 104 +- lib/src/models/currency_list.dart | 44 +- lib/src/models/database.dart | 82 +- lib/src/models/database_list.dart | 44 +- lib/src/models/deployment.dart | 291 +- lib/src/models/deployment_list.dart | 44 +- lib/src/models/document.dart | 105 +- lib/src/models/document_list.dart | 48 +- lib/src/models/execution.dart | 216 +- lib/src/models/execution_list.dart | 44 +- lib/src/models/file.dart | 142 +- lib/src/models/file_list.dart | 43 +- lib/src/models/function.dart | 291 +- lib/src/models/function_list.dart | 43 +- lib/src/models/headers.dart | 43 +- lib/src/models/health_antivirus.dart | 43 +- lib/src/models/health_certificate.dart | 93 +- lib/src/models/health_queue.dart | 32 +- lib/src/models/health_status.dart | 54 +- lib/src/models/health_time.dart | 54 +- lib/src/models/identity.dart | 131 +- lib/src/models/identity_list.dart | 44 +- lib/src/models/index.dart | 115 +- lib/src/models/index_list.dart | 43 +- lib/src/models/jwt.dart | 32 +- lib/src/models/language.dart | 54 +- lib/src/models/language_list.dart | 44 +- lib/src/models/locale.dart | 104 +- lib/src/models/locale_code.dart | 43 +- lib/src/models/locale_code_list.dart | 44 +- lib/src/models/log.dart | 258 +- lib/src/models/log_list.dart | 43 +- lib/src/models/membership.dart | 170 +- lib/src/models/membership_list.dart | 44 +- lib/src/models/message.dart | 170 +- lib/src/models/message_list.dart | 44 +- lib/src/models/mfa_challenge.dart | 65 +- lib/src/models/mfa_factors.dart | 65 +- lib/src/models/mfa_recovery_codes.dart | 32 +- lib/src/models/mfa_type.dart | 43 +- lib/src/models/model.dart | 2 +- lib/src/models/phone.dart | 54 +- lib/src/models/phone_list.dart | 43 +- lib/src/models/preferences.dart | 32 +- lib/src/models/provider.dart | 126 +- lib/src/models/provider_list.dart | 44 +- lib/src/models/runtime.dart | 115 +- lib/src/models/runtime_list.dart | 44 +- lib/src/models/session.dart | 346 +-- lib/src/models/session_list.dart | 44 +- lib/src/models/specification.dart | 65 +- lib/src/models/specification_list.dart | 44 +- lib/src/models/subscriber.dart | 126 +- lib/src/models/subscriber_list.dart | 44 +- lib/src/models/target.dart | 126 +- lib/src/models/target_list.dart | 43 +- lib/src/models/team.dart | 93 +- lib/src/models/team_list.dart | 43 +- lib/src/models/token.dart | 93 +- lib/src/models/topic.dart | 115 +- lib/src/models/topic_list.dart | 43 +- lib/src/models/user.dart | 236 +- lib/src/models/user_list.dart | 43 +- lib/src/models/variable.dart | 104 +- lib/src/models/variable_list.dart | 44 +- pubspec.yaml | 2 +- test/services/account_test.dart | 34 +- test/services/users_test.dart | 21 +- 140 files changed, 11325 insertions(+), 11855 deletions(-) diff --git a/LICENSE b/LICENSE index 5479bb8e..c1602fcd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2024 Appwrite (https://appwrite.io) and individual contributors. +Copyright (c) 2025 Appwrite (https://appwrite.io) and individual contributors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/README.md b/README.md index 117a0265..494a3f90 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Add this to your package's `pubspec.yaml` file: ```yml dependencies: - dart_appwrite: ^12.2.0 + dart_appwrite: ^12.2.1 ``` You can install packages from the command line: diff --git a/docs/examples/account/update-mfa-challenge.md b/docs/examples/account/update-mfa-challenge.md index fd64c61c..2843d2f1 100644 --- a/docs/examples/account/update-mfa-challenge.md +++ b/docs/examples/account/update-mfa-challenge.md @@ -7,7 +7,7 @@ Client client = Client() Account account = Account(client); - result = await account.updateMfaChallenge( +Session result = await account.updateMfaChallenge( challengeId: '<CHALLENGE_ID>', otp: '<OTP>', ); diff --git a/lib/client_browser.dart b/lib/client_browser.dart index b9805a3a..09f110ea 100644 --- a/lib/client_browser.dart +++ b/lib/client_browser.dart @@ -1 +1 @@ -export 'src/client_browser.dart'; +export 'src/client_browser.dart'; \ No newline at end of file diff --git a/lib/client_io.dart b/lib/client_io.dart index 42a0c0b6..4d85cbfa 100644 --- a/lib/client_io.dart +++ b/lib/client_io.dart @@ -1 +1 @@ -export 'src/client_io.dart'; +export 'src/client_io.dart'; \ No newline at end of file diff --git a/lib/dart_appwrite.dart b/lib/dart_appwrite.dart index 26412fe3..21865e2e 100644 --- a/lib/dart_appwrite.dart +++ b/lib/dart_appwrite.dart @@ -1,6 +1,6 @@ /// Appwrite Dart SDK /// -/// This SDK is compatible with Appwrite server version 1.6.x. +/// This SDK is compatible with Appwrite server version 1.6.x. /// For older versions, please check /// [previous releases](https://github.com/appwrite/sdk-for-dart/releases). library dart_appwrite; diff --git a/lib/id.dart b/lib/id.dart index 28ff15e8..72e26a23 100644 --- a/lib/id.dart +++ b/lib/id.dart @@ -10,7 +10,8 @@ class ID { final now = DateTime.now(); final sec = (now.millisecondsSinceEpoch / 1000).floor(); final usec = now.microsecondsSinceEpoch - (sec * 1000000); - return sec.toRadixString(16) + usec.toRadixString(16).padLeft(5, '0'); + return sec.toRadixString(16) + + usec.toRadixString(16).padLeft(5, '0'); } // Generate a unique ID with padding to have a longer ID diff --git a/lib/query.dart b/lib/query.dart index 6b8ed94f..46882207 100644 --- a/lib/query.dart +++ b/lib/query.dart @@ -1,5 +1,6 @@ part of 'dart_appwrite.dart'; + /// Helper class to generate query strings. class Query { final String method; @@ -13,11 +14,11 @@ class Query { 'method': method, }; - if (attribute != null) { + if(attribute != null) { map['attribute'] = attribute; } - - if (values != null) { + + if(values != null) { map['values'] = values is List ? values : [values]; } @@ -28,7 +29,7 @@ class Query { String toString() => jsonEncode(toJson()); /// Filter resources where [attribute] is equal to [value]. - /// + /// /// [value] can be a single value or a list. If a list is used /// the query will return resources where [attribute] is equal /// to any of the values in the list. @@ -60,12 +61,10 @@ class Query { Query._('search', attribute, value).toString(); /// Filter resources where [attribute] is null. - static String isNull(String attribute) => - Query._('isNull', attribute).toString(); + static String isNull(String attribute) => Query._('isNull', attribute).toString(); /// Filter resources where [attribute] is not null. - static String isNotNull(String attribute) => - Query._('isNotNull', attribute).toString(); + static String isNotNull(String attribute) => Query._('isNotNull', attribute).toString(); /// Filter resources where [attribute] is between [start] and [end] (inclusive). static String between(String attribute, dynamic start, dynamic end) => @@ -85,46 +84,40 @@ class Query { Query._('contains', attribute, value).toString(); static String or(List<String> queries) => - Query._('or', null, queries.map((query) => jsonDecode(query)).toList()) - .toString(); + Query._('or', null, queries.map((query) => jsonDecode(query)).toList()).toString(); static String and(List<String> queries) => - Query._('and', null, queries.map((query) => jsonDecode(query)).toList()) - .toString(); + Query._('and', null, queries.map((query) => jsonDecode(query)).toList()).toString(); /// Specify which attributes should be returned by the API call. static String select(List<String> attributes) => Query._('select', null, attributes).toString(); /// Sort results by [attribute] ascending. - static String orderAsc(String attribute) => - Query._('orderAsc', attribute).toString(); + static String orderAsc(String attribute) => Query._('orderAsc', attribute).toString(); /// Sort results by [attribute] descending. - static String orderDesc(String attribute) => - Query._('orderDesc', attribute).toString(); + static String orderDesc(String attribute) => Query._('orderDesc', attribute).toString(); /// Return results before [id]. - /// + /// /// Refer to the [Cursor Based Pagination](https://appwrite.io/docs/pagination#cursor-pagination) /// docs for more information. - static String cursorBefore(String id) => - Query._('cursorBefore', null, id).toString(); + static String cursorBefore(String id) => Query._('cursorBefore', null, id).toString(); /// Return results after [id]. - /// + /// /// Refer to the [Cursor Based Pagination](https://appwrite.io/docs/pagination#cursor-pagination) /// docs for more information. - static String cursorAfter(String id) => - Query._('cursorAfter', null, id).toString(); + static String cursorAfter(String id) => Query._('cursorAfter', null, id).toString(); /// Return only [limit] results. static String limit(int limit) => Query._('limit', null, limit).toString(); /// Return results from [offset]. - /// + /// /// Refer to the [Offset Pagination](https://appwrite.io/docs/pagination#offset-pagination) /// docs for more information. - static String offset(int offset) => - Query._('offset', null, offset).toString(); -} + static String offset(int offset) => Query._('offset', null, offset).toString(); + +} \ No newline at end of file diff --git a/lib/role.dart b/lib/role.dart index dafeb78d..6552df47 100644 --- a/lib/role.dart +++ b/lib/role.dart @@ -2,65 +2,65 @@ part of 'dart_appwrite.dart'; /// Helper class to generate role strings for [Permission]. class Role { - Role._(); - - /// Grants access to anyone. - /// - /// This includes authenticated and unauthenticated users. - static String any() { - return 'any'; - } + Role._(); + + /// Grants access to anyone. + /// + /// This includes authenticated and unauthenticated users. + static String any() { + return 'any'; + } - /// Grants access to a specific user by user ID. - /// - /// You can optionally pass verified or unverified for - /// [status] to target specific types of users. - static String user(String id, [String status = '']) { - if (status.isEmpty) { - return 'user:$id'; + /// Grants access to a specific user by user ID. + /// + /// You can optionally pass verified or unverified for + /// [status] to target specific types of users. + static String user(String id, [String status = '']) { + if(status.isEmpty) { + return 'user:$id'; + } + return 'user:$id/$status'; } - return 'user:$id/$status'; - } - /// Grants access to any authenticated or anonymous user. - /// - /// You can optionally pass verified or unverified for - /// [status] to target specific types of users. - static String users([String status = '']) { - if (status.isEmpty) { - return 'users'; + /// Grants access to any authenticated or anonymous user. + /// + /// You can optionally pass verified or unverified for + /// [status] to target specific types of users. + static String users([String status = '']) { + if(status.isEmpty) { + return 'users'; + } + return 'users/$status'; } - return 'users/$status'; - } - /// Grants access to any guest user without a session. - /// - /// Authenticated users don't have access to this role. - static String guests() { - return 'guests'; - } + /// Grants access to any guest user without a session. + /// + /// Authenticated users don't have access to this role. + static String guests() { + return 'guests'; + } - /// Grants access to a team by team ID. - /// - /// You can optionally pass a role for [role] to target - /// team members with the specified role. - static String team(String id, [String role = '']) { - if (role.isEmpty) { - return 'team:$id'; + /// Grants access to a team by team ID. + /// + /// You can optionally pass a role for [role] to target + /// team members with the specified role. + static String team(String id, [String role = '']) { + if(role.isEmpty) { + return 'team:$id'; + } + return 'team:$id/$role'; } - return 'team:$id/$role'; - } - /// Grants access to a specific member of a team. - /// - /// When the member is removed from the team, they will - /// no longer have access. - static String member(String id) { - return 'member:$id'; - } + /// Grants access to a specific member of a team. + /// + /// When the member is removed from the team, they will + /// no longer have access. + static String member(String id) { + return 'member:$id'; + } - /// Grants access to a user with the specified label. - static String label(String name) { - return 'label:$name'; - } -} + /// Grants access to a user with the specified label. + static String label(String name) { + return 'label:$name'; + } +} \ No newline at end of file diff --git a/lib/services/account.dart b/lib/services/account.dart index 00b7785c..93543d38 100644 --- a/lib/services/account.dart +++ b/lib/services/account.dart @@ -2,1070 +2,1175 @@ part of '../dart_appwrite.dart'; /// The Account service allows you to authenticate and manage a user account. class Account extends Service { - Account(super.client); - - /// Get account - /// - /// Get the currently logged in user. - Future<models.User> get() async { - final String apiPath = '/account'; - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession). - Future<models.User> create( - {required String userId, - required String email, - required String password, - String? name}) async { - final String apiPath = '/account'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'name': name, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update 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<models.User> updateEmail( - {required String email, required String password}) async { - final String apiPath = '/account/email'; - - final Map<String, dynamic> apiParams = { - 'email': email, - 'password': password, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// List identities - /// - /// Get the list of identities for the currently logged in user. - Future<models.IdentityList> listIdentities({List<String>? queries}) async { - final String apiPath = '/account/identities'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.IdentityList.fromMap(res.data); - } - - /// Delete identity - /// - /// Delete an identity by its unique ID. - Future deleteIdentity({required String identityId}) async { - final String apiPath = '/account/identities/{identityId}' - .replaceAll('{identityId}', identityId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Create 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<models.Jwt> createJWT() async { - final String apiPath = '/account/jwts'; - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Jwt.fromMap(res.data); - } - - /// List logs - /// - /// Get the list of latest security activity logs for the currently logged in - /// user. Each log returns user IP address, location and date and time of log. - Future<models.LogList> listLogs({List<String>? queries}) async { - final String apiPath = '/account/logs'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// Update MFA - /// - /// Enable or disable MFA on an account. - Future<models.User> updateMFA({required bool mfa}) async { - final String apiPath = '/account/mfa'; - - final Map<String, dynamic> apiParams = { - 'mfa': mfa, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create authenticator - /// - /// Add an authenticator app to be used as an MFA factor. Verify the - /// authenticator using the [verify - /// authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) - /// method. - Future<models.MfaType> createMfaAuthenticator( - {required enums.AuthenticatorType type}) async { - final String apiPath = - '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaType.fromMap(res.data); - } - - /// Verify authenticator - /// - /// Verify an authenticator app after adding it using the [add - /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) - /// method. - Future<models.User> updateMfaAuthenticator( - {required enums.AuthenticatorType type, required String otp}) async { - final String apiPath = - '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); - - final Map<String, dynamic> apiParams = { - 'otp': otp, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Delete authenticator - /// - /// Delete an authenticator for a user by ID. - Future deleteMfaAuthenticator({required enums.AuthenticatorType type}) async { - final String apiPath = - '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Create MFA challenge - /// - /// Begin the process of MFA verification after sign-in. Finish the flow with - /// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) - /// method. - Future<models.MfaChallenge> createMfaChallenge( - {required enums.AuthenticationFactor factor}) async { - final String apiPath = '/account/mfa/challenge'; - - final Map<String, dynamic> apiParams = { - 'factor': factor.value, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaChallenge.fromMap(res.data); - } - - /// Create MFA challenge (confirmation) - /// - /// Complete the MFA challenge by providing the one-time password. Finish the - /// process of MFA verification by providing the one-time password. To begin - /// the flow, use - /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) - /// method. - Future updateMfaChallenge( - {required String challengeId, required String otp}) async { - final String apiPath = '/account/mfa/challenge'; - - final Map<String, dynamic> apiParams = { - 'challengeId': challengeId, - 'otp': otp, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List factors - /// - /// List the factors available on the account to be used as a MFA challange. - Future<models.MfaFactors> listMfaFactors() async { - final String apiPath = '/account/mfa/factors'; - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaFactors.fromMap(res.data); - } - - /// Get MFA recovery codes - /// - /// Get recovery codes that can be used as backup for MFA flow. Before getting - /// codes, they must be generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. An OTP challenge is required to read recovery codes. - Future<models.MfaRecoveryCodes> getMfaRecoveryCodes() async { - final String apiPath = '/account/mfa/recovery-codes'; - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Create MFA recovery codes - /// - /// Generate recovery codes as backup for MFA flow. It's recommended to - /// generate and show then immediately after user successfully adds their - /// authehticator. Recovery codes can be used as a MFA verification type in - /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) - /// method. - Future<models.MfaRecoveryCodes> createMfaRecoveryCodes() async { - final String apiPath = '/account/mfa/recovery-codes'; - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Regenerate MFA recovery codes - /// - /// Regenerate recovery codes that can be used as backup for MFA flow. Before - /// regenerating codes, they must be first generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. An OTP challenge is required to regenreate recovery codes. - Future<models.MfaRecoveryCodes> updateMfaRecoveryCodes() async { - final String apiPath = '/account/mfa/recovery-codes'; - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Update name - /// - /// Update currently logged in user account name. - Future<models.User> updateName({required String name}) async { - final String apiPath = '/account/name'; - - final Map<String, dynamic> apiParams = { - 'name': name, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update 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<models.User> updatePassword( - {required String password, String? oldPassword}) async { - final String apiPath = '/account/password'; - - final Map<String, dynamic> apiParams = { - 'password': password, - 'oldPassword': oldPassword, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update 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](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification) - /// endpoint to send a confirmation SMS. - Future<models.User> updatePhone( - {required String phone, required String password}) async { - final String apiPath = '/account/phone'; - - final Map<String, dynamic> apiParams = { - 'phone': phone, - 'password': password, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Get account preferences - /// - /// Get the preferences as a key-value object for the currently logged in user. - Future<models.Preferences> getPrefs() async { - final String apiPath = '/account/prefs'; - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - } - - /// Update 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<models.User> updatePrefs({required Map prefs}) async { - final String apiPath = '/account/prefs'; - - final Map<String, dynamic> apiParams = { - 'prefs': prefs, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery) - /// endpoint to complete the process. The verification link sent to the user's - /// email address is valid for 1 hour. - Future<models.Token> createRecovery( - {required String email, required String url}) async { - final String apiPath = '/account/recovery'; - - final Map<String, dynamic> apiParams = { - 'email': email, - 'url': url, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Create 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](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery) - /// 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<models.Token> updateRecovery( - {required String userId, - required String secret, - required String password}) async { - final String apiPath = '/account/recovery'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'secret': secret, - 'password': password, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// List sessions - /// - /// Get the list of active sessions across different devices for the currently - /// logged in user. - Future<models.SessionList> listSessions() async { - final String apiPath = '/account/sessions'; - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SessionList.fromMap(res.data); - } - - /// Delete sessions - /// - /// Delete all sessions from the user account and remove any sessions cookies - /// from the end client. - Future deleteSessions() async { - final String apiPath = '/account/sessions'; - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail) - /// or create an [OAuth2 - /// session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session). - Future<models.Session> createAnonymousSession() async { - final String apiPath = '/account/sessions/anonymous'; - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Create email password session - /// - /// Allow the user to login into their account by providing a valid email and - /// password combination. This route will create a new session for the user. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future<models.Session> createEmailPasswordSession( - {required String email, required String password}) async { - final String apiPath = '/account/sessions/email'; - - final Map<String, dynamic> apiParams = { - 'email': email, - 'password': password, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Update magic URL session - /// - /// Use this endpoint to create a session from token. Provide the **userId** - /// and **secret** parameters from the successful response of authentication - /// flows initiated by token creation. For example, magic URL and phone login. - Future<models.Session> updateMagicURLSession( - {required String userId, required String secret}) async { - final String apiPath = '/account/sessions/magic-url'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Update phone session - /// - /// Use this endpoint to create a session from token. Provide the **userId** - /// and **secret** parameters from the successful response of authentication - /// flows initiated by token creation. For example, magic URL and phone login. - Future<models.Session> updatePhoneSession( - {required String userId, required String secret}) async { - final String apiPath = '/account/sessions/phone'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Create session - /// - /// Use this endpoint to create a session from token. Provide the **userId** - /// and **secret** parameters from the successful response of authentication - /// flows initiated by token creation. For example, magic URL and phone login. - Future<models.Session> createSession( - {required String userId, required String secret}) async { - final String apiPath = '/account/sessions/token'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Get session - /// - /// 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<models.Session> getSession({required String sessionId}) async { - final String apiPath = - '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Update session - /// - /// Use this endpoint to extend a session's length. Extending a session is - /// useful when session expiry is short. If the session was created using an - /// OAuth provider, this endpoint refreshes the access token from the provider. - Future<models.Session> updateSession({required String sessionId}) async { - final String apiPath = - '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Delete session - /// - /// Logout the user. Use 'current' as the session ID to logout on this device, - /// use a session ID to logout on another device. If you're looking to logout - /// the user on all devices, use [Delete - /// Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions) - /// instead. - Future deleteSession({required String sessionId}) async { - final String apiPath = - '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Update 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<models.User> updateStatus() async { - final String apiPath = '/account/status'; - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create email token (OTP) - /// - /// Sends the user an email with a secret key for creating a session. If the - /// provided user ID has not be registered, a new user will be created. Use the - /// returned user ID and secret and submit a request to the [POST - /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. The secret sent to the user's email - /// is valid for 15 minutes. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future<models.Token> createEmailToken( - {required String userId, required String email, bool? phrase}) async { - final String apiPath = '/account/tokens/email'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'email': email, - 'phrase': phrase, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Create magic URL token - /// - /// Sends the user an email with a secret key for creating a session. If the - /// provided user ID has not been registered, a new user will be created. When - /// the user clicks the link in the email, the user is redirected back to the - /// URL you provided with the secret key and userId values attached to the URL - /// query string. Use the query string parameters to submit a request to the - /// [POST - /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. The link sent to the user's email - /// address is valid for 1 hour. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - /// - Future<models.Token> createMagicURLToken( - {required String userId, - required String email, - String? url, - bool? phrase}) async { - final String apiPath = '/account/tokens/magic-url'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'email': email, - 'url': url, - 'phrase': phrase, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Create OAuth2 token - /// - /// Allow the user to login to their account using the OAuth2 provider of their - /// choice. Each OAuth2 provider should be enabled from the Appwrite console - /// first. Use the success and failure arguments to provide a redirect URL's - /// back to your app when login is completed. - /// - /// If authentication succeeds, `userId` and `secret` of a token will be - /// appended to the success URL as query parameters. These can be used to - /// create a new session using the [Create - /// session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future createOAuth2Token( - {required enums.OAuthProvider provider, - String? success, - String? failure, - List<String>? scopes}) async { - final String apiPath = '/account/tokens/oauth2/{provider}' - .replaceAll('{provider}', provider.value); - - final Map<String, dynamic> params = { - 'success': success, - 'failure': failure, - 'scopes': scopes, - 'project': client.config['project'], - }; - - final List query = []; - - params.forEach((key, value) { - if (value is List) { - for (var item in value) { - query.add(Uri.encodeComponent(key + '[]') + - '=' + - Uri.encodeComponent(item)); - } - } else if (value != null) { - query.add(Uri.encodeComponent(key) + '=' + Uri.encodeComponent(value)); - } - }); - - Uri endpoint = Uri.parse(client.endPoint); - Uri url = Uri( - scheme: endpoint.scheme, - host: endpoint.host, - port: endpoint.port, - path: endpoint.path + apiPath, - query: query.join('&')); - - return client.webAuth(url); - } - - /// Create phone token - /// - /// Sends the user an SMS with a secret key for creating a session. If the - /// provided user ID has not be registered, a new user will be created. Use the - /// returned user ID and secret and submit a request to the [POST - /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. The secret sent to the user's phone - /// is valid for 15 minutes. - /// - /// A user is limited to 10 active sessions at a time by default. [Learn more - /// about session - /// limits](https://appwrite.io/docs/authentication-security#limits). - Future<models.Token> createPhoneToken( - {required String userId, required String phone}) async { - final String apiPath = '/account/tokens/phone'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'phone': phone, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Create email verification - /// - /// Use this endpoint to send a verification message to your user email address - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). - /// 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<models.Token> createVerification({required String url}) async { - final String apiPath = '/account/verification'; - - final Map<String, dynamic> apiParams = { - 'url': url, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Create email verification (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<models.Token> updateVerification( - {required String userId, required String secret}) async { - final String apiPath = '/account/verification'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone) - /// endpoint. Learn more about how to [complete the verification - /// process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification). - /// The verification code sent to the user's phone number is valid for 15 - /// minutes. - Future<models.Token> createPhoneVerification() async { - final String apiPath = '/account/verification/phone'; - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Update 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<models.Token> updatePhoneVerification( - {required String userId, required String secret}) async { - final String apiPath = '/account/verification/phone'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } -} + Account(super.client); + + /// Get account + /// + /// Get the currently logged in user. + Future<models.User> get() async { + final String apiPath = '/account'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + 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](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession). + Future<models.User> create({required String userId, required String email, required String password, String? name}) async { + final String apiPath = '/account'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'name': name, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update 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<models.User> updateEmail({required String email, required String password}) async { + final String apiPath = '/account/email'; + + final Map<String, dynamic> apiParams = { + + 'email': email, +'password': password, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// List identities + /// + /// Get the list of identities for the currently logged in user. + Future<models.IdentityList> listIdentities({List<String>? queries}) async { + final String apiPath = '/account/identities'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.IdentityList.fromMap(res.data); + + } + + /// Delete identity + /// + /// Delete an identity by its unique ID. + Future deleteIdentity({required String identityId}) async { + final String apiPath = '/account/identities/{identityId}'.replaceAll('{identityId}', identityId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Create 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<models.Jwt> createJWT() async { + final String apiPath = '/account/jwts'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Jwt.fromMap(res.data); + + } + + /// List logs + /// + /// Get the list of latest security activity logs for the currently logged in + /// user. Each log returns user IP address, location and date and time of log. + Future<models.LogList> listLogs({List<String>? queries}) async { + final String apiPath = '/account/logs'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// Update MFA + /// + /// Enable or disable MFA on an account. + Future<models.User> updateMFA({required bool mfa}) async { + final String apiPath = '/account/mfa'; + + final Map<String, dynamic> apiParams = { + + 'mfa': mfa, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create authenticator + /// + /// Add an authenticator app to be used as an MFA factor. Verify the + /// authenticator using the [verify + /// authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) + /// method. + Future<models.MfaType> createMfaAuthenticator({required enums.AuthenticatorType type}) async { + final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaType.fromMap(res.data); + + } + + /// Verify authenticator + /// + /// Verify an authenticator app after adding it using the [add + /// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) + /// method. + Future<models.User> updateMfaAuthenticator({required enums.AuthenticatorType type, required String otp}) async { + final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map<String, dynamic> apiParams = { + + 'otp': otp, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Delete authenticator + /// + /// Delete an authenticator for a user by ID. + Future deleteMfaAuthenticator({required enums.AuthenticatorType type}) async { + final String apiPath = '/account/mfa/authenticators/{type}'.replaceAll('{type}', type.value); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Create MFA challenge + /// + /// Begin the process of MFA verification after sign-in. Finish the flow with + /// [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) + /// method. + Future<models.MfaChallenge> createMfaChallenge({required enums.AuthenticationFactor factor}) async { + final String apiPath = '/account/mfa/challenge'; + + final Map<String, dynamic> apiParams = { + + 'factor': factor.value, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaChallenge.fromMap(res.data); + + } + + /// Create MFA challenge (confirmation) + /// + /// Complete the MFA challenge by providing the one-time password. Finish the + /// process of MFA verification by providing the one-time password. To begin + /// the flow, use + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method. + Future<models.Session> updateMfaChallenge({required String challengeId, required String otp}) async { + final String apiPath = '/account/mfa/challenge'; + + final Map<String, dynamic> apiParams = { + + 'challengeId': challengeId, +'otp': otp, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// List factors + /// + /// List the factors available on the account to be used as a MFA challange. + Future<models.MfaFactors> listMfaFactors() async { + final String apiPath = '/account/mfa/factors'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaFactors.fromMap(res.data); + + } + + /// Get MFA recovery codes + /// + /// Get recovery codes that can be used as backup for MFA flow. Before getting + /// codes, they must be generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. An OTP challenge is required to read recovery codes. + Future<models.MfaRecoveryCodes> getMfaRecoveryCodes() async { + final String apiPath = '/account/mfa/recovery-codes'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Create MFA recovery codes + /// + /// Generate recovery codes as backup for MFA flow. It's recommended to + /// generate and show then immediately after user successfully adds their + /// authehticator. Recovery codes can be used as a MFA verification type in + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method. + Future<models.MfaRecoveryCodes> createMfaRecoveryCodes() async { + final String apiPath = '/account/mfa/recovery-codes'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Regenerate MFA recovery codes + /// + /// Regenerate recovery codes that can be used as backup for MFA flow. Before + /// regenerating codes, they must be first generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. An OTP challenge is required to regenreate recovery codes. + Future<models.MfaRecoveryCodes> updateMfaRecoveryCodes() async { + final String apiPath = '/account/mfa/recovery-codes'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Update name + /// + /// Update currently logged in user account name. + Future<models.User> updateName({required String name}) async { + final String apiPath = '/account/name'; + + final Map<String, dynamic> apiParams = { + + 'name': name, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update 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<models.User> updatePassword({required String password, String? oldPassword}) async { + final String apiPath = '/account/password'; + + final Map<String, dynamic> apiParams = { + + 'password': password, +'oldPassword': oldPassword, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update 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](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification) + /// endpoint to send a confirmation SMS. + Future<models.User> updatePhone({required String phone, required String password}) async { + final String apiPath = '/account/phone'; + + final Map<String, dynamic> apiParams = { + + 'phone': phone, +'password': password, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Get account preferences + /// + /// Get the preferences as a key-value object for the currently logged in user. + Future<models.Preferences> getPrefs() async { + final String apiPath = '/account/prefs'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + + } + + /// Update 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<models.User> updatePrefs({required Map prefs}) async { + final String apiPath = '/account/prefs'; + + final Map<String, dynamic> apiParams = { + + 'prefs': prefs, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + 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](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery) + /// endpoint to complete the process. The verification link sent to the user's + /// email address is valid for 1 hour. + Future<models.Token> createRecovery({required String email, required String url}) async { + final String apiPath = '/account/recovery'; + + final Map<String, dynamic> apiParams = { + + 'email': email, +'url': url, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Create 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](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery) + /// 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<models.Token> updateRecovery({required String userId, required String secret, required String password}) async { + final String apiPath = '/account/recovery'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'secret': secret, +'password': password, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// List sessions + /// + /// Get the list of active sessions across different devices for the currently + /// logged in user. + Future<models.SessionList> listSessions() async { + final String apiPath = '/account/sessions'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SessionList.fromMap(res.data); + + } + + /// Delete sessions + /// + /// Delete all sessions from the user account and remove any sessions cookies + /// from the end client. + Future deleteSessions() async { + final String apiPath = '/account/sessions'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + 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](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail) + /// or create an [OAuth2 + /// session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session). + Future<models.Session> createAnonymousSession() async { + final String apiPath = '/account/sessions/anonymous'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Create email password session + /// + /// Allow the user to login into their account by providing a valid email and + /// password combination. This route will create a new session for the user. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future<models.Session> createEmailPasswordSession({required String email, required String password}) async { + final String apiPath = '/account/sessions/email'; + + final Map<String, dynamic> apiParams = { + + 'email': email, +'password': password, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Update magic URL session + /// + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. + Future<models.Session> updateMagicURLSession({required String userId, required String secret}) async { + final String apiPath = '/account/sessions/magic-url'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Update phone session + /// + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. + Future<models.Session> updatePhoneSession({required String userId, required String secret}) async { + final String apiPath = '/account/sessions/phone'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Create session + /// + /// Use this endpoint to create a session from token. Provide the **userId** + /// and **secret** parameters from the successful response of authentication + /// flows initiated by token creation. For example, magic URL and phone login. + Future<models.Session> createSession({required String userId, required String secret}) async { + final String apiPath = '/account/sessions/token'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Get session + /// + /// 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<models.Session> getSession({required String sessionId}) async { + final String apiPath = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Update session + /// + /// Use this endpoint to extend a session's length. Extending a session is + /// useful when session expiry is short. If the session was created using an + /// OAuth provider, this endpoint refreshes the access token from the provider. + Future<models.Session> updateSession({required String sessionId}) async { + final String apiPath = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Delete session + /// + /// Logout the user. Use 'current' as the session ID to logout on this device, + /// use a session ID to logout on another device. If you're looking to logout + /// the user on all devices, use [Delete + /// Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions) + /// instead. + Future deleteSession({required String sessionId}) async { + final String apiPath = '/account/sessions/{sessionId}'.replaceAll('{sessionId}', sessionId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Update 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<models.User> updateStatus() async { + final String apiPath = '/account/status'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create email token (OTP) + /// + /// Sends the user an email with a secret key for creating a session. If the + /// provided user ID has not be registered, a new user will be created. Use the + /// returned user ID and secret and submit a request to the [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The secret sent to the user's email + /// is valid for 15 minutes. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future<models.Token> createEmailToken({required String userId, required String email, bool? phrase}) async { + final String apiPath = '/account/tokens/email'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'email': email, +'phrase': phrase, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Create magic URL token + /// + /// Sends the user an email with a secret key for creating a session. If the + /// provided user ID has not been registered, a new user will be created. When + /// the user clicks the link in the email, the user is redirected back to the + /// URL you provided with the secret key and userId values attached to the URL + /// query string. Use the query string parameters to submit a request to the + /// [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The link sent to the user's email + /// address is valid for 1 hour. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + /// + Future<models.Token> createMagicURLToken({required String userId, required String email, String? url, bool? phrase}) async { + final String apiPath = '/account/tokens/magic-url'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'email': email, +'url': url, +'phrase': phrase, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Create OAuth2 token + /// + /// Allow the user to login to their account using the OAuth2 provider of their + /// choice. Each OAuth2 provider should be enabled from the Appwrite console + /// first. Use the success and failure arguments to provide a redirect URL's + /// back to your app when login is completed. + /// + /// If authentication succeeds, `userId` and `secret` of a token will be + /// appended to the success URL as query parameters. These can be used to + /// create a new session using the [Create + /// session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future createOAuth2Token({required enums.OAuthProvider provider, String? success, String? failure, List<String>? scopes}) async { + final String apiPath = '/account/tokens/oauth2/{provider}'.replaceAll('{provider}', provider.value); + + final Map<String, dynamic> params = { + 'success': success, +'failure': failure, +'scopes': scopes, + + + 'project': client.config['project'], + }; + + final List query = []; + + params.forEach((key, value) { + if (value is List) { + for (var item in value) { + query.add(Uri.encodeComponent(key + '[]') + '=' + Uri.encodeComponent(item)); + } + } else if(value != null) { + query.add(Uri.encodeComponent(key) + '=' + Uri.encodeComponent(value)); + } + }); + + Uri endpoint = Uri.parse(client.endPoint); + Uri url = Uri(scheme: endpoint.scheme, + host: endpoint.host, + port: endpoint.port, + path: endpoint.path + apiPath, + query: query.join('&') + ); + + return client.webAuth(url); + } + + /// Create phone token + /// + /// Sends the user an SMS with a secret key for creating a session. If the + /// provided user ID has not be registered, a new user will be created. Use the + /// returned user ID and secret and submit a request to the [POST + /// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. The secret sent to the user's phone + /// is valid for 15 minutes. + /// + /// A user is limited to 10 active sessions at a time by default. [Learn more + /// about session + /// limits](https://appwrite.io/docs/authentication-security#limits). + Future<models.Token> createPhoneToken({required String userId, required String phone}) async { + final String apiPath = '/account/tokens/phone'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'phone': phone, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Create email verification + /// + /// Use this endpoint to send a verification message to your user email address + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). + /// 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<models.Token> createVerification({required String url}) async { + final String apiPath = '/account/verification'; + + final Map<String, dynamic> apiParams = { + + 'url': url, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Create email verification (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<models.Token> updateVerification({required String userId, required String secret}) async { + final String apiPath = '/account/verification'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// 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](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone) + /// endpoint. Learn more about how to [complete the verification + /// process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification). + /// The verification code sent to the user's phone number is valid for 15 + /// minutes. + Future<models.Token> createPhoneVerification() async { + final String apiPath = '/account/verification/phone'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Update 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<models.Token> updatePhoneVerification({required String userId, required String secret}) async { + final String apiPath = '/account/verification/phone'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 9c77eda6..4609b00b 100644 --- a/lib/services/avatars.dart +++ b/lib/services/avatars.dart @@ -3,209 +3,201 @@ part of '../dart_appwrite.dart'; /// The Avatars service aims to help you complete everyday tasks related to /// your app image, icons, and avatars. class Avatars extends Service { - Avatars(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](https://appwrite.io/docs/references/cloud/client-web/account#getSessions) - /// 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<Uint8List> getBrowser( - {required enums.Browser code, - int? width, - int? height, - int? quality}) async { - final String apiPath = - '/avatars/browsers/{code}'.replaceAll('{code}', code.value); - - final Map<String, dynamic> params = { - 'width': width, - 'height': height, - 'quality': quality, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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<Uint8List> getCreditCard( - {required enums.CreditCard code, - int? width, - int? height, - int? quality}) async { - final String apiPath = - '/avatars/credit-cards/{code}'.replaceAll('{code}', code.value); - - final Map<String, dynamic> params = { - 'width': width, - 'height': height, - 'quality': quality, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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. - /// - /// This endpoint does not follow HTTP redirects. - Future<Uint8List> getFavicon({required String url}) async { - final String apiPath = '/avatars/favicon'; - - final Map<String, dynamic> params = { - 'url': url, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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. Country codes - /// follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard. - /// - /// 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<Uint8List> getFlag( - {required enums.Flag code, int? width, int? height, int? quality}) async { - final String apiPath = - '/avatars/flags/{code}'.replaceAll('{code}', code.value); - - final Map<String, dynamic> params = { - 'width': width, - 'height': height, - 'quality': quality, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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. - /// - /// This endpoint does not follow HTTP redirects. - Future<Uint8List> getImage( - {required String url, int? width, int? height}) async { - final String apiPath = '/avatars/image'; - - final Map<String, dynamic> params = { - 'url': url, - 'width': width, - 'height': height, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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<Uint8List> getInitials( - {String? name, int? width, int? height, String? background}) async { - final String apiPath = '/avatars/initials'; - - final Map<String, dynamic> params = { - 'name': name, - 'width': width, - 'height': height, - 'background': background, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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<Uint8List> getQR( - {required String text, int? size, int? margin, bool? download}) async { - final String apiPath = '/avatars/qr'; - - final Map<String, dynamic> params = { - 'text': text, - 'size': size, - 'margin': margin, - 'download': download, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: params, responseType: ResponseType.bytes); - return res.data; - } -} + Avatars(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](https://appwrite.io/docs/references/cloud/client-web/account#getSessions) + /// 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<Uint8List> getBrowser({required enums.Browser code, int? width, int? height, int? quality}) async { + final String apiPath = '/avatars/browsers/{code}'.replaceAll('{code}', code.value); + + final Map<String, dynamic> params = { + 'width': width, +'height': height, +'quality': quality, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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<Uint8List> getCreditCard({required enums.CreditCard code, int? width, int? height, int? quality}) async { + final String apiPath = '/avatars/credit-cards/{code}'.replaceAll('{code}', code.value); + + final Map<String, dynamic> params = { + 'width': width, +'height': height, +'quality': quality, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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. + /// + /// This endpoint does not follow HTTP redirects. + Future<Uint8List> getFavicon({required String url}) async { + final String apiPath = '/avatars/favicon'; + + final Map<String, dynamic> params = { + 'url': url, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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. Country codes + /// follow the [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) standard. + /// + /// 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<Uint8List> getFlag({required enums.Flag code, int? width, int? height, int? quality}) async { + final String apiPath = '/avatars/flags/{code}'.replaceAll('{code}', code.value); + + final Map<String, dynamic> params = { + 'width': width, +'height': height, +'quality': quality, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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. + /// + /// This endpoint does not follow HTTP redirects. + Future<Uint8List> getImage({required String url, int? width, int? height}) async { + final String apiPath = '/avatars/image'; + + final Map<String, dynamic> params = { + 'url': url, +'width': width, +'height': height, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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<Uint8List> getInitials({String? name, int? width, int? height, String? background}) async { + final String apiPath = '/avatars/initials'; + + final Map<String, dynamic> params = { + 'name': name, +'width': width, +'height': height, +'background': background, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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<Uint8List> getQR({required String text, int? size, int? margin, bool? download}) async { + final String apiPath = '/avatars/qr'; + + final Map<String, dynamic> params = { + 'text': text, +'size': size, +'margin': margin, +'download': download, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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 5d3a8c86..6d74eb4b 100644 --- a/lib/services/databases.dart +++ b/lib/services/databases.dart @@ -3,1280 +3,1093 @@ part of '../dart_appwrite.dart'; /// The Databases service allows you to create structured collections of /// documents, query and filter lists of documents class Databases extends Service { - Databases(super.client); - - /// List databases - /// - /// Get a list of all databases from the current Appwrite project. You can use - /// the search parameter to filter your results. - Future<models.DatabaseList> list( - {List<String>? queries, String? search}) async { - final String apiPath = '/databases'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.DatabaseList.fromMap(res.data); - } - - /// Create database - /// - /// Create a new Database. - /// - Future<models.Database> create( - {required String databaseId, required String name, bool? enabled}) async { - final String apiPath = '/databases'; - - final Map<String, dynamic> apiParams = { - 'databaseId': databaseId, - 'name': name, - 'enabled': enabled, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Database.fromMap(res.data); - } - - /// Get database - /// - /// Get a database by its unique ID. This endpoint response returns a JSON - /// object with the database metadata. - Future<models.Database> get({required String databaseId}) async { - final String apiPath = - '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Database.fromMap(res.data); - } - - /// Update database - /// - /// Update a database by its unique ID. - Future<models.Database> update( - {required String databaseId, required String name, bool? enabled}) async { - final String apiPath = - '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); - - final Map<String, dynamic> apiParams = { - 'name': name, - 'enabled': enabled, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Database.fromMap(res.data); - } - - /// Delete database - /// - /// Delete a database by its unique ID. Only API keys with with databases.write - /// scope can delete a database. - Future delete({required String databaseId}) async { - final String apiPath = - '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List collections - /// - /// Get a list of all collections that belong to the provided databaseId. You - /// can use the search parameter to filter your results. - Future<models.CollectionList> listCollections( - {required String databaseId, - List<String>? queries, - String? search}) async { - final String apiPath = '/databases/{databaseId}/collections' - .replaceAll('{databaseId}', databaseId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.CollectionList.fromMap(res.data); - } - - /// Create collection - /// - /// Create a new Collection. Before using this route, you should create a new - /// database resource using either a [server - /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) - /// API or directly from your database console. - Future<models.Collection> createCollection( - {required String databaseId, - required String collectionId, - required String name, - List<String>? permissions, - bool? documentSecurity, - bool? enabled}) async { - final String apiPath = '/databases/{databaseId}/collections' - .replaceAll('{databaseId}', databaseId); - - final Map<String, dynamic> apiParams = { - 'collectionId': collectionId, - 'name': name, - 'permissions': permissions, - 'documentSecurity': documentSecurity, - 'enabled': enabled, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Collection.fromMap(res.data); - } - - /// Get collection - /// - /// Get a collection by its unique ID. This endpoint response returns a JSON - /// object with the collection metadata. - Future<models.Collection> getCollection( - {required String databaseId, required String collectionId}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Collection.fromMap(res.data); - } - - /// Update collection - /// - /// Update a collection by its unique ID. - Future<models.Collection> updateCollection( - {required String databaseId, - required String collectionId, - required String name, - List<String>? permissions, - bool? documentSecurity, - bool? enabled}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'name': name, - 'permissions': permissions, - 'documentSecurity': documentSecurity, - 'enabled': enabled, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Collection.fromMap(res.data); - } - - /// Delete collection - /// - /// Delete a collection by its unique ID. Only users with write permissions - /// have access to delete this resource. - Future deleteCollection( - {required String databaseId, required String collectionId}) async { - final String apiPath = '/databases/{databaseId}/collections/{collectionId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List attributes - /// - /// List attributes in the collection. - Future<models.AttributeList> listAttributes( - {required String databaseId, - required String collectionId, - List<String>? queries}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeList.fromMap(res.data); - } - - /// Create boolean attribute - /// - /// Create a boolean attribute. - /// - Future<models.AttributeBoolean> createBooleanAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - bool? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/boolean' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'key': key, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeBoolean.fromMap(res.data); - } - - /// Update boolean attribute - /// - /// Update a boolean attribute. Changing the `default` value will not update - /// already existing documents. - Future<models.AttributeBoolean> updateBooleanAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required bool? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/boolean/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeBoolean.fromMap(res.data); - } - - /// Create datetime attribute - /// - /// Create a date time attribute according to the ISO 8601 standard. - Future<models.AttributeDatetime> createDatetimeAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - String? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/datetime' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'key': key, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeDatetime.fromMap(res.data); - } - - /// Update dateTime attribute - /// - /// Update a date time attribute. Changing the `default` value will not update - /// already existing documents. - Future<models.AttributeDatetime> updateDatetimeAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required String? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/datetime/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeDatetime.fromMap(res.data); - } - - /// Create email attribute - /// - /// Create an email attribute. - /// - Future<models.AttributeEmail> createEmailAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - String? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/email' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'key': key, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEmail.fromMap(res.data); - } - - /// Update email attribute - /// - /// Update an email attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future<models.AttributeEmail> updateEmailAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required String? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/email/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEmail.fromMap(res.data); - } - - /// Create enum attribute - /// - /// Create an enumeration attribute. The `elements` param acts as a white-list - /// of accepted values for this attribute. - /// - Future<models.AttributeEnum> createEnumAttribute( - {required String databaseId, - required String collectionId, - required String key, - required List<String> elements, - required bool xrequired, - String? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/enum' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'key': key, - 'elements': elements, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEnum.fromMap(res.data); - } - - /// Update enum attribute - /// - /// Update an enum attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future<models.AttributeEnum> updateEnumAttribute( - {required String databaseId, - required String collectionId, - required String key, - required List<String> elements, - required bool xrequired, - required String? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/enum/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - 'elements': elements, - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeEnum.fromMap(res.data); - } - - /// Create float attribute - /// - /// Create a float attribute. Optionally, minimum and maximum values can be - /// provided. - /// - Future<models.AttributeFloat> createFloatAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - double? min, - double? max, - double? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/float' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'key': key, - 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, - 'array': array, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeFloat.fromMap(res.data); - } - - /// Update float attribute - /// - /// Update a float attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future<models.AttributeFloat> updateFloatAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required double min, - required double max, - required double? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/float/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeFloat.fromMap(res.data); - } - - /// Create integer attribute - /// - /// Create an integer attribute. Optionally, minimum and maximum values can be - /// provided. - /// - Future<models.AttributeInteger> createIntegerAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - int? min, - int? max, - int? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/integer' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'key': key, - 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, - 'array': array, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeInteger.fromMap(res.data); - } - - /// Update integer attribute - /// - /// Update an integer attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future<models.AttributeInteger> updateIntegerAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required int min, - required int max, - required int? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/integer/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - 'required': xrequired, - 'min': min, - 'max': max, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeInteger.fromMap(res.data); - } - - /// Create IP address attribute - /// - /// Create IP address attribute. - /// - Future<models.AttributeIp> createIpAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - String? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/ip' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'key': key, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeIp.fromMap(res.data); - } - - /// Update IP address attribute - /// - /// Update an ip attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future<models.AttributeIp> updateIpAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required String? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/ip/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeIp.fromMap(res.data); - } - - /// Create relationship attribute - /// - /// Create relationship attribute. [Learn more about relationship - /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). - /// - Future<models.AttributeRelationship> createRelationshipAttribute( - {required String databaseId, - required String collectionId, - required String relatedCollectionId, - required enums.RelationshipType type, - bool? twoWay, - String? key, - String? twoWayKey, - enums.RelationMutate? onDelete}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/relationship' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'relatedCollectionId': relatedCollectionId, - 'type': type.value, - 'twoWay': twoWay, - 'key': key, - 'twoWayKey': twoWayKey, - 'onDelete': onDelete?.value, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeRelationship.fromMap(res.data); - } - - /// Create string attribute - /// - /// Create a string attribute. - /// - Future<models.AttributeString> createStringAttribute( - {required String databaseId, - required String collectionId, - required String key, - required int size, - required bool xrequired, - String? xdefault, - bool? array, - bool? encrypt}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/string' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'key': key, - 'size': size, - 'required': xrequired, - 'default': xdefault, - 'array': array, - 'encrypt': encrypt, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeString.fromMap(res.data); - } - - /// Update string attribute - /// - /// Update a string attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future<models.AttributeString> updateStringAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required String? xdefault, - int? size, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/string/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - 'required': xrequired, - 'default': xdefault, - 'size': size, - 'newKey': newKey, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeString.fromMap(res.data); - } - - /// Create URL attribute - /// - /// Create a URL attribute. - /// - Future<models.AttributeUrl> createUrlAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - String? xdefault, - bool? array}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/url' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'key': key, - 'required': xrequired, - 'default': xdefault, - 'array': array, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeUrl.fromMap(res.data); - } - - /// Update URL attribute - /// - /// Update an url attribute. Changing the `default` value will not update - /// already existing documents. - /// - Future<models.AttributeUrl> updateUrlAttribute( - {required String databaseId, - required String collectionId, - required String key, - required bool xrequired, - required String? xdefault, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/url/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - 'required': xrequired, - 'default': xdefault, - 'newKey': newKey, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeUrl.fromMap(res.data); - } - - /// Get attribute - /// - /// Get attribute by ID. - Future getAttribute( - {required String databaseId, - required String collectionId, - required String key}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Delete attribute - /// - /// Deletes an attribute. - Future deleteAttribute( - {required String databaseId, - required String collectionId, - required String key}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Update relationship attribute - /// - /// Update relationship attribute. [Learn more about relationship - /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). - /// - Future<models.AttributeRelationship> updateRelationshipAttribute( - {required String databaseId, - required String collectionId, - required String key, - enums.RelationMutate? onDelete, - String? newKey}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/attributes/{key}/relationship' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = { - 'onDelete': onDelete?.value, - 'newKey': newKey, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.AttributeRelationship.fromMap(res.data); - } - - /// List documents - /// - /// Get a list of all the user's documents in a given collection. You can use - /// the query params to filter your results. - Future<models.DocumentList> listDocuments( - {required String databaseId, - required String collectionId, - List<String>? queries}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/documents' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.DocumentList.fromMap(res.data); - } - - /// Create document - /// - /// Create a new Document. Before using this route, you should create a new - /// collection resource using either a [server - /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) - /// API or directly from your database console. - Future<models.Document> createDocument( - {required String databaseId, - required String collectionId, - required String documentId, - required Map data, - List<String>? permissions}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/documents' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'documentId': documentId, - 'data': data, - 'permissions': permissions, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Document.fromMap(res.data); - } - - /// Get document - /// - /// Get a document by its unique ID. This endpoint response returns a JSON - /// object with the document data. - Future<models.Document> getDocument( - {required String databaseId, - required String collectionId, - required String documentId, - List<String>? queries}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{documentId}', documentId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Document.fromMap(res.data); - } - - /// Update document - /// - /// Update a document by its unique ID. Using the patch method you can pass - /// only specific fields that will get updated. - Future<models.Document> updateDocument( - {required String databaseId, - required String collectionId, - required String documentId, - Map? data, - List<String>? permissions}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{documentId}', documentId); - - final Map<String, dynamic> apiParams = { - 'data': data, - 'permissions': permissions, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Document.fromMap(res.data); - } - - /// Delete document - /// - /// Delete a document by its unique ID. - Future deleteDocument( - {required String databaseId, - required String collectionId, - required String documentId}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{documentId}', documentId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List indexes - /// - /// List indexes in the collection. - Future<models.IndexList> listIndexes( - {required String databaseId, - required String collectionId, - List<String>? queries}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/indexes' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.IndexList.fromMap(res.data); - } - - /// Create index - /// - /// Creates an index on the attributes listed. Your index should include all - /// the attributes you will query in a single request. - /// Attributes can be `key`, `fulltext`, and `unique`. - Future<models.Index> createIndex( - {required String databaseId, - required String collectionId, - required String key, - required enums.IndexType type, - required List<String> attributes, - List<String>? orders}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/indexes' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId); - - final Map<String, dynamic> apiParams = { - 'key': key, - 'type': type.value, - 'attributes': attributes, - 'orders': orders, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Index.fromMap(res.data); - } - - /// Get index - /// - /// Get index by ID. - Future<models.Index> getIndex( - {required String databaseId, - required String collectionId, - required String key}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/indexes/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Index.fromMap(res.data); - } - - /// Delete index - /// - /// Delete an index. - Future deleteIndex( - {required String databaseId, - required String collectionId, - required String key}) async { - final String apiPath = - '/databases/{databaseId}/collections/{collectionId}/indexes/{key}' - .replaceAll('{databaseId}', databaseId) - .replaceAll('{collectionId}', collectionId) - .replaceAll('{key}', key); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } -} + Databases(super.client); + + /// List databases + /// + /// Get a list of all databases from the current Appwrite project. You can use + /// the search parameter to filter your results. + Future<models.DatabaseList> list({List<String>? queries, String? search}) async { + final String apiPath = '/databases'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DatabaseList.fromMap(res.data); + + } + + /// Create database + /// + /// Create a new Database. + /// + Future<models.Database> create({required String databaseId, required String name, bool? enabled}) async { + final String apiPath = '/databases'; + + final Map<String, dynamic> apiParams = { + + 'databaseId': databaseId, +'name': name, +'enabled': enabled, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Database.fromMap(res.data); + + } + + /// Get database + /// + /// Get a database by its unique ID. This endpoint response returns a JSON + /// object with the database metadata. + Future<models.Database> get({required String databaseId}) async { + final String apiPath = '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Database.fromMap(res.data); + + } + + /// Update database + /// + /// Update a database by its unique ID. + Future<models.Database> update({required String databaseId, required String name, bool? enabled}) async { + final String apiPath = '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); + + final Map<String, dynamic> apiParams = { + + 'name': name, +'enabled': enabled, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Database.fromMap(res.data); + + } + + /// Delete database + /// + /// Delete a database by its unique ID. Only API keys with with databases.write + /// scope can delete a database. + Future delete({required String databaseId}) async { + final String apiPath = '/databases/{databaseId}'.replaceAll('{databaseId}', databaseId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List collections + /// + /// Get a list of all collections that belong to the provided databaseId. You + /// can use the search parameter to filter your results. + Future<models.CollectionList> listCollections({required String databaseId, List<String>? queries, String? search}) async { + final String apiPath = '/databases/{databaseId}/collections'.replaceAll('{databaseId}', databaseId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.CollectionList.fromMap(res.data); + + } + + /// Create collection + /// + /// Create a new Collection. Before using this route, you should create a new + /// database resource using either a [server + /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) + /// API or directly from your database console. + Future<models.Collection> createCollection({required String databaseId, required String collectionId, required String name, List<String>? permissions, bool? documentSecurity, bool? enabled}) async { + final String apiPath = '/databases/{databaseId}/collections'.replaceAll('{databaseId}', databaseId); + + final Map<String, dynamic> apiParams = { + + 'collectionId': collectionId, +'name': name, +'permissions': permissions, +'documentSecurity': documentSecurity, +'enabled': enabled, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Collection.fromMap(res.data); + + } + + /// Get collection + /// + /// Get a collection by its unique ID. This endpoint response returns a JSON + /// object with the collection metadata. + Future<models.Collection> getCollection({required String databaseId, required String collectionId}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Collection.fromMap(res.data); + + } + + /// Update collection + /// + /// Update a collection by its unique ID. + Future<models.Collection> updateCollection({required String databaseId, required String collectionId, required String name, List<String>? permissions, bool? documentSecurity, bool? enabled}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + + 'name': name, +'permissions': permissions, +'documentSecurity': documentSecurity, +'enabled': enabled, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Collection.fromMap(res.data); + + } + + /// Delete collection + /// + /// Delete a collection by its unique ID. Only users with write permissions + /// have access to delete this resource. + Future deleteCollection({required String databaseId, required String collectionId}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List attributes + /// + /// List attributes in the collection. + Future<models.AttributeList> listAttributes({required String databaseId, required String collectionId, List<String>? queries}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeList.fromMap(res.data); + + } + + /// Create boolean attribute + /// + /// Create a boolean attribute. + /// + Future<models.AttributeBoolean> createBooleanAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, bool? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/boolean'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + + 'key': key, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeBoolean.fromMap(res.data); + + } + + /// Update boolean attribute + /// + /// Update a boolean attribute. Changing the `default` value will not update + /// already existing documents. + Future<models.AttributeBoolean> updateBooleanAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required bool? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/boolean/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + + 'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeBoolean.fromMap(res.data); + + } + + /// Create datetime attribute + /// + /// Create a date time attribute according to the ISO 8601 standard. + Future<models.AttributeDatetime> createDatetimeAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/datetime'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + + 'key': key, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeDatetime.fromMap(res.data); + + } + + /// Update dateTime attribute + /// + /// Update a date time attribute. Changing the `default` value will not update + /// already existing documents. + Future<models.AttributeDatetime> updateDatetimeAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/datetime/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + + 'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeDatetime.fromMap(res.data); + + } + + /// Create email attribute + /// + /// Create an email attribute. + /// + Future<models.AttributeEmail> createEmailAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/email'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + + 'key': key, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEmail.fromMap(res.data); + + } + + /// Update email attribute + /// + /// Update an email attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future<models.AttributeEmail> updateEmailAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/email/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + + 'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEmail.fromMap(res.data); + + } + + /// Create enum attribute + /// + /// Create an enumeration attribute. The `elements` param acts as a white-list + /// of accepted values for this attribute. + /// + Future<models.AttributeEnum> createEnumAttribute({required String databaseId, required String collectionId, required String key, required List<String> elements, required bool xrequired, String? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/enum'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + + 'key': key, +'elements': elements, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEnum.fromMap(res.data); + + } + + /// Update enum attribute + /// + /// Update an enum attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future<models.AttributeEnum> updateEnumAttribute({required String databaseId, required String collectionId, required String key, required List<String> elements, required bool xrequired, required String? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/enum/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + + 'elements': elements, +'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeEnum.fromMap(res.data); + + } + + /// Create float attribute + /// + /// Create a float attribute. Optionally, minimum and maximum values can be + /// provided. + /// + Future<models.AttributeFloat> createFloatAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, double? min, double? max, double? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/float'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + + 'key': key, +'required': xrequired, +'min': min, +'max': max, +'default': xdefault, +'array': array, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeFloat.fromMap(res.data); + + } + + /// Update float attribute + /// + /// Update a float attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future<models.AttributeFloat> updateFloatAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required double min, required double max, required double? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/float/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + + 'required': xrequired, +'min': min, +'max': max, +'default': xdefault, +'newKey': newKey, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeFloat.fromMap(res.data); + + } + + /// Create integer attribute + /// + /// Create an integer attribute. Optionally, minimum and maximum values can be + /// provided. + /// + Future<models.AttributeInteger> createIntegerAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, int? min, int? max, int? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/integer'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + + 'key': key, +'required': xrequired, +'min': min, +'max': max, +'default': xdefault, +'array': array, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeInteger.fromMap(res.data); + + } + + /// Update integer attribute + /// + /// Update an integer attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future<models.AttributeInteger> updateIntegerAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required int min, required int max, required int? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/integer/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + + 'required': xrequired, +'min': min, +'max': max, +'default': xdefault, +'newKey': newKey, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeInteger.fromMap(res.data); + + } + + /// Create IP address attribute + /// + /// Create IP address attribute. + /// + Future<models.AttributeIp> createIpAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/ip'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + + 'key': key, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeIp.fromMap(res.data); + + } + + /// Update IP address attribute + /// + /// Update an ip attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future<models.AttributeIp> updateIpAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/ip/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + + 'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeIp.fromMap(res.data); + + } + + /// Create relationship attribute + /// + /// Create relationship attribute. [Learn more about relationship + /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). + /// + Future<models.AttributeRelationship> createRelationshipAttribute({required String databaseId, required String collectionId, required String relatedCollectionId, required enums.RelationshipType type, bool? twoWay, String? key, String? twoWayKey, enums.RelationMutate? onDelete}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/relationship'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + + 'relatedCollectionId': relatedCollectionId, +'type': type.value, +'twoWay': twoWay, +'key': key, +'twoWayKey': twoWayKey, +'onDelete': onDelete?.value, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeRelationship.fromMap(res.data); + + } + + /// Create string attribute + /// + /// Create a string attribute. + /// + Future<models.AttributeString> createStringAttribute({required String databaseId, required String collectionId, required String key, required int size, required bool xrequired, String? xdefault, bool? array, bool? encrypt}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/string'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + + 'key': key, +'size': size, +'required': xrequired, +'default': xdefault, +'array': array, +'encrypt': encrypt, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeString.fromMap(res.data); + + } + + /// Update string attribute + /// + /// Update a string attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future<models.AttributeString> updateStringAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, int? size, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/string/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + + 'required': xrequired, +'default': xdefault, +'size': size, +'newKey': newKey, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeString.fromMap(res.data); + + } + + /// Create URL attribute + /// + /// Create a URL attribute. + /// + Future<models.AttributeUrl> createUrlAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, String? xdefault, bool? array}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/url'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + + 'key': key, +'required': xrequired, +'default': xdefault, +'array': array, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeUrl.fromMap(res.data); + + } + + /// Update URL attribute + /// + /// Update an url attribute. Changing the `default` value will not update + /// already existing documents. + /// + Future<models.AttributeUrl> updateUrlAttribute({required String databaseId, required String collectionId, required String key, required bool xrequired, required String? xdefault, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/url/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + + 'required': xrequired, +'default': xdefault, +'newKey': newKey, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeUrl.fromMap(res.data); + + } + + /// Get attribute + /// + /// Get attribute by ID. + Future getAttribute({required String databaseId, required String collectionId, required String key}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Delete attribute + /// + /// Deletes an attribute. + Future deleteAttribute({required String databaseId, required String collectionId, required String key}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Update relationship attribute + /// + /// Update relationship attribute. [Learn more about relationship + /// attributes](https://appwrite.io/docs/databases-relationships#relationship-attributes). + /// + Future<models.AttributeRelationship> updateRelationshipAttribute({required String databaseId, required String collectionId, required String key, enums.RelationMutate? onDelete, String? newKey}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}/relationship'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + + 'onDelete': onDelete?.value, +'newKey': newKey, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.AttributeRelationship.fromMap(res.data); + + } + + /// List documents + /// + /// Get a list of all the user's documents in a given collection. You can use + /// the query params to filter your results. + Future<models.DocumentList> listDocuments({required String databaseId, required String collectionId, List<String>? queries}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DocumentList.fromMap(res.data); + + } + + /// Create document + /// + /// Create a new Document. Before using this route, you should create a new + /// collection resource using either a [server + /// integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) + /// API or directly from your database console. + Future<models.Document> createDocument({required String databaseId, required String collectionId, required String documentId, required Map data, List<String>? permissions}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + + 'documentId': documentId, +'data': data, +'permissions': permissions, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Document.fromMap(res.data); + + } + + /// Get document + /// + /// Get a document by its unique ID. This endpoint response returns a JSON + /// object with the document data. + Future<models.Document> getDocument({required String databaseId, required String collectionId, required String documentId, List<String>? queries}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Document.fromMap(res.data); + + } + + /// Update document + /// + /// Update a document by its unique ID. Using the patch method you can pass + /// only specific fields that will get updated. + Future<models.Document> updateDocument({required String databaseId, required String collectionId, required String documentId, Map? data, List<String>? permissions}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); + + final Map<String, dynamic> apiParams = { + + 'data': data, +'permissions': permissions, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Document.fromMap(res.data); + + } + + /// Delete document + /// + /// Delete a document by its unique ID. + Future deleteDocument({required String databaseId, required String collectionId, required String documentId}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{documentId}', documentId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List indexes + /// + /// List indexes in the collection. + Future<models.IndexList> listIndexes({required String databaseId, required String collectionId, List<String>? queries}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.IndexList.fromMap(res.data); + + } + + /// Create index + /// + /// Creates an index on the attributes listed. Your index should include all + /// the attributes you will query in a single request. + /// Attributes can be `key`, `fulltext`, and `unique`. + Future<models.Index> createIndex({required String databaseId, required String collectionId, required String key, required enums.IndexType type, required List<String> attributes, List<String>? orders}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId); + + final Map<String, dynamic> apiParams = { + + 'key': key, +'type': type.value, +'attributes': attributes, +'orders': orders, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Index.fromMap(res.data); + + } + + /// Get index + /// + /// Get index by ID. + Future<models.Index> getIndex({required String databaseId, required String collectionId, required String key}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Index.fromMap(res.data); + + } + + /// Delete index + /// + /// Delete an index. + Future deleteIndex({required String databaseId, required String collectionId, required String key}) async { + final String apiPath = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replaceAll('{databaseId}', databaseId).replaceAll('{collectionId}', collectionId).replaceAll('{key}', key); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } +} \ No newline at end of file diff --git a/lib/services/functions.dart b/lib/services/functions.dart index 7a59547e..f1e7d0e3 100644 --- a/lib/services/functions.dart +++ b/lib/services/functions.dart @@ -3,649 +3,629 @@ part of '../dart_appwrite.dart'; /// The Functions Service allows you view, create and manage your Cloud /// Functions. class Functions extends Service { - Functions(super.client); - - /// List functions - /// - /// Get a list of all the project's functions. You can use the query params to - /// filter your results. - Future<models.FunctionList> list( - {List<String>? queries, String? search}) async { - final String apiPath = '/functions'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.FunctionList.fromMap(res.data); - } - - /// Create function - /// - /// Create a new function. You can pass a list of - /// [permissions](https://appwrite.io/docs/permissions) to allow different - /// project users or team with access to execute the function using the client - /// API. - Future<models.Func> create( - {required String functionId, - required String name, - required enums.Runtime runtime, - List<String>? execute, - List<String>? events, - String? schedule, - int? timeout, - bool? enabled, - bool? logging, - String? entrypoint, - String? commands, - List<String>? scopes, - String? installationId, - String? providerRepositoryId, - String? providerBranch, - bool? providerSilentMode, - String? providerRootDirectory, - String? templateRepository, - String? templateOwner, - String? templateRootDirectory, - String? templateVersion, - String? specification}) async { - final String apiPath = '/functions'; - - final Map<String, dynamic> apiParams = { - 'functionId': functionId, - 'name': name, - 'runtime': runtime.value, - 'execute': execute, - 'events': events, - 'schedule': schedule, - 'timeout': timeout, - 'enabled': enabled, - 'logging': logging, - 'entrypoint': entrypoint, - 'commands': commands, - 'scopes': scopes, - 'installationId': installationId, - 'providerRepositoryId': providerRepositoryId, - 'providerBranch': providerBranch, - 'providerSilentMode': providerSilentMode, - 'providerRootDirectory': providerRootDirectory, - 'templateRepository': templateRepository, - 'templateOwner': templateOwner, - 'templateRootDirectory': templateRootDirectory, - 'templateVersion': templateVersion, - 'specification': specification, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - } - - /// List runtimes - /// - /// Get a list of all runtimes that are currently active on your instance. - Future<models.RuntimeList> listRuntimes() async { - final String apiPath = '/functions/runtimes'; - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.RuntimeList.fromMap(res.data); - } - - /// List available function runtime specifications - /// - /// List allowed function specifications for this instance. - /// - Future<models.SpecificationList> listSpecifications() async { - final String apiPath = '/functions/specifications'; - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SpecificationList.fromMap(res.data); - } - - /// Get function - /// - /// Get a function by its unique ID. - Future<models.Func> get({required String functionId}) async { - final String apiPath = - '/functions/{functionId}'.replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - } - - /// Update function - /// - /// Update function by its unique ID. - Future<models.Func> update( - {required String functionId, - required String name, - enums.Runtime? runtime, - List<String>? execute, - List<String>? events, - String? schedule, - int? timeout, - bool? enabled, - bool? logging, - String? entrypoint, - String? commands, - List<String>? scopes, - String? installationId, - String? providerRepositoryId, - String? providerBranch, - bool? providerSilentMode, - String? providerRootDirectory, - String? specification}) async { - final String apiPath = - '/functions/{functionId}'.replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = { - 'name': name, - 'runtime': runtime?.value, - 'execute': execute, - 'events': events, - 'schedule': schedule, - 'timeout': timeout, - 'enabled': enabled, - 'logging': logging, - 'entrypoint': entrypoint, - 'commands': commands, - 'scopes': scopes, - 'installationId': installationId, - 'providerRepositoryId': providerRepositoryId, - 'providerBranch': providerBranch, - 'providerSilentMode': providerSilentMode, - 'providerRootDirectory': providerRootDirectory, - 'specification': specification, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - } - - /// Delete function - /// - /// Delete a function by its unique ID. - Future delete({required String functionId}) async { - final String apiPath = - '/functions/{functionId}'.replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List deployments - /// - /// Get a list of all the project's code deployments. You can use the query - /// params to filter your results. - Future<models.DeploymentList> listDeployments( - {required String functionId, - List<String>? queries, - String? search}) async { - final String apiPath = '/functions/{functionId}/deployments' - .replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.DeploymentList.fromMap(res.data); - } - - /// Create deployment - /// - /// Create a new function code deployment. Use this endpoint to upload a new - /// version of your code function. To execute your newly uploaded code, you'll - /// need to update the function's deployment to use your new deployment UID. - /// - /// This endpoint accepts a tar.gz file compressed with your code. Make sure to - /// include any dependencies your code has within the compressed file. You can - /// learn more about code packaging in the [Appwrite Cloud Functions - /// tutorial](https://appwrite.io/docs/functions). - /// - /// Use the "command" param to set the entrypoint used to execute your code. - Future<models.Deployment> createDeployment( - {required String functionId, - required InputFile code, - required bool activate, - String? entrypoint, - String? commands, - Function(UploadProgress)? onProgress}) async { - final String apiPath = '/functions/{functionId}/deployments' - .replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = { - 'entrypoint': entrypoint, - 'commands': commands, - 'code': code, - 'activate': activate, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'multipart/form-data', - }; - - String idParamName = ''; - final paramName = 'code'; - final res = await client.chunkedUpload( - path: apiPath, - params: apiParams, - paramName: paramName, - idParamName: idParamName, - headers: apiHeaders, - onProgress: onProgress, - ); - - return models.Deployment.fromMap(res.data); - } - - /// Get deployment - /// - /// Get a code deployment by its unique ID. - Future<models.Deployment> getDeployment( - {required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Deployment.fromMap(res.data); - } - - /// Update deployment - /// - /// Update the function code deployment ID using the unique function ID. Use - /// this endpoint to switch the code deployment that should be executed by the - /// execution endpoint. - Future<models.Func> updateDeployment( - {required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Func.fromMap(res.data); - } - - /// Delete deployment - /// - /// Delete a code deployment by its unique ID. - Future deleteDeployment( - {required String functionId, required String deploymentId}) async { - final String apiPath = '/functions/{functionId}/deployments/{deploymentId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Rebuild deployment - /// - Future createBuild( - {required String functionId, - required String deploymentId, - String? buildId}) async { - final String apiPath = - '/functions/{functionId}/deployments/{deploymentId}/build' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map<String, dynamic> apiParams = { - 'buildId': buildId, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Cancel deployment - /// - Future<models.Build> updateDeploymentBuild( - {required String functionId, required String deploymentId}) async { - final String apiPath = - '/functions/{functionId}/deployments/{deploymentId}/build' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Build.fromMap(res.data); - } - - /// Download deployment - /// - /// Get a Deployment's contents by its unique ID. This endpoint supports range - /// requests for partial or streaming file download. - Future<Uint8List> getDeploymentDownload( - {required String functionId, required String deploymentId}) async { - final String apiPath = - '/functions/{functionId}/deployments/{deploymentId}/download' - .replaceAll('{functionId}', functionId) - .replaceAll('{deploymentId}', deploymentId); - - final Map<String, dynamic> params = { - 'project': client.config['project'], - 'key': client.config['key'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: params, responseType: ResponseType.bytes); - 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. - Future<models.ExecutionList> listExecutions( - {required String functionId, - List<String>? queries, - String? search}) async { - final String apiPath = '/functions/{functionId}/executions' - .replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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<models.Execution> createExecution( - {required String functionId, - String? body, - bool? xasync, - String? path, - enums.ExecutionMethod? method, - Map? headers, - String? scheduledAt}) async { - final String apiPath = '/functions/{functionId}/executions' - .replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = { - 'body': body, - 'async': xasync, - 'path': path, - 'method': method?.value, - 'headers': headers, - 'scheduledAt': scheduledAt, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Execution.fromMap(res.data); - } - - /// Get execution - /// - /// Get a function execution log by its unique ID. - Future<models.Execution> getExecution( - {required String functionId, required String executionId}) async { - final String apiPath = '/functions/{functionId}/executions/{executionId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{executionId}', executionId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Execution.fromMap(res.data); - } - - /// Delete execution - /// - /// Delete a function execution by its unique ID. - /// - Future deleteExecution( - {required String functionId, required String executionId}) async { - final String apiPath = '/functions/{functionId}/executions/{executionId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{executionId}', executionId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List variables - /// - /// Get a list of all variables of a specific function. - Future<models.VariableList> listVariables( - {required String functionId}) async { - final String apiPath = '/functions/{functionId}/variables' - .replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.VariableList.fromMap(res.data); - } - - /// Create variable - /// - /// Create a new function environment variable. These variables can be accessed - /// in the function at runtime as environment variables. - Future<models.Variable> createVariable( - {required String functionId, - required String key, - required String value}) async { - final String apiPath = '/functions/{functionId}/variables' - .replaceAll('{functionId}', functionId); - - final Map<String, dynamic> apiParams = { - 'key': key, - 'value': value, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Variable.fromMap(res.data); - } - - /// Get variable - /// - /// Get a variable by its unique ID. - Future<models.Variable> getVariable( - {required String functionId, required String variableId}) async { - final String apiPath = '/functions/{functionId}/variables/{variableId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{variableId}', variableId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Variable.fromMap(res.data); - } - - /// Update variable - /// - /// Update variable by its unique ID. - Future<models.Variable> updateVariable( - {required String functionId, - required String variableId, - required String key, - String? value}) async { - final String apiPath = '/functions/{functionId}/variables/{variableId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{variableId}', variableId); - - final Map<String, dynamic> apiParams = { - 'key': key, - 'value': value, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Variable.fromMap(res.data); - } - - /// Delete variable - /// - /// Delete a variable by its unique ID. - Future deleteVariable( - {required String functionId, required String variableId}) async { - final String apiPath = '/functions/{functionId}/variables/{variableId}' - .replaceAll('{functionId}', functionId) - .replaceAll('{variableId}', variableId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } -} + Functions(super.client); + + /// List functions + /// + /// Get a list of all the project's functions. You can use the query params to + /// filter your results. + Future<models.FunctionList> list({List<String>? queries, String? search}) async { + final String apiPath = '/functions'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.FunctionList.fromMap(res.data); + + } + + /// Create function + /// + /// Create a new function. You can pass a list of + /// [permissions](https://appwrite.io/docs/permissions) to allow different + /// project users or team with access to execute the function using the client + /// API. + Future<models.Func> create({required String functionId, required String name, required enums.Runtime runtime, List<String>? execute, List<String>? events, String? schedule, int? timeout, bool? enabled, bool? logging, String? entrypoint, String? commands, List<String>? scopes, String? installationId, String? providerRepositoryId, String? providerBranch, bool? providerSilentMode, String? providerRootDirectory, String? templateRepository, String? templateOwner, String? templateRootDirectory, String? templateVersion, String? specification}) async { + final String apiPath = '/functions'; + + final Map<String, dynamic> apiParams = { + + 'functionId': functionId, +'name': name, +'runtime': runtime.value, +'execute': execute, +'events': events, +'schedule': schedule, +'timeout': timeout, +'enabled': enabled, +'logging': logging, +'entrypoint': entrypoint, +'commands': commands, +'scopes': scopes, +'installationId': installationId, +'providerRepositoryId': providerRepositoryId, +'providerBranch': providerBranch, +'providerSilentMode': providerSilentMode, +'providerRootDirectory': providerRootDirectory, +'templateRepository': templateRepository, +'templateOwner': templateOwner, +'templateRootDirectory': templateRootDirectory, +'templateVersion': templateVersion, +'specification': specification, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + + } + + /// List runtimes + /// + /// Get a list of all runtimes that are currently active on your instance. + Future<models.RuntimeList> listRuntimes() async { + final String apiPath = '/functions/runtimes'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.RuntimeList.fromMap(res.data); + + } + + /// List available function runtime specifications + /// + /// List allowed function specifications for this instance. + /// + Future<models.SpecificationList> listSpecifications() async { + final String apiPath = '/functions/specifications'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SpecificationList.fromMap(res.data); + + } + + /// Get function + /// + /// Get a function by its unique ID. + Future<models.Func> get({required String functionId}) async { + final String apiPath = '/functions/{functionId}'.replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + + } + + /// Update function + /// + /// Update function by its unique ID. + Future<models.Func> update({required String functionId, required String name, enums.Runtime? runtime, List<String>? execute, List<String>? events, String? schedule, int? timeout, bool? enabled, bool? logging, String? entrypoint, String? commands, List<String>? scopes, String? installationId, String? providerRepositoryId, String? providerBranch, bool? providerSilentMode, String? providerRootDirectory, String? specification}) async { + final String apiPath = '/functions/{functionId}'.replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = { + + 'name': name, +'runtime': runtime?.value, +'execute': execute, +'events': events, +'schedule': schedule, +'timeout': timeout, +'enabled': enabled, +'logging': logging, +'entrypoint': entrypoint, +'commands': commands, +'scopes': scopes, +'installationId': installationId, +'providerRepositoryId': providerRepositoryId, +'providerBranch': providerBranch, +'providerSilentMode': providerSilentMode, +'providerRootDirectory': providerRootDirectory, +'specification': specification, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + + } + + /// Delete function + /// + /// Delete a function by its unique ID. + Future delete({required String functionId}) async { + final String apiPath = '/functions/{functionId}'.replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List deployments + /// + /// Get a list of all the project's code deployments. You can use the query + /// params to filter your results. + Future<models.DeploymentList> listDeployments({required String functionId, List<String>? queries, String? search}) async { + final String apiPath = '/functions/{functionId}/deployments'.replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.DeploymentList.fromMap(res.data); + + } + + /// Create deployment + /// + /// Create a new function code deployment. Use this endpoint to upload a new + /// version of your code function. To execute your newly uploaded code, you'll + /// need to update the function's deployment to use your new deployment UID. + /// + /// This endpoint accepts a tar.gz file compressed with your code. Make sure to + /// include any dependencies your code has within the compressed file. You can + /// learn more about code packaging in the [Appwrite Cloud Functions + /// tutorial](https://appwrite.io/docs/functions). + /// + /// Use the "command" param to set the entrypoint used to execute your code. + Future<models.Deployment> createDeployment({required String functionId, required InputFile code, required bool activate, String? entrypoint, String? commands, Function(UploadProgress)? onProgress}) async { + final String apiPath = '/functions/{functionId}/deployments'.replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = { + + 'entrypoint': entrypoint, +'commands': commands, +'code': code, +'activate': activate, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'multipart/form-data', + + }; + + String idParamName = ''; + final paramName = 'code'; + final res = await client.chunkedUpload( + path: apiPath, + params: apiParams, + paramName: paramName, + idParamName: idParamName, + headers: apiHeaders, + onProgress: onProgress, + ); + + return models.Deployment.fromMap(res.data); + + } + + /// Get deployment + /// + /// Get a code deployment by its unique ID. + Future<models.Deployment> getDeployment({required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Deployment.fromMap(res.data); + + } + + /// Update deployment + /// + /// Update the function code deployment ID using the unique function ID. Use + /// this endpoint to switch the code deployment that should be executed by the + /// execution endpoint. + Future<models.Func> updateDeployment({required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Func.fromMap(res.data); + + } + + /// Delete deployment + /// + /// Delete a code deployment by its unique ID. + Future deleteDeployment({required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Rebuild deployment + /// + /// Create a new build for an existing function deployment. This endpoint + /// allows you to rebuild a deployment with the updated function configuration, + /// including its entrypoint and build commands if they have been modified The + /// build process will be queued and executed asynchronously. The original + /// deployment's code will be preserved and used for the new build. + Future createBuild({required String functionId, required String deploymentId, String? buildId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}/build'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map<String, dynamic> apiParams = { + + 'buildId': buildId, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Cancel deployment + /// + /// Cancel an ongoing function deployment build. If the build is already in + /// progress, it will be stopped and marked as canceled. If the build hasn't + /// started yet, it will be marked as canceled without executing. You cannot + /// cancel builds that have already completed (status 'ready') or failed. The + /// response includes the final build status and details. + Future<models.Build> updateDeploymentBuild({required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}/build'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Build.fromMap(res.data); + + } + + /// Download deployment + /// + /// Get a Deployment's contents by its unique ID. This endpoint supports range + /// requests for partial or streaming file download. + Future<Uint8List> getDeploymentDownload({required String functionId, required String deploymentId}) async { + final String apiPath = '/functions/{functionId}/deployments/{deploymentId}/download'.replaceAll('{functionId}', functionId).replaceAll('{deploymentId}', deploymentId); + + final Map<String, dynamic> params = { + + + 'project': client.config['project'], + 'key': client.config['key'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: params, responseType: ResponseType.bytes); + 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. + Future<models.ExecutionList> listExecutions({required String functionId, List<String>? queries, String? search}) async { + final String apiPath = '/functions/{functionId}/executions'.replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + 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<models.Execution> createExecution({required String functionId, String? body, bool? xasync, String? path, enums.ExecutionMethod? method, Map? headers, String? scheduledAt}) async { + final String apiPath = '/functions/{functionId}/executions'.replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = { + + 'body': body, +'async': xasync, +'path': path, +'method': method?.value, +'headers': headers, +'scheduledAt': scheduledAt, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Execution.fromMap(res.data); + + } + + /// Get execution + /// + /// Get a function execution log by its unique ID. + Future<models.Execution> getExecution({required String functionId, required String executionId}) async { + final String apiPath = '/functions/{functionId}/executions/{executionId}'.replaceAll('{functionId}', functionId).replaceAll('{executionId}', executionId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Execution.fromMap(res.data); + + } + + /// Delete execution + /// + /// Delete a function execution by its unique ID. + /// + Future deleteExecution({required String functionId, required String executionId}) async { + final String apiPath = '/functions/{functionId}/executions/{executionId}'.replaceAll('{functionId}', functionId).replaceAll('{executionId}', executionId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List variables + /// + /// Get a list of all variables of a specific function. + Future<models.VariableList> listVariables({required String functionId}) async { + final String apiPath = '/functions/{functionId}/variables'.replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.VariableList.fromMap(res.data); + + } + + /// Create variable + /// + /// Create a new function environment variable. These variables can be accessed + /// in the function at runtime as environment variables. + Future<models.Variable> createVariable({required String functionId, required String key, required String value}) async { + final String apiPath = '/functions/{functionId}/variables'.replaceAll('{functionId}', functionId); + + final Map<String, dynamic> apiParams = { + + 'key': key, +'value': value, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Variable.fromMap(res.data); + + } + + /// Get variable + /// + /// Get a variable by its unique ID. + Future<models.Variable> getVariable({required String functionId, required String variableId}) async { + final String apiPath = '/functions/{functionId}/variables/{variableId}'.replaceAll('{functionId}', functionId).replaceAll('{variableId}', variableId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Variable.fromMap(res.data); + + } + + /// Update variable + /// + /// Update variable by its unique ID. + Future<models.Variable> updateVariable({required String functionId, required String variableId, required String key, String? value}) async { + final String apiPath = '/functions/{functionId}/variables/{variableId}'.replaceAll('{functionId}', functionId).replaceAll('{variableId}', variableId); + + final Map<String, dynamic> apiParams = { + + 'key': key, +'value': value, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Variable.fromMap(res.data); + + } + + /// Delete variable + /// + /// Delete a variable by its unique ID. + Future deleteVariable({required String functionId, required String variableId}) async { + final String apiPath = '/functions/{functionId}/variables/{variableId}'.replaceAll('{functionId}', functionId).replaceAll('{variableId}', variableId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } +} \ No newline at end of file diff --git a/lib/services/graphql.dart b/lib/services/graphql.dart index fdc1ae0b..be9d037b 100644 --- a/lib/services/graphql.dart +++ b/lib/services/graphql.dart @@ -3,47 +3,53 @@ part of '../dart_appwrite.dart'; /// The GraphQL API allows you to query and mutate your Appwrite server using /// GraphQL. class Graphql extends Service { - Graphql(super.client); - - /// GraphQL endpoint - /// - /// Execute a GraphQL mutation. - Future query({required Map query}) async { - final String apiPath = '/graphql'; - - final Map<String, dynamic> apiParams = { - 'query': query, - }; - - final Map<String, String> apiHeaders = { - 'x-sdk-graphql': 'true', - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// GraphQL endpoint - /// - /// Execute a GraphQL mutation. - Future mutation({required Map query}) async { - final String apiPath = '/graphql/mutation'; - - final Map<String, dynamic> apiParams = { - 'query': query, - }; - - final Map<String, String> apiHeaders = { - 'x-sdk-graphql': 'true', - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } -} + Graphql(super.client); + + /// GraphQL endpoint + /// + /// Execute a GraphQL mutation. + Future query({required Map query}) async { + final String apiPath = '/graphql'; + + final Map<String, dynamic> apiParams = { + + 'query': query, + + }; + + final Map<String, String> apiHeaders = { + 'x-sdk-graphql': 'true', +'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// GraphQL endpoint + /// + /// Execute a GraphQL mutation. + Future mutation({required Map query}) async { + final String apiPath = '/graphql/mutation'; + + final Map<String, dynamic> apiParams = { + + 'query': query, + + }; + + final Map<String, String> apiHeaders = { + 'x-sdk-graphql': 'true', +'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } +} \ No newline at end of file diff --git a/lib/services/health.dart b/lib/services/health.dart index 121083c0..4e7b4603 100644 --- a/lib/services/health.dart +++ b/lib/services/health.dart @@ -3,473 +3,548 @@ part of '../dart_appwrite.dart'; /// The Health service allows you to both validate and monitor your Appwrite /// server's health. class Health extends Service { - Health(super.client); + Health(super.client); - /// Get HTTP - /// - /// Check the Appwrite HTTP server is up and responsive. - Future<models.HealthStatus> get() async { - final String apiPath = '/health'; + /// Get HTTP + /// + /// Check the Appwrite HTTP server is up and responsive. + Future<models.HealthStatus> get() async { + final String apiPath = '/health'; - final Map<String, dynamic> apiParams = {}; + final Map<String, dynamic> apiParams = { + + + }; - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + }; - return models.HealthStatus.fromMap(res.data); - } + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - /// Get antivirus - /// - /// Check the Appwrite Antivirus server is up and connection is successful. - Future<models.HealthAntivirus> getAntivirus() async { - final String apiPath = '/health/anti-virus'; + return models.HealthStatus.fromMap(res.data); - final Map<String, dynamic> apiParams = {}; + } - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; + /// Get antivirus + /// + /// Check the Appwrite Antivirus server is up and connection is successful. + Future<models.HealthAntivirus> getAntivirus() async { + final String apiPath = '/health/anti-virus'; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + final Map<String, dynamic> apiParams = { + + + }; - return models.HealthAntivirus.fromMap(res.data); - } + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', - /// Get cache - /// - /// Check the Appwrite in-memory cache servers are up and connection is - /// successful. - Future<models.HealthStatus> getCache() async { - final String apiPath = '/health/cache'; + }; - final Map<String, dynamic> apiParams = {}; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; + return models.HealthAntivirus.fromMap(res.data); - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + } - return models.HealthStatus.fromMap(res.data); - } + /// Get cache + /// + /// Check the Appwrite in-memory cache servers are up and connection is + /// successful. + Future<models.HealthStatus> getCache() async { + final String apiPath = '/health/cache'; - /// Get the SSL certificate for a domain - /// - /// Get the SSL certificate for a domain - Future<models.HealthCertificate> getCertificate({String? domain}) async { - final String apiPath = '/health/certificate'; + final Map<String, dynamic> apiParams = { + + + }; - final Map<String, dynamic> apiParams = { - 'domain': domain, - }; + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; + }; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - return models.HealthCertificate.fromMap(res.data); - } + return models.HealthStatus.fromMap(res.data); - /// Get DB - /// - /// Check the Appwrite database servers are up and connection is successful. - Future<models.HealthStatus> getDB() async { - final String apiPath = '/health/db'; + } - final Map<String, dynamic> apiParams = {}; + /// Get the SSL certificate for a domain + /// + /// Get the SSL certificate for a domain + Future<models.HealthCertificate> getCertificate({String? domain}) async { + final String apiPath = '/health/certificate'; - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; + final Map<String, dynamic> apiParams = { + 'domain': domain, - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + + }; - return models.HealthStatus.fromMap(res.data); - } + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', - /// Get pubsub - /// - /// Check the Appwrite pub-sub servers are up and connection is successful. - Future<models.HealthStatus> getPubSub() async { - final String apiPath = '/health/pubsub'; + }; - final Map<String, dynamic> apiParams = {}; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; + return models.HealthCertificate.fromMap(res.data); - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + } - return models.HealthStatus.fromMap(res.data); - } + /// Get DB + /// + /// Check the Appwrite database servers are up and connection is successful. + Future<models.HealthStatus> getDB() async { + final String apiPath = '/health/db'; - /// Get queue - /// - /// Check the Appwrite queue messaging servers are up and connection is - /// successful. - Future<models.HealthStatus> getQueue() async { - final String apiPath = '/health/queue'; + final Map<String, dynamic> apiParams = { + + + }; - final Map<String, dynamic> apiParams = {}; + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; + }; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthStatus.fromMap(res.data); - } + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - /// Get builds queue - /// - /// Get the number of builds that are waiting to be processed in the Appwrite - /// internal queue server. - Future<models.HealthQueue> getQueueBuilds({int? threshold}) async { - final String apiPath = '/health/queue/builds'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - }; + return models.HealthStatus.fromMap(res.data); - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get certificates queue - /// - /// Get the number of certificates that are waiting to be issued against - /// [Letsencrypt](https://letsencrypt.org/) in the Appwrite internal queue - /// server. - Future<models.HealthQueue> getQueueCertificates({int? threshold}) async { - final String apiPath = '/health/queue/certificates'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get databases queue - /// - /// Get the number of database changes that are waiting to be processed in the - /// Appwrite internal queue server. - Future<models.HealthQueue> getQueueDatabases( - {String? name, int? threshold}) async { - final String apiPath = '/health/queue/databases'; - - final Map<String, dynamic> apiParams = { - 'name': name, - 'threshold': threshold, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get deletes queue - /// - /// Get the number of background destructive changes that are waiting to be - /// processed in the Appwrite internal queue server. - Future<models.HealthQueue> getQueueDeletes({int? threshold}) async { - final String apiPath = '/health/queue/deletes'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get number of failed queue jobs - /// - /// Returns the amount of failed jobs in a given queue. - /// - Future<models.HealthQueue> getFailedJobs( - {required enums.Name name, int? threshold}) async { - final String apiPath = - '/health/queue/failed/{name}'.replaceAll('{name}', name.value); - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get functions queue - /// - /// Get the number of function executions that are waiting to be processed in - /// the Appwrite internal queue server. - Future<models.HealthQueue> getQueueFunctions({int? threshold}) async { - final String apiPath = '/health/queue/functions'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get logs queue - /// - /// Get the number of logs that are waiting to be processed in the Appwrite - /// internal queue server. - Future<models.HealthQueue> getQueueLogs({int? threshold}) async { - final String apiPath = '/health/queue/logs'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get mails queue - /// - /// Get the number of mails that are waiting to be processed in the Appwrite - /// internal queue server. - Future<models.HealthQueue> getQueueMails({int? threshold}) async { - final String apiPath = '/health/queue/mails'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get messaging queue - /// - /// Get the number of messages that are waiting to be processed in the Appwrite - /// internal queue server. - Future<models.HealthQueue> getQueueMessaging({int? threshold}) async { - final String apiPath = '/health/queue/messaging'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get migrations queue - /// - /// Get the number of migrations that are waiting to be processed in the - /// Appwrite internal queue server. - Future<models.HealthQueue> getQueueMigrations({int? threshold}) async { - final String apiPath = '/health/queue/migrations'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } + } - /// Get usage queue - /// - /// Get the number of metrics that are waiting to be processed in the Appwrite - /// internal queue server. - Future<models.HealthQueue> getQueueUsage({int? threshold}) async { - final String apiPath = '/health/queue/usage'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get usage dump queue - /// - /// Get the number of projects containing metrics that are waiting to be - /// processed in the Appwrite internal queue server. - Future<models.HealthQueue> getQueueUsageDump({int? threshold}) async { - final String apiPath = '/health/queue/usage-dump'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get webhooks queue - /// - /// Get the number of webhooks that are waiting to be processed in the Appwrite - /// internal queue server. - Future<models.HealthQueue> getQueueWebhooks({int? threshold}) async { - final String apiPath = '/health/queue/webhooks'; - - final Map<String, dynamic> apiParams = { - 'threshold': threshold, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthQueue.fromMap(res.data); - } - - /// Get storage - /// - /// Check the Appwrite storage device is up and connection is successful. - Future<models.HealthStatus> getStorage() async { - final String apiPath = '/health/storage'; + /// Get pubsub + /// + /// Check the Appwrite pub-sub servers are up and connection is successful. + Future<models.HealthStatus> getPubSub() async { + final String apiPath = '/health/pubsub'; - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthStatus.fromMap(res.data); - } - - /// Get local storage - /// - /// Check the Appwrite local storage device is up and connection is successful. - Future<models.HealthStatus> getStorageLocal() async { - final String apiPath = '/health/storage/local'; - - final Map<String, dynamic> apiParams = {}; + final Map<String, dynamic> apiParams = { + + + }; - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthStatus.fromMap(res.data); - } - - /// Get time - /// - /// Check the Appwrite server time is synced with Google remote NTP server. We - /// use this technology to smoothly handle leap seconds with no disruptive - /// events. The [Network Time - /// Protocol](https://en.wikipedia.org/wiki/Network_Time_Protocol) (NTP) is - /// used by hundreds of millions of computers and devices to synchronize their - /// clocks over the Internet. If your computer sets its own clock, it likely - /// uses NTP. - Future<models.HealthTime> getTime() async { - final String apiPath = '/health/time'; + }; - final Map<String, dynamic> apiParams = {}; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; + return models.HealthStatus.fromMap(res.data); - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.HealthTime.fromMap(res.data); - } -} + } + + /// Get queue + /// + /// Check the Appwrite queue messaging servers are up and connection is + /// successful. + Future<models.HealthStatus> getQueue() async { + final String apiPath = '/health/queue'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthStatus.fromMap(res.data); + + } + + /// Get builds queue + /// + /// Get the number of builds that are waiting to be processed in the Appwrite + /// internal queue server. + Future<models.HealthQueue> getQueueBuilds({int? threshold}) async { + final String apiPath = '/health/queue/builds'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get certificates queue + /// + /// Get the number of certificates that are waiting to be issued against + /// [Letsencrypt](https://letsencrypt.org/) in the Appwrite internal queue + /// server. + Future<models.HealthQueue> getQueueCertificates({int? threshold}) async { + final String apiPath = '/health/queue/certificates'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get databases queue + /// + /// Get the number of database changes that are waiting to be processed in the + /// Appwrite internal queue server. + Future<models.HealthQueue> getQueueDatabases({String? name, int? threshold}) async { + final String apiPath = '/health/queue/databases'; + + final Map<String, dynamic> apiParams = { + 'name': name, +'threshold': threshold, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get deletes queue + /// + /// Get the number of background destructive changes that are waiting to be + /// processed in the Appwrite internal queue server. + Future<models.HealthQueue> getQueueDeletes({int? threshold}) async { + final String apiPath = '/health/queue/deletes'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get number of failed queue jobs + /// + /// Returns the amount of failed jobs in a given queue. + /// + Future<models.HealthQueue> getFailedJobs({required enums.Name name, int? threshold}) async { + final String apiPath = '/health/queue/failed/{name}'.replaceAll('{name}', name.value); + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get functions queue + /// + /// Get the number of function executions that are waiting to be processed in + /// the Appwrite internal queue server. + Future<models.HealthQueue> getQueueFunctions({int? threshold}) async { + final String apiPath = '/health/queue/functions'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get logs queue + /// + /// Get the number of logs that are waiting to be processed in the Appwrite + /// internal queue server. + Future<models.HealthQueue> getQueueLogs({int? threshold}) async { + final String apiPath = '/health/queue/logs'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get mails queue + /// + /// Get the number of mails that are waiting to be processed in the Appwrite + /// internal queue server. + Future<models.HealthQueue> getQueueMails({int? threshold}) async { + final String apiPath = '/health/queue/mails'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get messaging queue + /// + /// Get the number of messages that are waiting to be processed in the Appwrite + /// internal queue server. + Future<models.HealthQueue> getQueueMessaging({int? threshold}) async { + final String apiPath = '/health/queue/messaging'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get migrations queue + /// + /// Get the number of migrations that are waiting to be processed in the + /// Appwrite internal queue server. + Future<models.HealthQueue> getQueueMigrations({int? threshold}) async { + final String apiPath = '/health/queue/migrations'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get usage queue + /// + /// Get the number of metrics that are waiting to be processed in the Appwrite + /// internal queue server. + Future<models.HealthQueue> getQueueUsage({int? threshold}) async { + final String apiPath = '/health/queue/usage'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get usage dump queue + /// + /// Get the number of projects containing metrics that are waiting to be + /// processed in the Appwrite internal queue server. + Future<models.HealthQueue> getQueueUsageDump({int? threshold}) async { + final String apiPath = '/health/queue/usage-dump'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get webhooks queue + /// + /// Get the number of webhooks that are waiting to be processed in the Appwrite + /// internal queue server. + Future<models.HealthQueue> getQueueWebhooks({int? threshold}) async { + final String apiPath = '/health/queue/webhooks'; + + final Map<String, dynamic> apiParams = { + 'threshold': threshold, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthQueue.fromMap(res.data); + + } + + /// Get storage + /// + /// Check the Appwrite storage device is up and connection is successful. + Future<models.HealthStatus> getStorage() async { + final String apiPath = '/health/storage'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthStatus.fromMap(res.data); + + } + + /// Get local storage + /// + /// Check the Appwrite local storage device is up and connection is successful. + Future<models.HealthStatus> getStorageLocal() async { + final String apiPath = '/health/storage/local'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthStatus.fromMap(res.data); + + } + + /// Get time + /// + /// Check the Appwrite server time is synced with Google remote NTP server. We + /// use this technology to smoothly handle leap seconds with no disruptive + /// events. The [Network Time + /// Protocol](https://en.wikipedia.org/wiki/Network_Time_Protocol) (NTP) is + /// used by hundreds of millions of computers and devices to synchronize their + /// clocks over the Internet. If your computer sets its own clock, it likely + /// uses NTP. + Future<models.HealthTime> getTime() async { + final String apiPath = '/health/time'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.HealthTime.fromMap(res.data); + + } +} \ No newline at end of file diff --git a/lib/services/locale.dart b/lib/services/locale.dart index a7eaf3bb..cf65a2f3 100644 --- a/lib/services/locale.dart +++ b/lib/services/locale.dart @@ -3,162 +3,194 @@ part of '../dart_appwrite.dart'; /// The Locale service allows you to customize your app based on your users' /// location. class Locale extends Service { - Locale(super.client); + Locale(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<models.Locale> get() async { - final String apiPath = '/locale'; + /// 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<models.Locale> get() async { + final String apiPath = '/locale'; - final Map<String, dynamic> apiParams = {}; + final Map<String, dynamic> apiParams = { + + + }; - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + }; - return models.Locale.fromMap(res.data); - } + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - /// List locale codes - /// - /// List of all locale codes in [ISO - /// 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). - Future<models.LocaleCodeList> listCodes() async { - final String apiPath = '/locale/codes'; + return models.Locale.fromMap(res.data); - final Map<String, dynamic> apiParams = {}; + } - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; + /// List locale codes + /// + /// List of all locale codes in [ISO + /// 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). + Future<models.LocaleCodeList> listCodes() async { + final String apiPath = '/locale/codes'; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + final Map<String, dynamic> apiParams = { + + + }; - return models.LocaleCodeList.fromMap(res.data); - } + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', - /// List continents - /// - /// List of all continents. You can use the locale header to get the data in a - /// supported language. - Future<models.ContinentList> listContinents() async { - final String apiPath = '/locale/continents'; + }; - final Map<String, dynamic> apiParams = {}; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; + return models.LocaleCodeList.fromMap(res.data); - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + } - return models.ContinentList.fromMap(res.data); - } + /// List continents + /// + /// List of all continents. You can use the locale header to get the data in a + /// supported language. + Future<models.ContinentList> listContinents() async { + final String apiPath = '/locale/continents'; - /// List countries - /// - /// List of all countries. You can use the locale header to get the data in a - /// supported language. - Future<models.CountryList> listCountries() async { - final String apiPath = '/locale/countries'; + final Map<String, dynamic> apiParams = { + + + }; - final Map<String, dynamic> apiParams = {}; + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; + }; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - return models.CountryList.fromMap(res.data); - } + return models.ContinentList.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<models.CountryList> listCountriesEU() async { - final String apiPath = '/locale/countries/eu'; + } - final Map<String, dynamic> apiParams = {}; + /// List countries + /// + /// List of all countries. You can use the locale header to get the data in a + /// supported language. + Future<models.CountryList> listCountries() async { + final String apiPath = '/locale/countries'; - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; + final Map<String, dynamic> apiParams = { + + + }; - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', - 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<models.PhoneList> listCountriesPhones() async { - final String apiPath = '/locale/countries/phones'; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final Map<String, dynamic> apiParams = {}; + return models.CountryList.fromMap(res.data); - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; + } - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + /// 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<models.CountryList> listCountriesEU() async { + final String apiPath = '/locale/countries/eu'; - return models.PhoneList.fromMap(res.data); - } + final Map<String, dynamic> apiParams = { + + + }; - /// 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<models.CurrencyList> listCurrencies() async { - final String apiPath = '/locale/currencies'; + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', - final Map<String, dynamic> apiParams = {}; + }; - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + return models.CountryList.fromMap(res.data); - 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<models.LanguageList> listLanguages() async { - final String apiPath = '/locale/languages'; + /// 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<models.PhoneList> listCountriesPhones() async { + final String apiPath = '/locale/countries/phones'; - final Map<String, dynamic> apiParams = {}; + final Map<String, dynamic> apiParams = { + + + }; - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); + }; - return models.LanguageList.fromMap(res.data); - } -} + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + 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<models.CurrencyList> listCurrencies() async { + final String apiPath = '/locale/currencies'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + 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<models.LanguageList> listLanguages() async { + final String apiPath = '/locale/languages'; + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LanguageList.fromMap(res.data); + + } +} \ No newline at end of file diff --git a/lib/services/messaging.dart b/lib/services/messaging.dart index 5fc759fd..6a7024d2 100644 --- a/lib/services/messaging.dart +++ b/lib/services/messaging.dart @@ -3,1386 +3,1257 @@ part of '../dart_appwrite.dart'; /// The Messaging service allows you to send messages to any provider type /// (SMTP, push notification, SMS, etc.). class Messaging extends Service { - Messaging(super.client); - - /// List messages - /// - /// Get a list of all messages from the current Appwrite project. - Future<models.MessageList> listMessages( - {List<String>? queries, String? search}) async { - final String apiPath = '/messaging/messages'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MessageList.fromMap(res.data); - } - - /// Create email - /// - /// Create a new email message. - Future<models.Message> createEmail( - {required String messageId, - required String subject, - required String content, - List<String>? topics, - List<String>? users, - List<String>? targets, - List<String>? cc, - List<String>? bcc, - List<String>? attachments, - bool? draft, - bool? html, - String? scheduledAt}) async { - final String apiPath = '/messaging/messages/email'; - - final Map<String, dynamic> apiParams = { - 'messageId': messageId, - 'subject': subject, - 'content': content, - 'topics': topics, - 'users': users, - 'targets': targets, - 'cc': cc, - 'bcc': bcc, - 'attachments': attachments, - 'draft': draft, - 'html': html, - 'scheduledAt': scheduledAt, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Update email - /// - /// Update an email message by its unique ID. - /// - Future<models.Message> updateEmail( - {required String messageId, - List<String>? topics, - List<String>? users, - List<String>? targets, - String? subject, - String? content, - bool? draft, - bool? html, - List<String>? cc, - List<String>? bcc, - String? scheduledAt, - List<String>? attachments}) async { - final String apiPath = '/messaging/messages/email/{messageId}' - .replaceAll('{messageId}', messageId); - - final Map<String, dynamic> apiParams = { - 'topics': topics, - 'users': users, - 'targets': targets, - 'subject': subject, - 'content': content, - 'draft': draft, - 'html': html, - 'cc': cc, - 'bcc': bcc, - 'scheduledAt': scheduledAt, - 'attachments': attachments, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Create push notification - /// - /// Create a new push notification. - Future<models.Message> createPush( - {required String messageId, - String? title, - String? body, - List<String>? topics, - List<String>? users, - List<String>? targets, - Map? data, - String? action, - String? image, - String? icon, - String? sound, - String? color, - String? tag, - int? badge, - bool? draft, - String? scheduledAt, - bool? contentAvailable, - bool? critical, - enums.MessagePriority? priority}) async { - final String apiPath = '/messaging/messages/push'; - - final Map<String, dynamic> apiParams = { - 'messageId': messageId, - 'title': title, - 'body': body, - 'topics': topics, - 'users': users, - 'targets': targets, - 'data': data, - 'action': action, - 'image': image, - 'icon': icon, - 'sound': sound, - 'color': color, - 'tag': tag, - 'badge': badge, - 'draft': draft, - 'scheduledAt': scheduledAt, - 'contentAvailable': contentAvailable, - 'critical': critical, - 'priority': priority?.value, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Update push notification - /// - /// Update a push notification by its unique ID. - /// - Future<models.Message> updatePush( - {required String messageId, - List<String>? topics, - List<String>? users, - List<String>? targets, - String? title, - String? body, - Map? data, - String? action, - String? image, - String? icon, - String? sound, - String? color, - String? tag, - int? badge, - bool? draft, - String? scheduledAt, - bool? contentAvailable, - bool? critical, - enums.MessagePriority? priority}) async { - final String apiPath = '/messaging/messages/push/{messageId}' - .replaceAll('{messageId}', messageId); - - final Map<String, dynamic> apiParams = { - 'topics': topics, - 'users': users, - 'targets': targets, - 'title': title, - 'body': body, - 'data': data, - 'action': action, - 'image': image, - 'icon': icon, - 'sound': sound, - 'color': color, - 'tag': tag, - 'badge': badge, - 'draft': draft, - 'scheduledAt': scheduledAt, - 'contentAvailable': contentAvailable, - 'critical': critical, - 'priority': priority?.value, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Create SMS - /// - /// Create a new SMS message. - Future<models.Message> createSms( - {required String messageId, - required String content, - List<String>? topics, - List<String>? users, - List<String>? targets, - bool? draft, - String? scheduledAt}) async { - final String apiPath = '/messaging/messages/sms'; - - final Map<String, dynamic> apiParams = { - 'messageId': messageId, - 'content': content, - 'topics': topics, - 'users': users, - 'targets': targets, - 'draft': draft, - 'scheduledAt': scheduledAt, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Update SMS - /// - /// Update an email message by its unique ID. - /// - Future<models.Message> updateSms( - {required String messageId, - List<String>? topics, - List<String>? users, - List<String>? targets, - String? content, - bool? draft, - String? scheduledAt}) async { - final String apiPath = '/messaging/messages/sms/{messageId}' - .replaceAll('{messageId}', messageId); - - final Map<String, dynamic> apiParams = { - 'topics': topics, - 'users': users, - 'targets': targets, - 'content': content, - 'draft': draft, - 'scheduledAt': scheduledAt, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Get message - /// - /// Get a message by its unique ID. - /// - Future<models.Message> getMessage({required String messageId}) async { - final String apiPath = - '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Message.fromMap(res.data); - } - - /// Delete message - /// - /// Delete a message. If the message is not a draft or scheduled, but has been - /// sent, this will not recall the message. - Future delete({required String messageId}) async { - final String apiPath = - '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List message logs - /// - /// Get the message activity logs listed by its unique ID. - Future<models.LogList> listMessageLogs( - {required String messageId, List<String>? queries}) async { - final String apiPath = '/messaging/messages/{messageId}/logs' - .replaceAll('{messageId}', messageId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// List message targets - /// - /// Get a list of the targets associated with a message. - Future<models.TargetList> listTargets( - {required String messageId, List<String>? queries}) async { - final String apiPath = '/messaging/messages/{messageId}/targets' - .replaceAll('{messageId}', messageId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.TargetList.fromMap(res.data); - } - - /// List providers - /// - /// Get a list of all providers from the current Appwrite project. - Future<models.ProviderList> listProviders( - {List<String>? queries, String? search}) async { - final String apiPath = '/messaging/providers'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.ProviderList.fromMap(res.data); - } - - /// Create APNS provider - /// - /// Create a new Apple Push Notification service provider. - Future<models.Provider> createApnsProvider( - {required String providerId, - required String name, - String? authKey, - String? authKeyId, - String? teamId, - String? bundleId, - bool? sandbox, - bool? enabled}) async { - final String apiPath = '/messaging/providers/apns'; - - final Map<String, dynamic> apiParams = { - 'providerId': providerId, - 'name': name, - 'authKey': authKey, - 'authKeyId': authKeyId, - 'teamId': teamId, - 'bundleId': bundleId, - 'sandbox': sandbox, - 'enabled': enabled, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update APNS provider - /// - /// Update a Apple Push Notification service provider by its unique ID. - Future<models.Provider> updateApnsProvider( - {required String providerId, - String? name, - bool? enabled, - String? authKey, - String? authKeyId, - String? teamId, - String? bundleId, - bool? sandbox}) async { - final String apiPath = '/messaging/providers/apns/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - 'name': name, - 'enabled': enabled, - 'authKey': authKey, - 'authKeyId': authKeyId, - 'teamId': teamId, - 'bundleId': bundleId, - 'sandbox': sandbox, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create FCM provider - /// - /// Create a new Firebase Cloud Messaging provider. - Future<models.Provider> createFcmProvider( - {required String providerId, - required String name, - Map? serviceAccountJSON, - bool? enabled}) async { - final String apiPath = '/messaging/providers/fcm'; - - final Map<String, dynamic> apiParams = { - 'providerId': providerId, - 'name': name, - 'serviceAccountJSON': serviceAccountJSON, - 'enabled': enabled, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update FCM provider - /// - /// Update a Firebase Cloud Messaging provider by its unique ID. - Future<models.Provider> updateFcmProvider( - {required String providerId, - String? name, - bool? enabled, - Map? serviceAccountJSON}) async { - final String apiPath = '/messaging/providers/fcm/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - 'name': name, - 'enabled': enabled, - 'serviceAccountJSON': serviceAccountJSON, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Mailgun provider - /// - /// Create a new Mailgun provider. - Future<models.Provider> createMailgunProvider( - {required String providerId, - required String name, - String? apiKey, - String? domain, - bool? isEuRegion, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail, - bool? enabled}) async { - final String apiPath = '/messaging/providers/mailgun'; - - final Map<String, dynamic> apiParams = { - 'providerId': providerId, - 'name': name, - 'apiKey': apiKey, - 'domain': domain, - 'isEuRegion': isEuRegion, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - 'enabled': enabled, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Mailgun provider - /// - /// Update a Mailgun provider by its unique ID. - Future<models.Provider> updateMailgunProvider( - {required String providerId, - String? name, - String? apiKey, - String? domain, - bool? isEuRegion, - bool? enabled, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail}) async { - final String apiPath = '/messaging/providers/mailgun/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - 'name': name, - 'apiKey': apiKey, - 'domain': domain, - 'isEuRegion': isEuRegion, - 'enabled': enabled, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Msg91 provider - /// - /// Create a new MSG91 provider. - Future<models.Provider> createMsg91Provider( - {required String providerId, - required String name, - String? templateId, - String? senderId, - String? authKey, - bool? enabled}) async { - final String apiPath = '/messaging/providers/msg91'; - - final Map<String, dynamic> apiParams = { - 'providerId': providerId, - 'name': name, - 'templateId': templateId, - 'senderId': senderId, - 'authKey': authKey, - 'enabled': enabled, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Msg91 provider - /// - /// Update a MSG91 provider by its unique ID. - Future<models.Provider> updateMsg91Provider( - {required String providerId, - String? name, - bool? enabled, - String? templateId, - String? senderId, - String? authKey}) async { - final String apiPath = '/messaging/providers/msg91/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - 'name': name, - 'enabled': enabled, - 'templateId': templateId, - 'senderId': senderId, - 'authKey': authKey, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Sendgrid provider - /// - /// Create a new Sendgrid provider. - Future<models.Provider> createSendgridProvider( - {required String providerId, - required String name, - String? apiKey, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail, - bool? enabled}) async { - final String apiPath = '/messaging/providers/sendgrid'; - - final Map<String, dynamic> apiParams = { - 'providerId': providerId, - 'name': name, - 'apiKey': apiKey, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - 'enabled': enabled, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Sendgrid provider - /// - /// Update a Sendgrid provider by its unique ID. - Future<models.Provider> updateSendgridProvider( - {required String providerId, - String? name, - bool? enabled, - String? apiKey, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail}) async { - final String apiPath = '/messaging/providers/sendgrid/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - 'name': name, - 'enabled': enabled, - 'apiKey': apiKey, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create SMTP provider - /// - /// Create a new SMTP provider. - Future<models.Provider> createSmtpProvider( - {required String providerId, - required String name, - required String host, - int? port, - String? username, - String? password, - enums.SmtpEncryption? encryption, - bool? autoTLS, - String? mailer, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail, - bool? enabled}) async { - final String apiPath = '/messaging/providers/smtp'; - - final Map<String, dynamic> apiParams = { - 'providerId': providerId, - 'name': name, - 'host': host, - 'port': port, - 'username': username, - 'password': password, - 'encryption': encryption?.value, - 'autoTLS': autoTLS, - 'mailer': mailer, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - 'enabled': enabled, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update SMTP provider - /// - /// Update a SMTP provider by its unique ID. - Future<models.Provider> updateSmtpProvider( - {required String providerId, - String? name, - String? host, - int? port, - String? username, - String? password, - enums.SmtpEncryption? encryption, - bool? autoTLS, - String? mailer, - String? fromName, - String? fromEmail, - String? replyToName, - String? replyToEmail, - bool? enabled}) async { - final String apiPath = '/messaging/providers/smtp/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - 'name': name, - 'host': host, - 'port': port, - 'username': username, - 'password': password, - 'encryption': encryption?.value, - 'autoTLS': autoTLS, - 'mailer': mailer, - 'fromName': fromName, - 'fromEmail': fromEmail, - 'replyToName': replyToName, - 'replyToEmail': replyToEmail, - 'enabled': enabled, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Telesign provider - /// - /// Create a new Telesign provider. - Future<models.Provider> createTelesignProvider( - {required String providerId, - required String name, - String? from, - String? customerId, - String? apiKey, - bool? enabled}) async { - final String apiPath = '/messaging/providers/telesign'; - - final Map<String, dynamic> apiParams = { - 'providerId': providerId, - 'name': name, - 'from': from, - 'customerId': customerId, - 'apiKey': apiKey, - 'enabled': enabled, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Telesign provider - /// - /// Update a Telesign provider by its unique ID. - Future<models.Provider> updateTelesignProvider( - {required String providerId, - String? name, - bool? enabled, - String? customerId, - String? apiKey, - String? from}) async { - final String apiPath = '/messaging/providers/telesign/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - 'name': name, - 'enabled': enabled, - 'customerId': customerId, - 'apiKey': apiKey, - 'from': from, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Textmagic provider - /// - /// Create a new Textmagic provider. - Future<models.Provider> createTextmagicProvider( - {required String providerId, - required String name, - String? from, - String? username, - String? apiKey, - bool? enabled}) async { - final String apiPath = '/messaging/providers/textmagic'; - - final Map<String, dynamic> apiParams = { - 'providerId': providerId, - 'name': name, - 'from': from, - 'username': username, - 'apiKey': apiKey, - 'enabled': enabled, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Textmagic provider - /// - /// Update a Textmagic provider by its unique ID. - Future<models.Provider> updateTextmagicProvider( - {required String providerId, - String? name, - bool? enabled, - String? username, - String? apiKey, - String? from}) async { - final String apiPath = '/messaging/providers/textmagic/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - 'name': name, - 'enabled': enabled, - 'username': username, - 'apiKey': apiKey, - 'from': from, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Twilio provider - /// - /// Create a new Twilio provider. - Future<models.Provider> createTwilioProvider( - {required String providerId, - required String name, - String? from, - String? accountSid, - String? authToken, - bool? enabled}) async { - final String apiPath = '/messaging/providers/twilio'; - - final Map<String, dynamic> apiParams = { - 'providerId': providerId, - 'name': name, - 'from': from, - 'accountSid': accountSid, - 'authToken': authToken, - 'enabled': enabled, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Twilio provider - /// - /// Update a Twilio provider by its unique ID. - Future<models.Provider> updateTwilioProvider( - {required String providerId, - String? name, - bool? enabled, - String? accountSid, - String? authToken, - String? from}) async { - final String apiPath = '/messaging/providers/twilio/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - 'name': name, - 'enabled': enabled, - 'accountSid': accountSid, - 'authToken': authToken, - 'from': from, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Create Vonage provider - /// - /// Create a new Vonage provider. - Future<models.Provider> createVonageProvider( - {required String providerId, - required String name, - String? from, - String? apiKey, - String? apiSecret, - bool? enabled}) async { - final String apiPath = '/messaging/providers/vonage'; - - final Map<String, dynamic> apiParams = { - 'providerId': providerId, - 'name': name, - 'from': from, - 'apiKey': apiKey, - 'apiSecret': apiSecret, - 'enabled': enabled, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Update Vonage provider - /// - /// Update a Vonage provider by its unique ID. - Future<models.Provider> updateVonageProvider( - {required String providerId, - String? name, - bool? enabled, - String? apiKey, - String? apiSecret, - String? from}) async { - final String apiPath = '/messaging/providers/vonage/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - 'name': name, - 'enabled': enabled, - 'apiKey': apiKey, - 'apiSecret': apiSecret, - 'from': from, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Get provider - /// - /// Get a provider by its unique ID. - /// - Future<models.Provider> getProvider({required String providerId}) async { - final String apiPath = '/messaging/providers/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Provider.fromMap(res.data); - } - - /// Delete provider - /// - /// Delete a provider by its unique ID. - Future deleteProvider({required String providerId}) async { - final String apiPath = '/messaging/providers/{providerId}' - .replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List provider logs - /// - /// Get the provider activity logs listed by its unique ID. - Future<models.LogList> listProviderLogs( - {required String providerId, List<String>? queries}) async { - final String apiPath = '/messaging/providers/{providerId}/logs' - .replaceAll('{providerId}', providerId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// List subscriber logs - /// - /// Get the subscriber activity logs listed by its unique ID. - Future<models.LogList> listSubscriberLogs( - {required String subscriberId, List<String>? queries}) async { - final String apiPath = '/messaging/subscribers/{subscriberId}/logs' - .replaceAll('{subscriberId}', subscriberId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// List topics - /// - /// Get a list of all topics from the current Appwrite project. - Future<models.TopicList> listTopics( - {List<String>? queries, String? search}) async { - final String apiPath = '/messaging/topics'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.TopicList.fromMap(res.data); - } - - /// Create topic - /// - /// Create a new topic. - Future<models.Topic> createTopic( - {required String topicId, - required String name, - List<String>? subscribe}) async { - final String apiPath = '/messaging/topics'; - - final Map<String, dynamic> apiParams = { - 'topicId': topicId, - 'name': name, - 'subscribe': subscribe, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Topic.fromMap(res.data); - } - - /// Get topic - /// - /// Get a topic by its unique ID. - /// - Future<models.Topic> getTopic({required String topicId}) async { - final String apiPath = - '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Topic.fromMap(res.data); - } - - /// Update topic - /// - /// Update a topic by its unique ID. - /// - Future<models.Topic> updateTopic( - {required String topicId, String? name, List<String>? subscribe}) async { - final String apiPath = - '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); - - final Map<String, dynamic> apiParams = { - 'name': name, - 'subscribe': subscribe, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Topic.fromMap(res.data); - } - - /// Delete topic - /// - /// Delete a topic by its unique ID. - Future deleteTopic({required String topicId}) async { - final String apiPath = - '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List topic logs - /// - /// Get the topic activity logs listed by its unique ID. - Future<models.LogList> listTopicLogs( - {required String topicId, List<String>? queries}) async { - final String apiPath = - '/messaging/topics/{topicId}/logs'.replaceAll('{topicId}', topicId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// List subscribers - /// - /// Get a list of all subscribers from the current Appwrite project. - Future<models.SubscriberList> listSubscribers( - {required String topicId, List<String>? queries, String? search}) async { - final String apiPath = '/messaging/topics/{topicId}/subscribers' - .replaceAll('{topicId}', topicId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SubscriberList.fromMap(res.data); - } - - /// Create subscriber - /// - /// Create a new subscriber. - Future<models.Subscriber> createSubscriber( - {required String topicId, - required String subscriberId, - required String targetId}) async { - final String apiPath = '/messaging/topics/{topicId}/subscribers' - .replaceAll('{topicId}', topicId); - - final Map<String, dynamic> apiParams = { - 'subscriberId': subscriberId, - 'targetId': targetId, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Subscriber.fromMap(res.data); - } - - /// Get subscriber - /// - /// Get a subscriber by its unique ID. - /// - Future<models.Subscriber> getSubscriber( - {required String topicId, required String subscriberId}) async { - final String apiPath = - '/messaging/topics/{topicId}/subscribers/{subscriberId}' - .replaceAll('{topicId}', topicId) - .replaceAll('{subscriberId}', subscriberId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Subscriber.fromMap(res.data); - } - - /// Delete subscriber - /// - /// Delete a subscriber by its unique ID. - Future deleteSubscriber( - {required String topicId, required String subscriberId}) async { - final String apiPath = - '/messaging/topics/{topicId}/subscribers/{subscriberId}' - .replaceAll('{topicId}', topicId) - .replaceAll('{subscriberId}', subscriberId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } -} + Messaging(super.client); + + /// List messages + /// + /// Get a list of all messages from the current Appwrite project. + Future<models.MessageList> listMessages({List<String>? queries, String? search}) async { + final String apiPath = '/messaging/messages'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MessageList.fromMap(res.data); + + } + + /// Create email + /// + /// Create a new email message. + Future<models.Message> createEmail({required String messageId, required String subject, required String content, List<String>? topics, List<String>? users, List<String>? targets, List<String>? cc, List<String>? bcc, List<String>? attachments, bool? draft, bool? html, String? scheduledAt}) async { + final String apiPath = '/messaging/messages/email'; + + final Map<String, dynamic> apiParams = { + + 'messageId': messageId, +'subject': subject, +'content': content, +'topics': topics, +'users': users, +'targets': targets, +'cc': cc, +'bcc': bcc, +'attachments': attachments, +'draft': draft, +'html': html, +'scheduledAt': scheduledAt, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Update email + /// + /// Update an email message by its unique ID. + /// + Future<models.Message> updateEmail({required String messageId, List<String>? topics, List<String>? users, List<String>? targets, String? subject, String? content, bool? draft, bool? html, List<String>? cc, List<String>? bcc, String? scheduledAt, List<String>? attachments}) async { + final String apiPath = '/messaging/messages/email/{messageId}'.replaceAll('{messageId}', messageId); + + final Map<String, dynamic> apiParams = { + + 'topics': topics, +'users': users, +'targets': targets, +'subject': subject, +'content': content, +'draft': draft, +'html': html, +'cc': cc, +'bcc': bcc, +'scheduledAt': scheduledAt, +'attachments': attachments, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Create push notification + /// + /// Create a new push notification. + Future<models.Message> createPush({required String messageId, String? title, String? body, List<String>? topics, List<String>? users, List<String>? targets, Map? data, String? action, String? image, String? icon, String? sound, String? color, String? tag, int? badge, bool? draft, String? scheduledAt, bool? contentAvailable, bool? critical, enums.MessagePriority? priority}) async { + final String apiPath = '/messaging/messages/push'; + + final Map<String, dynamic> apiParams = { + + 'messageId': messageId, +'title': title, +'body': body, +'topics': topics, +'users': users, +'targets': targets, +'data': data, +'action': action, +'image': image, +'icon': icon, +'sound': sound, +'color': color, +'tag': tag, +'badge': badge, +'draft': draft, +'scheduledAt': scheduledAt, +'contentAvailable': contentAvailable, +'critical': critical, +'priority': priority?.value, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Update push notification + /// + /// Update a push notification by its unique ID. + /// + Future<models.Message> updatePush({required String messageId, List<String>? topics, List<String>? users, List<String>? targets, String? title, String? body, Map? data, String? action, String? image, String? icon, String? sound, String? color, String? tag, int? badge, bool? draft, String? scheduledAt, bool? contentAvailable, bool? critical, enums.MessagePriority? priority}) async { + final String apiPath = '/messaging/messages/push/{messageId}'.replaceAll('{messageId}', messageId); + + final Map<String, dynamic> apiParams = { + + 'topics': topics, +'users': users, +'targets': targets, +'title': title, +'body': body, +'data': data, +'action': action, +'image': image, +'icon': icon, +'sound': sound, +'color': color, +'tag': tag, +'badge': badge, +'draft': draft, +'scheduledAt': scheduledAt, +'contentAvailable': contentAvailable, +'critical': critical, +'priority': priority?.value, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Create SMS + /// + /// Create a new SMS message. + Future<models.Message> createSms({required String messageId, required String content, List<String>? topics, List<String>? users, List<String>? targets, bool? draft, String? scheduledAt}) async { + final String apiPath = '/messaging/messages/sms'; + + final Map<String, dynamic> apiParams = { + + 'messageId': messageId, +'content': content, +'topics': topics, +'users': users, +'targets': targets, +'draft': draft, +'scheduledAt': scheduledAt, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Update SMS + /// + /// Update an SMS message by its unique ID. + /// + Future<models.Message> updateSms({required String messageId, List<String>? topics, List<String>? users, List<String>? targets, String? content, bool? draft, String? scheduledAt}) async { + final String apiPath = '/messaging/messages/sms/{messageId}'.replaceAll('{messageId}', messageId); + + final Map<String, dynamic> apiParams = { + + 'topics': topics, +'users': users, +'targets': targets, +'content': content, +'draft': draft, +'scheduledAt': scheduledAt, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Get message + /// + /// Get a message by its unique ID. + /// + Future<models.Message> getMessage({required String messageId}) async { + final String apiPath = '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Message.fromMap(res.data); + + } + + /// Delete message + /// + /// Delete a message. If the message is not a draft or scheduled, but has been + /// sent, this will not recall the message. + Future delete({required String messageId}) async { + final String apiPath = '/messaging/messages/{messageId}'.replaceAll('{messageId}', messageId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List message logs + /// + /// Get the message activity logs listed by its unique ID. + Future<models.LogList> listMessageLogs({required String messageId, List<String>? queries}) async { + final String apiPath = '/messaging/messages/{messageId}/logs'.replaceAll('{messageId}', messageId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// List message targets + /// + /// Get a list of the targets associated with a message. + Future<models.TargetList> listTargets({required String messageId, List<String>? queries}) async { + final String apiPath = '/messaging/messages/{messageId}/targets'.replaceAll('{messageId}', messageId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.TargetList.fromMap(res.data); + + } + + /// List providers + /// + /// Get a list of all providers from the current Appwrite project. + Future<models.ProviderList> listProviders({List<String>? queries, String? search}) async { + final String apiPath = '/messaging/providers'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.ProviderList.fromMap(res.data); + + } + + /// Create APNS provider + /// + /// Create a new Apple Push Notification service provider. + Future<models.Provider> createApnsProvider({required String providerId, required String name, String? authKey, String? authKeyId, String? teamId, String? bundleId, bool? sandbox, bool? enabled}) async { + final String apiPath = '/messaging/providers/apns'; + + final Map<String, dynamic> apiParams = { + + 'providerId': providerId, +'name': name, +'authKey': authKey, +'authKeyId': authKeyId, +'teamId': teamId, +'bundleId': bundleId, +'sandbox': sandbox, +'enabled': enabled, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update APNS provider + /// + /// Update a Apple Push Notification service provider by its unique ID. + Future<models.Provider> updateApnsProvider({required String providerId, String? name, bool? enabled, String? authKey, String? authKeyId, String? teamId, String? bundleId, bool? sandbox}) async { + final String apiPath = '/messaging/providers/apns/{providerId}'.replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + + 'name': name, +'enabled': enabled, +'authKey': authKey, +'authKeyId': authKeyId, +'teamId': teamId, +'bundleId': bundleId, +'sandbox': sandbox, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create FCM provider + /// + /// Create a new Firebase Cloud Messaging provider. + Future<models.Provider> createFcmProvider({required String providerId, required String name, Map? serviceAccountJSON, bool? enabled}) async { + final String apiPath = '/messaging/providers/fcm'; + + final Map<String, dynamic> apiParams = { + + 'providerId': providerId, +'name': name, +'serviceAccountJSON': serviceAccountJSON, +'enabled': enabled, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update FCM provider + /// + /// Update a Firebase Cloud Messaging provider by its unique ID. + Future<models.Provider> updateFcmProvider({required String providerId, String? name, bool? enabled, Map? serviceAccountJSON}) async { + final String apiPath = '/messaging/providers/fcm/{providerId}'.replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + + 'name': name, +'enabled': enabled, +'serviceAccountJSON': serviceAccountJSON, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Mailgun provider + /// + /// Create a new Mailgun provider. + Future<models.Provider> createMailgunProvider({required String providerId, required String name, String? apiKey, String? domain, bool? isEuRegion, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { + final String apiPath = '/messaging/providers/mailgun'; + + final Map<String, dynamic> apiParams = { + + 'providerId': providerId, +'name': name, +'apiKey': apiKey, +'domain': domain, +'isEuRegion': isEuRegion, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, +'enabled': enabled, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Mailgun provider + /// + /// Update a Mailgun provider by its unique ID. + Future<models.Provider> updateMailgunProvider({required String providerId, String? name, String? apiKey, String? domain, bool? isEuRegion, bool? enabled, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail}) async { + final String apiPath = '/messaging/providers/mailgun/{providerId}'.replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + + 'name': name, +'apiKey': apiKey, +'domain': domain, +'isEuRegion': isEuRegion, +'enabled': enabled, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Msg91 provider + /// + /// Create a new MSG91 provider. + Future<models.Provider> createMsg91Provider({required String providerId, required String name, String? templateId, String? senderId, String? authKey, bool? enabled}) async { + final String apiPath = '/messaging/providers/msg91'; + + final Map<String, dynamic> apiParams = { + + 'providerId': providerId, +'name': name, +'templateId': templateId, +'senderId': senderId, +'authKey': authKey, +'enabled': enabled, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Msg91 provider + /// + /// Update a MSG91 provider by its unique ID. + Future<models.Provider> updateMsg91Provider({required String providerId, String? name, bool? enabled, String? templateId, String? senderId, String? authKey}) async { + final String apiPath = '/messaging/providers/msg91/{providerId}'.replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + + 'name': name, +'enabled': enabled, +'templateId': templateId, +'senderId': senderId, +'authKey': authKey, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Sendgrid provider + /// + /// Create a new Sendgrid provider. + Future<models.Provider> createSendgridProvider({required String providerId, required String name, String? apiKey, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { + final String apiPath = '/messaging/providers/sendgrid'; + + final Map<String, dynamic> apiParams = { + + 'providerId': providerId, +'name': name, +'apiKey': apiKey, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, +'enabled': enabled, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Sendgrid provider + /// + /// Update a Sendgrid provider by its unique ID. + Future<models.Provider> updateSendgridProvider({required String providerId, String? name, bool? enabled, String? apiKey, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail}) async { + final String apiPath = '/messaging/providers/sendgrid/{providerId}'.replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + + 'name': name, +'enabled': enabled, +'apiKey': apiKey, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create SMTP provider + /// + /// Create a new SMTP provider. + Future<models.Provider> createSmtpProvider({required String providerId, required String name, required String host, int? port, String? username, String? password, enums.SmtpEncryption? encryption, bool? autoTLS, String? mailer, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { + final String apiPath = '/messaging/providers/smtp'; + + final Map<String, dynamic> apiParams = { + + 'providerId': providerId, +'name': name, +'host': host, +'port': port, +'username': username, +'password': password, +'encryption': encryption?.value, +'autoTLS': autoTLS, +'mailer': mailer, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, +'enabled': enabled, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update SMTP provider + /// + /// Update a SMTP provider by its unique ID. + Future<models.Provider> updateSmtpProvider({required String providerId, String? name, String? host, int? port, String? username, String? password, enums.SmtpEncryption? encryption, bool? autoTLS, String? mailer, String? fromName, String? fromEmail, String? replyToName, String? replyToEmail, bool? enabled}) async { + final String apiPath = '/messaging/providers/smtp/{providerId}'.replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + + 'name': name, +'host': host, +'port': port, +'username': username, +'password': password, +'encryption': encryption?.value, +'autoTLS': autoTLS, +'mailer': mailer, +'fromName': fromName, +'fromEmail': fromEmail, +'replyToName': replyToName, +'replyToEmail': replyToEmail, +'enabled': enabled, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Telesign provider + /// + /// Create a new Telesign provider. + Future<models.Provider> createTelesignProvider({required String providerId, required String name, String? from, String? customerId, String? apiKey, bool? enabled}) async { + final String apiPath = '/messaging/providers/telesign'; + + final Map<String, dynamic> apiParams = { + + 'providerId': providerId, +'name': name, +'from': from, +'customerId': customerId, +'apiKey': apiKey, +'enabled': enabled, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Telesign provider + /// + /// Update a Telesign provider by its unique ID. + Future<models.Provider> updateTelesignProvider({required String providerId, String? name, bool? enabled, String? customerId, String? apiKey, String? from}) async { + final String apiPath = '/messaging/providers/telesign/{providerId}'.replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + + 'name': name, +'enabled': enabled, +'customerId': customerId, +'apiKey': apiKey, +'from': from, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Textmagic provider + /// + /// Create a new Textmagic provider. + Future<models.Provider> createTextmagicProvider({required String providerId, required String name, String? from, String? username, String? apiKey, bool? enabled}) async { + final String apiPath = '/messaging/providers/textmagic'; + + final Map<String, dynamic> apiParams = { + + 'providerId': providerId, +'name': name, +'from': from, +'username': username, +'apiKey': apiKey, +'enabled': enabled, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Textmagic provider + /// + /// Update a Textmagic provider by its unique ID. + Future<models.Provider> updateTextmagicProvider({required String providerId, String? name, bool? enabled, String? username, String? apiKey, String? from}) async { + final String apiPath = '/messaging/providers/textmagic/{providerId}'.replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + + 'name': name, +'enabled': enabled, +'username': username, +'apiKey': apiKey, +'from': from, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Twilio provider + /// + /// Create a new Twilio provider. + Future<models.Provider> createTwilioProvider({required String providerId, required String name, String? from, String? accountSid, String? authToken, bool? enabled}) async { + final String apiPath = '/messaging/providers/twilio'; + + final Map<String, dynamic> apiParams = { + + 'providerId': providerId, +'name': name, +'from': from, +'accountSid': accountSid, +'authToken': authToken, +'enabled': enabled, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Twilio provider + /// + /// Update a Twilio provider by its unique ID. + Future<models.Provider> updateTwilioProvider({required String providerId, String? name, bool? enabled, String? accountSid, String? authToken, String? from}) async { + final String apiPath = '/messaging/providers/twilio/{providerId}'.replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + + 'name': name, +'enabled': enabled, +'accountSid': accountSid, +'authToken': authToken, +'from': from, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Create Vonage provider + /// + /// Create a new Vonage provider. + Future<models.Provider> createVonageProvider({required String providerId, required String name, String? from, String? apiKey, String? apiSecret, bool? enabled}) async { + final String apiPath = '/messaging/providers/vonage'; + + final Map<String, dynamic> apiParams = { + + 'providerId': providerId, +'name': name, +'from': from, +'apiKey': apiKey, +'apiSecret': apiSecret, +'enabled': enabled, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Update Vonage provider + /// + /// Update a Vonage provider by its unique ID. + Future<models.Provider> updateVonageProvider({required String providerId, String? name, bool? enabled, String? apiKey, String? apiSecret, String? from}) async { + final String apiPath = '/messaging/providers/vonage/{providerId}'.replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + + 'name': name, +'enabled': enabled, +'apiKey': apiKey, +'apiSecret': apiSecret, +'from': from, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Get provider + /// + /// Get a provider by its unique ID. + /// + Future<models.Provider> getProvider({required String providerId}) async { + final String apiPath = '/messaging/providers/{providerId}'.replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Provider.fromMap(res.data); + + } + + /// Delete provider + /// + /// Delete a provider by its unique ID. + Future deleteProvider({required String providerId}) async { + final String apiPath = '/messaging/providers/{providerId}'.replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List provider logs + /// + /// Get the provider activity logs listed by its unique ID. + Future<models.LogList> listProviderLogs({required String providerId, List<String>? queries}) async { + final String apiPath = '/messaging/providers/{providerId}/logs'.replaceAll('{providerId}', providerId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// List subscriber logs + /// + /// Get the subscriber activity logs listed by its unique ID. + Future<models.LogList> listSubscriberLogs({required String subscriberId, List<String>? queries}) async { + final String apiPath = '/messaging/subscribers/{subscriberId}/logs'.replaceAll('{subscriberId}', subscriberId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// List topics + /// + /// Get a list of all topics from the current Appwrite project. + Future<models.TopicList> listTopics({List<String>? queries, String? search}) async { + final String apiPath = '/messaging/topics'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.TopicList.fromMap(res.data); + + } + + /// Create topic + /// + /// Create a new topic. + Future<models.Topic> createTopic({required String topicId, required String name, List<String>? subscribe}) async { + final String apiPath = '/messaging/topics'; + + final Map<String, dynamic> apiParams = { + + 'topicId': topicId, +'name': name, +'subscribe': subscribe, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Topic.fromMap(res.data); + + } + + /// Get topic + /// + /// Get a topic by its unique ID. + /// + Future<models.Topic> getTopic({required String topicId}) async { + final String apiPath = '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Topic.fromMap(res.data); + + } + + /// Update topic + /// + /// Update a topic by its unique ID. + /// + Future<models.Topic> updateTopic({required String topicId, String? name, List<String>? subscribe}) async { + final String apiPath = '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); + + final Map<String, dynamic> apiParams = { + + 'name': name, +'subscribe': subscribe, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Topic.fromMap(res.data); + + } + + /// Delete topic + /// + /// Delete a topic by its unique ID. + Future deleteTopic({required String topicId}) async { + final String apiPath = '/messaging/topics/{topicId}'.replaceAll('{topicId}', topicId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List topic logs + /// + /// Get the topic activity logs listed by its unique ID. + Future<models.LogList> listTopicLogs({required String topicId, List<String>? queries}) async { + final String apiPath = '/messaging/topics/{topicId}/logs'.replaceAll('{topicId}', topicId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// List subscribers + /// + /// Get a list of all subscribers from the current Appwrite project. + Future<models.SubscriberList> listSubscribers({required String topicId, List<String>? queries, String? search}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers'.replaceAll('{topicId}', topicId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SubscriberList.fromMap(res.data); + + } + + /// Create subscriber + /// + /// Create a new subscriber. + Future<models.Subscriber> createSubscriber({required String topicId, required String subscriberId, required String targetId}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers'.replaceAll('{topicId}', topicId); + + final Map<String, dynamic> apiParams = { + + 'subscriberId': subscriberId, +'targetId': targetId, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Subscriber.fromMap(res.data); + + } + + /// Get subscriber + /// + /// Get a subscriber by its unique ID. + /// + Future<models.Subscriber> getSubscriber({required String topicId, required String subscriberId}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replaceAll('{topicId}', topicId).replaceAll('{subscriberId}', subscriberId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Subscriber.fromMap(res.data); + + } + + /// Delete subscriber + /// + /// Delete a subscriber by its unique ID. + Future deleteSubscriber({required String topicId, required String subscriberId}) async { + final String apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replaceAll('{topicId}', topicId).replaceAll('{subscriberId}', subscriberId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } +} \ No newline at end of file diff --git a/lib/services/storage.dart b/lib/services/storage.dart index 25808b70..a6f987bc 100644 --- a/lib/services/storage.dart +++ b/lib/services/storage.dart @@ -2,382 +2,356 @@ part of '../dart_appwrite.dart'; /// The Storage service allows you to manage your project files. class Storage extends Service { - Storage(super.client); - - /// List buckets - /// - /// Get a list of all the storage buckets. You can use the query params to - /// filter your results. - Future<models.BucketList> listBuckets( - {List<String>? queries, String? search}) async { - final String apiPath = '/storage/buckets'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.BucketList.fromMap(res.data); - } - - /// Create bucket - /// - /// Create a new storage bucket. - Future<models.Bucket> createBucket( - {required String bucketId, - required String name, - List<String>? permissions, - bool? fileSecurity, - bool? enabled, - int? maximumFileSize, - List<String>? allowedFileExtensions, - enums.Compression? compression, - bool? encryption, - bool? antivirus}) async { - final String apiPath = '/storage/buckets'; - - final Map<String, dynamic> apiParams = { - 'bucketId': bucketId, - 'name': name, - 'permissions': permissions, - 'fileSecurity': fileSecurity, - 'enabled': enabled, - 'maximumFileSize': maximumFileSize, - 'allowedFileExtensions': allowedFileExtensions, - 'compression': compression?.value, - 'encryption': encryption, - 'antivirus': antivirus, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Bucket.fromMap(res.data); - } - - /// Get bucket - /// - /// Get a storage bucket by its unique ID. This endpoint response returns a - /// JSON object with the storage bucket metadata. - Future<models.Bucket> getBucket({required String bucketId}) async { - final String apiPath = - '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Bucket.fromMap(res.data); - } - - /// Update bucket - /// - /// Update a storage bucket by its unique ID. - Future<models.Bucket> updateBucket( - {required String bucketId, - required String name, - List<String>? permissions, - bool? fileSecurity, - bool? enabled, - int? maximumFileSize, - List<String>? allowedFileExtensions, - enums.Compression? compression, - bool? encryption, - bool? antivirus}) async { - final String apiPath = - '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); - - final Map<String, dynamic> apiParams = { - 'name': name, - 'permissions': permissions, - 'fileSecurity': fileSecurity, - 'enabled': enabled, - 'maximumFileSize': maximumFileSize, - 'allowedFileExtensions': allowedFileExtensions, - 'compression': compression?.value, - 'encryption': encryption, - 'antivirus': antivirus, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Bucket.fromMap(res.data); - } - - /// Delete bucket - /// - /// Delete a storage bucket by its unique ID. - Future deleteBucket({required String bucketId}) async { - final String apiPath = - '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List files - /// - /// Get a list of all the user files. You can use the query params to filter - /// your results. - Future<models.FileList> listFiles( - {required String bucketId, List<String>? queries, String? search}) async { - final String apiPath = - '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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](https://appwrite.io/docs/server/storage#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<models.File> createFile( - {required String bucketId, - required String fileId, - required InputFile file, - List<String>? permissions, - Function(UploadProgress)? onProgress}) async { - final String apiPath = - '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); - - final Map<String, dynamic> apiParams = { - 'fileId': fileId, - 'file': file, - 'permissions': permissions, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'multipart/form-data', - }; - - String idParamName = ''; - idParamName = 'fileId'; - final paramName = 'file'; - final res = await client.chunkedUpload( - path: apiPath, - params: apiParams, - paramName: paramName, - idParamName: idParamName, - headers: apiHeaders, - onProgress: onProgress, - ); - - 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<models.File> getFile( - {required String bucketId, required String fileId}) async { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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<models.File> updateFile( - {required String bucketId, - required String fileId, - String? name, - List<String>? permissions}) async { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map<String, dynamic> apiParams = { - 'name': name, - 'permissions': permissions, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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<Uint8List> getFileDownload( - {required String bucketId, required String fileId}) async { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map<String, dynamic> params = { - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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<Uint8List> getFilePreview( - {required String bucketId, - required String fileId, - int? width, - int? height, - enums.ImageGravity? gravity, - int? quality, - int? borderWidth, - String? borderColor, - int? borderRadius, - double? opacity, - int? rotation, - String? background, - enums.ImageFormat? output}) async { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map<String, dynamic> params = { - 'width': width, - 'height': height, - 'gravity': gravity?.value, - 'quality': quality, - 'borderWidth': borderWidth, - 'borderColor': borderColor, - 'borderRadius': borderRadius, - 'opacity': opacity, - 'rotation': rotation, - 'background': background, - 'output': output?.value, - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, 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<Uint8List> getFileView( - {required String bucketId, required String fileId}) async { - final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view' - .replaceAll('{bucketId}', bucketId) - .replaceAll('{fileId}', fileId); - - final Map<String, dynamic> params = { - 'project': client.config['project'], - 'session': client.config['session'], - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: params, responseType: ResponseType.bytes); - return res.data; - } -} + Storage(super.client); + + /// List buckets + /// + /// Get a list of all the storage buckets. You can use the query params to + /// filter your results. + Future<models.BucketList> listBuckets({List<String>? queries, String? search}) async { + final String apiPath = '/storage/buckets'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.BucketList.fromMap(res.data); + + } + + /// Create bucket + /// + /// Create a new storage bucket. + Future<models.Bucket> createBucket({required String bucketId, required String name, List<String>? permissions, bool? fileSecurity, bool? enabled, int? maximumFileSize, List<String>? allowedFileExtensions, enums.Compression? compression, bool? encryption, bool? antivirus}) async { + final String apiPath = '/storage/buckets'; + + final Map<String, dynamic> apiParams = { + + 'bucketId': bucketId, +'name': name, +'permissions': permissions, +'fileSecurity': fileSecurity, +'enabled': enabled, +'maximumFileSize': maximumFileSize, +'allowedFileExtensions': allowedFileExtensions, +'compression': compression?.value, +'encryption': encryption, +'antivirus': antivirus, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Bucket.fromMap(res.data); + + } + + /// Get bucket + /// + /// Get a storage bucket by its unique ID. This endpoint response returns a + /// JSON object with the storage bucket metadata. + Future<models.Bucket> getBucket({required String bucketId}) async { + final String apiPath = '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Bucket.fromMap(res.data); + + } + + /// Update bucket + /// + /// Update a storage bucket by its unique ID. + Future<models.Bucket> updateBucket({required String bucketId, required String name, List<String>? permissions, bool? fileSecurity, bool? enabled, int? maximumFileSize, List<String>? allowedFileExtensions, enums.Compression? compression, bool? encryption, bool? antivirus}) async { + final String apiPath = '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); + + final Map<String, dynamic> apiParams = { + + 'name': name, +'permissions': permissions, +'fileSecurity': fileSecurity, +'enabled': enabled, +'maximumFileSize': maximumFileSize, +'allowedFileExtensions': allowedFileExtensions, +'compression': compression?.value, +'encryption': encryption, +'antivirus': antivirus, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Bucket.fromMap(res.data); + + } + + /// Delete bucket + /// + /// Delete a storage bucket by its unique ID. + Future deleteBucket({required String bucketId}) async { + final String apiPath = '/storage/buckets/{bucketId}'.replaceAll('{bucketId}', bucketId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List files + /// + /// Get a list of all the user files. You can use the query params to filter + /// your results. + Future<models.FileList> listFiles({required String bucketId, List<String>? queries, String? search}) async { + final String apiPath = '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + 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](https://appwrite.io/docs/server/storage#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<models.File> createFile({required String bucketId, required String fileId, required InputFile file, List<String>? permissions, Function(UploadProgress)? onProgress}) async { + final String apiPath = '/storage/buckets/{bucketId}/files'.replaceAll('{bucketId}', bucketId); + + final Map<String, dynamic> apiParams = { + + 'fileId': fileId, +'file': file, +'permissions': permissions, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'multipart/form-data', + + }; + + String idParamName = ''; + idParamName = 'fileId'; + final paramName = 'file'; + final res = await client.chunkedUpload( + path: apiPath, + params: apiParams, + paramName: paramName, + idParamName: idParamName, + headers: apiHeaders, + onProgress: onProgress, + ); + + 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<models.File> getFile({required String bucketId, required String fileId}) async { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + 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<models.File> updateFile({required String bucketId, required String fileId, String? name, List<String>? permissions}) async { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map<String, dynamic> apiParams = { + + 'name': name, +'permissions': permissions, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + 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<Uint8List> getFileDownload({required String bucketId, required String fileId}) async { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map<String, dynamic> params = { + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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<Uint8List> getFilePreview({required String bucketId, required String fileId, int? width, int? height, enums.ImageGravity? gravity, int? quality, int? borderWidth, String? borderColor, int? borderRadius, double? opacity, int? rotation, String? background, enums.ImageFormat? output}) async { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map<String, dynamic> params = { + 'width': width, +'height': height, +'gravity': gravity?.value, +'quality': quality, +'borderWidth': borderWidth, +'borderColor': borderColor, +'borderRadius': borderRadius, +'opacity': opacity, +'rotation': rotation, +'background': background, +'output': output?.value, + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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<Uint8List> getFileView({required String bucketId, required String fileId}) async { + final String apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replaceAll('{bucketId}', bucketId).replaceAll('{fileId}', fileId); + + final Map<String, dynamic> params = { + + + 'project': client.config['project'], + 'session': client.config['session'], + }; + + final res = await client.call(HttpMethod.get, path: apiPath, 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 7833e8f6..699608fb 100644 --- a/lib/services/teams.dart +++ b/lib/services/teams.dart @@ -3,342 +3,352 @@ part of '../dart_appwrite.dart'; /// 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(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. - Future<models.TeamList> list({List<String>? queries, String? search}) async { - final String apiPath = '/teams'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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<models.Team> create( - {required String teamId, - required String name, - List<String>? roles}) async { - final String apiPath = '/teams'; - - final Map<String, dynamic> apiParams = { - 'teamId': teamId, - 'name': name, - 'roles': roles, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Team.fromMap(res.data); - } - - /// Get team - /// - /// Get a team by its ID. All team members have read access for this resource. - Future<models.Team> get({required String teamId}) async { - final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Team.fromMap(res.data); - } - - /// Update name - /// - /// Update the team's name by its unique ID. - Future<models.Team> updateName( - {required String teamId, required String name}) async { - final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); - - final Map<String, dynamic> apiParams = { - 'name': name, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// List 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. Hide sensitive attributes from - /// the response by toggling membership privacy in the Console. - Future<models.MembershipList> listMemberships( - {required String teamId, List<String>? queries, String? search}) async { - final String apiPath = - '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MembershipList.fromMap(res.data); - } - - /// Create team membership - /// - /// Invite a new member to join your team. Provide an ID for existing users, or - /// invite unregistered users using an email or phone number. If initiated from - /// a Client SDK, Appwrite will send an email or sms with a link to join the - /// team to the invited user, and an account will be created for them if one - /// doesn't exist. If initiated from a Server SDK, the new member will be added - /// automatically to the team. - /// - /// You only need to provide one of a user ID, email, or phone number. Appwrite - /// will prioritize accepting the user ID > email > phone number if you provide - /// more than one of these parameters. - /// - /// Use the `url` parameter to redirect the user from the invitation email to - /// your app. After the user is redirected, use the [Update Team Membership - /// Status](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus) - /// 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) - /// Appwrite will accept the only redirect URLs under the domains you have - /// added as a platform on the Appwrite Console. - /// - Future<models.Membership> createMembership( - {required String teamId, - required List<String> roles, - String? email, - String? userId, - String? phone, - String? url, - String? name}) async { - final String apiPath = - '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); - - final Map<String, dynamic> apiParams = { - 'email': email, - 'userId': userId, - 'phone': phone, - 'roles': roles, - 'url': url, - 'name': name, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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. Hide sensitive attributes from the response by - /// toggling membership privacy in the Console. - Future<models.Membership> getMembership( - {required String teamId, required String membershipId}) async { - final String apiPath = '/teams/{teamId}/memberships/{membershipId}' - .replaceAll('{teamId}', teamId) - .replaceAll('{membershipId}', membershipId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Membership.fromMap(res.data); - } - - /// Update membership - /// - /// 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](https://appwrite.io/docs/permissions). - /// - Future<models.Membership> updateMembership( - {required String teamId, - required String membershipId, - required List<String> roles}) async { - final String apiPath = '/teams/{teamId}/memberships/{membershipId}' - .replaceAll('{teamId}', teamId) - .replaceAll('{membershipId}', membershipId); - - final Map<String, dynamic> apiParams = { - 'roles': roles, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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 { - final String apiPath = '/teams/{teamId}/memberships/{membershipId}' - .replaceAll('{teamId}', teamId) - .replaceAll('{membershipId}', membershipId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - 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<models.Membership> updateMembershipStatus( - {required String teamId, - required String membershipId, - required String userId, - required String secret}) async { - final String apiPath = '/teams/{teamId}/memberships/{membershipId}/status' - .replaceAll('{teamId}', teamId) - .replaceAll('{membershipId}', membershipId); - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'secret': secret, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Membership.fromMap(res.data); - } - - /// Get team preferences - /// - /// Get the team's shared preferences by its unique ID. If a preference doesn't - /// need to be shared by all team members, prefer storing them in [user - /// preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs). - Future<models.Preferences> getPrefs({required String teamId}) async { - final String apiPath = - '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - } - - /// Update preferences - /// - /// Update the team's preferences by its unique ID. The object you pass is - /// stored as is and replaces any previous value. The maximum allowed prefs - /// size is 64kB and throws an error if exceeded. - Future<models.Preferences> updatePrefs( - {required String teamId, required Map prefs}) async { - final String apiPath = - '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); - - final Map<String, dynamic> apiParams = { - 'prefs': prefs, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - } -} + Teams(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. + Future<models.TeamList> list({List<String>? queries, String? search}) async { + final String apiPath = '/teams'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + 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<models.Team> create({required String teamId, required String name, List<String>? roles}) async { + final String apiPath = '/teams'; + + final Map<String, dynamic> apiParams = { + + 'teamId': teamId, +'name': name, +'roles': roles, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Team.fromMap(res.data); + + } + + /// Get team + /// + /// Get a team by its ID. All team members have read access for this resource. + Future<models.Team> get({required String teamId}) async { + final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Team.fromMap(res.data); + + } + + /// Update name + /// + /// Update the team's name by its unique ID. + Future<models.Team> updateName({required String teamId, required String name}) async { + final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); + + final Map<String, dynamic> apiParams = { + + 'name': name, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams/{teamId}'.replaceAll('{teamId}', teamId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List 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. Hide sensitive attributes from + /// the response by toggling membership privacy in the Console. + Future<models.MembershipList> listMemberships({required String teamId, List<String>? queries, String? search}) async { + final String apiPath = '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MembershipList.fromMap(res.data); + + } + + /// Create team membership + /// + /// Invite a new member to join your team. Provide an ID for existing users, or + /// invite unregistered users using an email or phone number. If initiated from + /// a Client SDK, Appwrite will send an email or sms with a link to join the + /// team to the invited user, and an account will be created for them if one + /// doesn't exist. If initiated from a Server SDK, the new member will be added + /// automatically to the team. + /// + /// You only need to provide one of a user ID, email, or phone number. Appwrite + /// will prioritize accepting the user ID > email > phone number if you provide + /// more than one of these parameters. + /// + /// Use the `url` parameter to redirect the user from the invitation email to + /// your app. After the user is redirected, use the [Update Team Membership + /// Status](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus) + /// 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) + /// Appwrite will accept the only redirect URLs under the domains you have + /// added as a platform on the Appwrite Console. + /// + Future<models.Membership> createMembership({required String teamId, required List<String> roles, String? email, String? userId, String? phone, String? url, String? name}) async { + final String apiPath = '/teams/{teamId}/memberships'.replaceAll('{teamId}', teamId); + + final Map<String, dynamic> apiParams = { + + 'email': email, +'userId': userId, +'phone': phone, +'roles': roles, +'url': url, +'name': name, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + 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. Hide sensitive attributes from the response by + /// toggling membership privacy in the Console. + Future<models.Membership> getMembership({required String teamId, required String membershipId}) async { + final String apiPath = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Membership.fromMap(res.data); + + } + + /// Update membership + /// + /// 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](https://appwrite.io/docs/permissions). + /// + Future<models.Membership> updateMembership({required String teamId, required String membershipId, required List<String> roles}) async { + final String apiPath = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); + + final Map<String, dynamic> apiParams = { + + 'roles': roles, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + 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 { + final String apiPath = '/teams/{teamId}/memberships/{membershipId}'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + 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<models.Membership> updateMembershipStatus({required String teamId, required String membershipId, required String userId, required String secret}) async { + final String apiPath = '/teams/{teamId}/memberships/{membershipId}/status'.replaceAll('{teamId}', teamId).replaceAll('{membershipId}', membershipId); + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'secret': secret, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Membership.fromMap(res.data); + + } + + /// Get team preferences + /// + /// Get the team's shared preferences by its unique ID. If a preference doesn't + /// need to be shared by all team members, prefer storing them in [user + /// preferences](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs). + Future<models.Preferences> getPrefs({required String teamId}) async { + final String apiPath = '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + + } + + /// Update preferences + /// + /// Update the team's preferences by its unique ID. The object you pass is + /// stored as is and replaces any previous value. The maximum allowed prefs + /// size is 64kB and throws an error if exceeded. + Future<models.Preferences> updatePrefs({required String teamId, required Map prefs}) async { + final String apiPath = '/teams/{teamId}/prefs'.replaceAll('{teamId}', teamId); + + final Map<String, dynamic> apiParams = { + + 'prefs': prefs, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + + } +} \ No newline at end of file diff --git a/lib/services/users.dart b/lib/services/users.dart index 28673732..7d10cf54 100644 --- a/lib/services/users.dart +++ b/lib/services/users.dart @@ -2,1023 +2,1055 @@ part of '../dart_appwrite.dart'; /// The Users service allows you to manage your project users. class Users extends Service { - Users(super.client); - - /// List users - /// - /// Get a list of all the project's users. You can use the query params to - /// filter your results. - Future<models.UserList> list({List<String>? queries, String? search}) async { - final String apiPath = '/users'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.UserList.fromMap(res.data); - } - - /// Create user - /// - /// Create a new user. - Future<models.User> create( - {required String userId, - String? email, - String? phone, - String? password, - String? name}) async { - final String apiPath = '/users'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'email': email, - 'phone': phone, - 'password': password, - 'name': name, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with Argon2 password - /// - /// Create a new user. Password provided must be hashed with the - /// [Argon2](https://en.wikipedia.org/wiki/Argon2) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future<models.User> createArgon2User( - {required String userId, - required String email, - required String password, - String? name}) async { - final String apiPath = '/users/argon2'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'name': name, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with bcrypt password - /// - /// Create a new user. Password provided must be hashed with the - /// [Bcrypt](https://en.wikipedia.org/wiki/Bcrypt) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future<models.User> createBcryptUser( - {required String userId, - required String email, - required String password, - String? name}) async { - final String apiPath = '/users/bcrypt'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'name': name, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// List identities - /// - /// Get identities for all users. - Future<models.IdentityList> listIdentities( - {List<String>? queries, String? search}) async { - final String apiPath = '/users/identities'; - - final Map<String, dynamic> apiParams = { - 'queries': queries, - 'search': search, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.IdentityList.fromMap(res.data); - } - - /// Delete identity - /// - /// Delete an identity by its unique ID. - Future deleteIdentity({required String identityId}) async { - final String apiPath = - '/users/identities/{identityId}'.replaceAll('{identityId}', identityId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Create user with MD5 password - /// - /// Create a new user. Password provided must be hashed with the - /// [MD5](https://en.wikipedia.org/wiki/MD5) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future<models.User> createMD5User( - {required String userId, - required String email, - required String password, - String? name}) async { - final String apiPath = '/users/md5'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'name': name, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with PHPass password - /// - /// Create a new user. Password provided must be hashed with the - /// [PHPass](https://www.openwall.com/phpass/) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future<models.User> createPHPassUser( - {required String userId, - required String email, - required String password, - String? name}) async { - final String apiPath = '/users/phpass'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'name': name, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with Scrypt password - /// - /// Create a new user. Password provided must be hashed with the - /// [Scrypt](https://github.com/Tarsnap/scrypt) algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future<models.User> createScryptUser( - {required String userId, - required String email, - required String password, - required String passwordSalt, - required int passwordCpu, - required int passwordMemory, - required int passwordParallel, - required int passwordLength, - String? name}) async { - final String apiPath = '/users/scrypt'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'passwordSalt': passwordSalt, - 'passwordCpu': passwordCpu, - 'passwordMemory': passwordMemory, - 'passwordParallel': passwordParallel, - 'passwordLength': passwordLength, - 'name': name, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with Scrypt modified password - /// - /// Create a new user. Password provided must be hashed with the [Scrypt - /// Modified](https://gist.github.com/Meldiron/eecf84a0225eccb5a378d45bb27462cc) - /// algorithm. Use the [POST - /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to - /// create users with a plain text password. - Future<models.User> createScryptModifiedUser( - {required String userId, - required String email, - required String password, - required String passwordSalt, - required String passwordSaltSeparator, - required String passwordSignerKey, - String? name}) async { - final String apiPath = '/users/scrypt-modified'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'passwordSalt': passwordSalt, - 'passwordSaltSeparator': passwordSaltSeparator, - 'passwordSignerKey': passwordSignerKey, - 'name': name, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user with SHA password - /// - /// Create a new user. Password provided must be hashed with the - /// [SHA](https://en.wikipedia.org/wiki/Secure_Hash_Algorithm) algorithm. Use - /// the [POST /users](https://appwrite.io/docs/server/users#usersCreate) - /// endpoint to create users with a plain text password. - Future<models.User> createSHAUser( - {required String userId, - required String email, - required String password, - enums.PasswordHash? passwordVersion, - String? name}) async { - final String apiPath = '/users/sha'; - - final Map<String, dynamic> apiParams = { - 'userId': userId, - 'email': email, - 'password': password, - 'passwordVersion': passwordVersion?.value, - 'name': name, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Get user - /// - /// Get a user by its unique ID. - Future<models.User> get({required String userId}) async { - final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Delete user - /// - /// Delete a user by its unique ID, thereby releasing it's ID. Since ID is - /// released and can be reused, all user-related resources like documents or - /// storage files should be deleted before user deletion. If you want to keep - /// ID reserved, use the - /// [updateStatus](https://appwrite.io/docs/server/users#usersUpdateStatus) - /// endpoint instead. - Future delete({required String userId}) async { - final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Update email - /// - /// Update the user email by its unique ID. - Future<models.User> updateEmail( - {required String userId, required String email}) async { - final String apiPath = - '/users/{userId}/email'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - 'email': email, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Create user JWT - /// - /// Use this endpoint to create a JSON Web Token for user by its unique ID. You - /// can use the resulting JWT to authenticate on behalf of the user. The JWT - /// secret will become invalid if the session it uses gets deleted. - Future<models.Jwt> createJWT( - {required String userId, String? sessionId, int? duration}) async { - final String apiPath = - '/users/{userId}/jwts'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - 'sessionId': sessionId, - 'duration': duration, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Jwt.fromMap(res.data); - } - - /// Update user labels - /// - /// Update the user labels by its unique ID. - /// - /// Labels can be used to grant access to resources. While teams are a way for - /// user's to share access to a resource, labels can be defined by the - /// developer to grant access without an invitation. See the [Permissions - /// docs](https://appwrite.io/docs/permissions) for more info. - Future<models.User> updateLabels( - {required String userId, required List<String> labels}) async { - final String apiPath = - '/users/{userId}/labels'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - 'labels': labels, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// List user logs - /// - /// Get the user activity logs list by its unique ID. - Future<models.LogList> listLogs( - {required String userId, List<String>? queries}) async { - final String apiPath = - '/users/{userId}/logs'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.LogList.fromMap(res.data); - } - - /// List user memberships - /// - /// Get the user membership list by its unique ID. - Future<models.MembershipList> listMemberships( - {required String userId}) async { - final String apiPath = - '/users/{userId}/memberships'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MembershipList.fromMap(res.data); - } - - /// Update MFA - /// - /// Enable or disable MFA on a user account. - Future<models.User> updateMfa( - {required String userId, required bool mfa}) async { - final String apiPath = '/users/{userId}/mfa'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - 'mfa': mfa, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Delete authenticator - /// - /// Delete an authenticator app. - Future<models.User> deleteMfaAuthenticator( - {required String userId, required enums.AuthenticatorType type}) async { - final String apiPath = '/users/{userId}/mfa/authenticators/{type}' - .replaceAll('{userId}', userId) - .replaceAll('{type}', type.value); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// List factors - /// - /// List the factors available on the account to be used as a MFA challange. - Future<models.MfaFactors> listMfaFactors({required String userId}) async { - final String apiPath = - '/users/{userId}/mfa/factors'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaFactors.fromMap(res.data); - } - - /// Get MFA recovery codes - /// - /// Get recovery codes that can be used as backup for MFA flow by User ID. - /// Before getting codes, they must be generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. - Future<models.MfaRecoveryCodes> getMfaRecoveryCodes( - {required String userId}) async { - final String apiPath = - '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Regenerate MFA recovery codes - /// - /// Regenerate recovery codes that can be used as backup for MFA flow by User - /// ID. Before regenerating codes, they must be first generated using - /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - /// method. - Future<models.MfaRecoveryCodes> updateMfaRecoveryCodes( - {required String userId}) async { - final String apiPath = - '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.put, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Create MFA recovery codes - /// - /// Generate recovery codes used as backup for MFA flow for User ID. Recovery - /// codes can be used as a MFA verification type in - /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) - /// method by client SDK. - Future<models.MfaRecoveryCodes> createMfaRecoveryCodes( - {required String userId}) async { - final String apiPath = - '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.MfaRecoveryCodes.fromMap(res.data); - } - - /// Update name - /// - /// Update the user name by its unique ID. - Future<models.User> updateName( - {required String userId, required String name}) async { - final String apiPath = - '/users/{userId}/name'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - 'name': name, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update password - /// - /// Update the user password by its unique ID. - Future<models.User> updatePassword( - {required String userId, required String password}) async { - final String apiPath = - '/users/{userId}/password'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - 'password': password, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update phone - /// - /// Update the user phone by its unique ID. - Future<models.User> updatePhone( - {required String userId, required String number}) async { - final String apiPath = - '/users/{userId}/phone'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - 'number': number, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Get user preferences - /// - /// Get the user preferences by its unique ID. - Future<models.Preferences> getPrefs({required String userId}) async { - final String apiPath = - '/users/{userId}/prefs'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - } - - /// Update user preferences - /// - /// Update the user preferences by its unique ID. 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<models.Preferences> updatePrefs( - {required String userId, required Map prefs}) async { - final String apiPath = - '/users/{userId}/prefs'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - 'prefs': prefs, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Preferences.fromMap(res.data); - } - - /// List user sessions - /// - /// Get the user sessions list by its unique ID. - Future<models.SessionList> listSessions({required String userId}) async { - final String apiPath = - '/users/{userId}/sessions'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.SessionList.fromMap(res.data); - } - - /// Create session - /// - /// Creates a session for a user. Returns an immediately usable session object. - /// - /// If you want to generate a token for a custom authentication flow, use the - /// [POST - /// /users/{userId}/tokens](https://appwrite.io/docs/server/users#createToken) - /// endpoint. - Future<models.Session> createSession({required String userId}) async { - final String apiPath = - '/users/{userId}/sessions'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Session.fromMap(res.data); - } - - /// Delete user sessions - /// - /// Delete all user's sessions by using the user's unique ID. - Future deleteSessions({required String userId}) async { - final String apiPath = - '/users/{userId}/sessions'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Delete user session - /// - /// Delete a user sessions by its unique ID. - Future deleteSession( - {required String userId, required String sessionId}) async { - final String apiPath = '/users/{userId}/sessions/{sessionId}' - .replaceAll('{userId}', userId) - .replaceAll('{sessionId}', sessionId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Update user status - /// - /// Update the user status by its unique ID. Use this endpoint as an - /// alternative to deleting a user if you want to keep user's ID reserved. - Future<models.User> updateStatus( - {required String userId, required bool status}) async { - final String apiPath = - '/users/{userId}/status'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - 'status': status, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// List user targets - /// - /// List the messaging targets that are associated with a user. - Future<models.TargetList> listTargets( - {required String userId, List<String>? queries}) async { - final String apiPath = - '/users/{userId}/targets'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - 'queries': queries, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.TargetList.fromMap(res.data); - } - - /// Create user target - /// - /// Create a messaging target. - Future<models.Target> createTarget( - {required String userId, - required String targetId, - required enums.MessagingProviderType providerType, - required String identifier, - String? providerId, - String? name}) async { - final String apiPath = - '/users/{userId}/targets'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - 'targetId': targetId, - 'providerType': providerType.value, - 'identifier': identifier, - 'providerId': providerId, - 'name': name, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Target.fromMap(res.data); - } - - /// Get user target - /// - /// Get a user's push notification target by ID. - Future<models.Target> getTarget( - {required String userId, required String targetId}) async { - final String apiPath = '/users/{userId}/targets/{targetId}' - .replaceAll('{userId}', userId) - .replaceAll('{targetId}', targetId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.get, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Target.fromMap(res.data); - } - - /// Update user target - /// - /// Update a messaging target. - Future<models.Target> updateTarget( - {required String userId, - required String targetId, - String? identifier, - String? providerId, - String? name}) async { - final String apiPath = '/users/{userId}/targets/{targetId}' - .replaceAll('{userId}', userId) - .replaceAll('{targetId}', targetId); - - final Map<String, dynamic> apiParams = { - 'identifier': identifier, - 'providerId': providerId, - 'name': name, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Target.fromMap(res.data); - } - - /// Delete user target - /// - /// Delete a messaging target. - Future deleteTarget( - {required String userId, required String targetId}) async { - final String apiPath = '/users/{userId}/targets/{targetId}' - .replaceAll('{userId}', userId) - .replaceAll('{targetId}', targetId); - - final Map<String, dynamic> apiParams = {}; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.delete, - path: apiPath, params: apiParams, headers: apiHeaders); - - return res.data; - } - - /// Create token - /// - /// Returns a token with a secret key for creating a session. Use the user ID - /// and secret and submit a request to the [PUT - /// /account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - /// endpoint to complete the login process. - /// - Future<models.Token> createToken( - {required String userId, int? length, int? expire}) async { - final String apiPath = - '/users/{userId}/tokens'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - 'length': length, - 'expire': expire, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.post, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.Token.fromMap(res.data); - } - - /// Update email verification - /// - /// Update the user email verification status by its unique ID. - Future<models.User> updateEmailVerification( - {required String userId, required bool emailVerification}) async { - final String apiPath = - '/users/{userId}/verification'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - 'emailVerification': emailVerification, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } - - /// Update phone verification - /// - /// Update the user phone verification status by its unique ID. - Future<models.User> updatePhoneVerification( - {required String userId, required bool phoneVerification}) async { - final String apiPath = - '/users/{userId}/verification/phone'.replaceAll('{userId}', userId); - - final Map<String, dynamic> apiParams = { - 'phoneVerification': phoneVerification, - }; - - final Map<String, String> apiHeaders = { - 'content-type': 'application/json', - }; - - final res = await client.call(HttpMethod.patch, - path: apiPath, params: apiParams, headers: apiHeaders); - - return models.User.fromMap(res.data); - } -} + Users(super.client); + + /// List users + /// + /// Get a list of all the project's users. You can use the query params to + /// filter your results. + Future<models.UserList> list({List<String>? queries, String? search}) async { + final String apiPath = '/users'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.UserList.fromMap(res.data); + + } + + /// Create user + /// + /// Create a new user. + Future<models.User> create({required String userId, String? email, String? phone, String? password, String? name}) async { + final String apiPath = '/users'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'email': email, +'phone': phone, +'password': password, +'name': name, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with Argon2 password + /// + /// Create a new user. Password provided must be hashed with the + /// [Argon2](https://en.wikipedia.org/wiki/Argon2) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future<models.User> createArgon2User({required String userId, required String email, required String password, String? name}) async { + final String apiPath = '/users/argon2'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'name': name, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with bcrypt password + /// + /// Create a new user. Password provided must be hashed with the + /// [Bcrypt](https://en.wikipedia.org/wiki/Bcrypt) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future<models.User> createBcryptUser({required String userId, required String email, required String password, String? name}) async { + final String apiPath = '/users/bcrypt'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'name': name, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// List identities + /// + /// Get identities for all users. + Future<models.IdentityList> listIdentities({List<String>? queries, String? search}) async { + final String apiPath = '/users/identities'; + + final Map<String, dynamic> apiParams = { + 'queries': queries, +'search': search, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.IdentityList.fromMap(res.data); + + } + + /// Delete identity + /// + /// Delete an identity by its unique ID. + Future deleteIdentity({required String identityId}) async { + final String apiPath = '/users/identities/{identityId}'.replaceAll('{identityId}', identityId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Create user with MD5 password + /// + /// Create a new user. Password provided must be hashed with the + /// [MD5](https://en.wikipedia.org/wiki/MD5) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future<models.User> createMD5User({required String userId, required String email, required String password, String? name}) async { + final String apiPath = '/users/md5'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'name': name, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with PHPass password + /// + /// Create a new user. Password provided must be hashed with the + /// [PHPass](https://www.openwall.com/phpass/) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future<models.User> createPHPassUser({required String userId, required String email, required String password, String? name}) async { + final String apiPath = '/users/phpass'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'name': name, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with Scrypt password + /// + /// Create a new user. Password provided must be hashed with the + /// [Scrypt](https://github.com/Tarsnap/scrypt) algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future<models.User> createScryptUser({required String userId, required String email, required String password, required String passwordSalt, required int passwordCpu, required int passwordMemory, required int passwordParallel, required int passwordLength, String? name}) async { + final String apiPath = '/users/scrypt'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'passwordSalt': passwordSalt, +'passwordCpu': passwordCpu, +'passwordMemory': passwordMemory, +'passwordParallel': passwordParallel, +'passwordLength': passwordLength, +'name': name, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with Scrypt modified password + /// + /// Create a new user. Password provided must be hashed with the [Scrypt + /// Modified](https://gist.github.com/Meldiron/eecf84a0225eccb5a378d45bb27462cc) + /// algorithm. Use the [POST + /// /users](https://appwrite.io/docs/server/users#usersCreate) endpoint to + /// create users with a plain text password. + Future<models.User> createScryptModifiedUser({required String userId, required String email, required String password, required String passwordSalt, required String passwordSaltSeparator, required String passwordSignerKey, String? name}) async { + final String apiPath = '/users/scrypt-modified'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'passwordSalt': passwordSalt, +'passwordSaltSeparator': passwordSaltSeparator, +'passwordSignerKey': passwordSignerKey, +'name': name, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user with SHA password + /// + /// Create a new user. Password provided must be hashed with the + /// [SHA](https://en.wikipedia.org/wiki/Secure_Hash_Algorithm) algorithm. Use + /// the [POST /users](https://appwrite.io/docs/server/users#usersCreate) + /// endpoint to create users with a plain text password. + Future<models.User> createSHAUser({required String userId, required String email, required String password, enums.PasswordHash? passwordVersion, String? name}) async { + final String apiPath = '/users/sha'; + + final Map<String, dynamic> apiParams = { + + 'userId': userId, +'email': email, +'password': password, +'passwordVersion': passwordVersion?.value, +'name': name, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Get user + /// + /// Get a user by its unique ID. + Future<models.User> get({required String userId}) async { + final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Delete user + /// + /// Delete a user by its unique ID, thereby releasing it's ID. Since ID is + /// released and can be reused, all user-related resources like documents or + /// storage files should be deleted before user deletion. If you want to keep + /// ID reserved, use the + /// [updateStatus](https://appwrite.io/docs/server/users#usersUpdateStatus) + /// endpoint instead. + Future delete({required String userId}) async { + final String apiPath = '/users/{userId}'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Update email + /// + /// Update the user email by its unique ID. + Future<models.User> updateEmail({required String userId, required String email}) async { + final String apiPath = '/users/{userId}/email'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + 'email': email, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Create user JWT + /// + /// Use this endpoint to create a JSON Web Token for user by its unique ID. You + /// can use the resulting JWT to authenticate on behalf of the user. The JWT + /// secret will become invalid if the session it uses gets deleted. + Future<models.Jwt> createJWT({required String userId, String? sessionId, int? duration}) async { + final String apiPath = '/users/{userId}/jwts'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + 'sessionId': sessionId, +'duration': duration, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Jwt.fromMap(res.data); + + } + + /// Update user labels + /// + /// Update the user labels by its unique ID. + /// + /// Labels can be used to grant access to resources. While teams are a way for + /// user's to share access to a resource, labels can be defined by the + /// developer to grant access without an invitation. See the [Permissions + /// docs](https://appwrite.io/docs/permissions) for more info. + Future<models.User> updateLabels({required String userId, required List<String> labels}) async { + final String apiPath = '/users/{userId}/labels'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + 'labels': labels, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// List user logs + /// + /// Get the user activity logs list by its unique ID. + Future<models.LogList> listLogs({required String userId, List<String>? queries}) async { + final String apiPath = '/users/{userId}/logs'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.LogList.fromMap(res.data); + + } + + /// List user memberships + /// + /// Get the user membership list by its unique ID. + Future<models.MembershipList> listMemberships({required String userId}) async { + final String apiPath = '/users/{userId}/memberships'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MembershipList.fromMap(res.data); + + } + + /// Update MFA + /// + /// Enable or disable MFA on a user account. + Future<models.User> updateMfa({required String userId, required bool mfa}) async { + final String apiPath = '/users/{userId}/mfa'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + 'mfa': mfa, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Delete authenticator + /// + /// Delete an authenticator app. + Future deleteMfaAuthenticator({required String userId, required enums.AuthenticatorType type}) async { + final String apiPath = '/users/{userId}/mfa/authenticators/{type}'.replaceAll('{userId}', userId).replaceAll('{type}', type.value); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// List factors + /// + /// List the factors available on the account to be used as a MFA challange. + Future<models.MfaFactors> listMfaFactors({required String userId}) async { + final String apiPath = '/users/{userId}/mfa/factors'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaFactors.fromMap(res.data); + + } + + /// Get MFA recovery codes + /// + /// Get recovery codes that can be used as backup for MFA flow by User ID. + /// Before getting codes, they must be generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. + Future<models.MfaRecoveryCodes> getMfaRecoveryCodes({required String userId}) async { + final String apiPath = '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Regenerate MFA recovery codes + /// + /// Regenerate recovery codes that can be used as backup for MFA flow by User + /// ID. Before regenerating codes, they must be first generated using + /// [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) + /// method. + Future<models.MfaRecoveryCodes> updateMfaRecoveryCodes({required String userId}) async { + final String apiPath = '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.put, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Create MFA recovery codes + /// + /// Generate recovery codes used as backup for MFA flow for User ID. Recovery + /// codes can be used as a MFA verification type in + /// [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) + /// method by client SDK. + Future<models.MfaRecoveryCodes> createMfaRecoveryCodes({required String userId}) async { + final String apiPath = '/users/{userId}/mfa/recovery-codes'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.MfaRecoveryCodes.fromMap(res.data); + + } + + /// Update name + /// + /// Update the user name by its unique ID. + Future<models.User> updateName({required String userId, required String name}) async { + final String apiPath = '/users/{userId}/name'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + 'name': name, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update password + /// + /// Update the user password by its unique ID. + Future<models.User> updatePassword({required String userId, required String password}) async { + final String apiPath = '/users/{userId}/password'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + 'password': password, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update phone + /// + /// Update the user phone by its unique ID. + Future<models.User> updatePhone({required String userId, required String number}) async { + final String apiPath = '/users/{userId}/phone'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + 'number': number, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Get user preferences + /// + /// Get the user preferences by its unique ID. + Future<models.Preferences> getPrefs({required String userId}) async { + final String apiPath = '/users/{userId}/prefs'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + + } + + /// Update user preferences + /// + /// Update the user preferences by its unique ID. 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<models.Preferences> updatePrefs({required String userId, required Map prefs}) async { + final String apiPath = '/users/{userId}/prefs'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + 'prefs': prefs, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Preferences.fromMap(res.data); + + } + + /// List user sessions + /// + /// Get the user sessions list by its unique ID. + Future<models.SessionList> listSessions({required String userId}) async { + final String apiPath = '/users/{userId}/sessions'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.SessionList.fromMap(res.data); + + } + + /// Create session + /// + /// Creates a session for a user. Returns an immediately usable session object. + /// + /// If you want to generate a token for a custom authentication flow, use the + /// [POST + /// /users/{userId}/tokens](https://appwrite.io/docs/server/users#createToken) + /// endpoint. + Future<models.Session> createSession({required String userId}) async { + final String apiPath = '/users/{userId}/sessions'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Session.fromMap(res.data); + + } + + /// Delete user sessions + /// + /// Delete all user's sessions by using the user's unique ID. + Future deleteSessions({required String userId}) async { + final String apiPath = '/users/{userId}/sessions'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Delete user session + /// + /// Delete a user sessions by its unique ID. + Future deleteSession({required String userId, required String sessionId}) async { + final String apiPath = '/users/{userId}/sessions/{sessionId}'.replaceAll('{userId}', userId).replaceAll('{sessionId}', sessionId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Update user status + /// + /// Update the user status by its unique ID. Use this endpoint as an + /// alternative to deleting a user if you want to keep user's ID reserved. + Future<models.User> updateStatus({required String userId, required bool status}) async { + final String apiPath = '/users/{userId}/status'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + 'status': status, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// List user targets + /// + /// List the messaging targets that are associated with a user. + Future<models.TargetList> listTargets({required String userId, List<String>? queries}) async { + final String apiPath = '/users/{userId}/targets'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + 'queries': queries, + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.TargetList.fromMap(res.data); + + } + + /// Create user target + /// + /// Create a messaging target. + Future<models.Target> createTarget({required String userId, required String targetId, required enums.MessagingProviderType providerType, required String identifier, String? providerId, String? name}) async { + final String apiPath = '/users/{userId}/targets'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + 'targetId': targetId, +'providerType': providerType.value, +'identifier': identifier, +'providerId': providerId, +'name': name, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Target.fromMap(res.data); + + } + + /// Get user target + /// + /// Get a user's push notification target by ID. + Future<models.Target> getTarget({required String userId, required String targetId}) async { + final String apiPath = '/users/{userId}/targets/{targetId}'.replaceAll('{userId}', userId).replaceAll('{targetId}', targetId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Target.fromMap(res.data); + + } + + /// Update user target + /// + /// Update a messaging target. + Future<models.Target> updateTarget({required String userId, required String targetId, String? identifier, String? providerId, String? name}) async { + final String apiPath = '/users/{userId}/targets/{targetId}'.replaceAll('{userId}', userId).replaceAll('{targetId}', targetId); + + final Map<String, dynamic> apiParams = { + + 'identifier': identifier, +'providerId': providerId, +'name': name, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Target.fromMap(res.data); + + } + + /// Delete user target + /// + /// Delete a messaging target. + Future deleteTarget({required String userId, required String targetId}) async { + final String apiPath = '/users/{userId}/targets/{targetId}'.replaceAll('{userId}', userId).replaceAll('{targetId}', targetId); + + final Map<String, dynamic> apiParams = { + + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.delete, path: apiPath, params: apiParams, headers: apiHeaders); + + return res.data; + + } + + /// Create token + /// + /// Returns a token with a secret key for creating a session. Use the user ID + /// and secret and submit a request to the [PUT + /// /account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) + /// endpoint to complete the login process. + /// + Future<models.Token> createToken({required String userId, int? length, int? expire}) async { + final String apiPath = '/users/{userId}/tokens'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + 'length': length, +'expire': expire, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.post, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Token.fromMap(res.data); + + } + + /// Update email verification + /// + /// Update the user email verification status by its unique ID. + Future<models.User> updateEmailVerification({required String userId, required bool emailVerification}) async { + final String apiPath = '/users/{userId}/verification'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + 'emailVerification': emailVerification, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } + + /// Update phone verification + /// + /// Update the user phone verification status by its unique ID. + Future<models.User> updatePhoneVerification({required String userId, required bool phoneVerification}) async { + final String apiPath = '/users/{userId}/verification/phone'.replaceAll('{userId}', userId); + + final Map<String, dynamic> apiParams = { + + 'phoneVerification': phoneVerification, + + }; + + final Map<String, String> apiHeaders = { + 'content-type': 'application/json', + + }; + + final res = await client.call(HttpMethod.patch, path: apiPath, params: apiParams, headers: apiHeaders); + + return models.User.fromMap(res.data); + + } +} \ No newline at end of file diff --git a/lib/src/client.dart b/lib/src/client.dart index bac07cfb..2fc990a5 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -8,7 +8,7 @@ import 'upload_progress.dart'; /// [Client] that handles requests to Appwrite abstract class Client { /// The size for cunked uploads in bytes. - static const int CHUNK_SIZE = 5 * 1024 * 1024; + static const int CHUNK_SIZE = 5*1024*1024; /// Holds configuration such as project. late Map<String, String> config; @@ -27,7 +27,7 @@ abstract class Client { Future<String?> webAuth(Uri url); /// Set self signed to [status]. - /// + /// /// If self signed is true, [Client] will ignore invalid certificates. /// This is helpful in environments where your Appwrite /// instance does not have a valid SSL certificate. @@ -67,6 +67,9 @@ abstract class Client { /// Add headers that should be sent with all API calls. Client addHeader(String key, String value); + /// Sends a "ping" request to Appwrite to verify connectivity. + Future<String> ping(); + /// Upload a file in chunks. Future<Response> chunkedUpload({ required String path, @@ -78,8 +81,7 @@ abstract class Client { }); /// Send the API request. - Future<Response> call( - HttpMethod method, { + Future<Response> call(HttpMethod method, { String path = '', Map<String, String> headers = const {}, Map<String, dynamic> params = const {}, diff --git a/lib/src/client_base.dart b/lib/src/client_base.dart index 95476465..5e0b5c08 100644 --- a/lib/src/client_base.dart +++ b/lib/src/client_base.dart @@ -2,25 +2,21 @@ import 'response.dart'; import 'client.dart'; import 'enums.dart'; -abstract class ClientBase implements Client { +abstract class ClientBase implements Client { /// Your project ID @override ClientBase setProject(value); - /// Your secret API key @override ClientBase setKey(value); - /// Your secret JSON Web Token @override ClientBase setJWT(value); @override ClientBase setLocale(value); - /// The user session to authenticate with @override ClientBase setSession(value); - /// The user agent string of the client that made the request @override ClientBase setForwardedUserAgent(value); @@ -34,6 +30,9 @@ abstract class ClientBase implements Client { @override ClientBase addHeader(String key, String value); + @override + Future<String> ping(); + @override Future<Response> call( HttpMethod method, { diff --git a/lib/src/client_browser.dart b/lib/src/client_browser.dart index 428877a5..cae1c069 100644 --- a/lib/src/client_browser.dart +++ b/lib/src/client_browser.dart @@ -16,7 +16,7 @@ ClientBase createClient({ ClientBrowser(endPoint: endPoint, selfSigned: selfSigned); class ClientBrowser extends ClientBase with ClientMixin { - static const int CHUNK_SIZE = 5 * 1024 * 1024; + static const int CHUNK_SIZE = 5*1024*1024; String _endPoint; Map<String, String>? _headers; @override @@ -33,8 +33,8 @@ class ClientBrowser extends ClientBase with ClientMixin { 'x-sdk-name': 'Dart', 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', - 'x-sdk-version': '12.2.0', - 'X-Appwrite-Response-Format': '1.6.0', + 'x-sdk-version': '12.2.1', + 'X-Appwrite-Response-Format' : '1.6.0', }; config = {}; @@ -46,52 +46,47 @@ class ClientBrowser extends ClientBase with ClientMixin { @override String get endPoint => _endPoint; - /// Your project ID - @override - ClientBrowser setProject(value) { - config['project'] = value; - addHeader('X-Appwrite-Project', value); - return this; - } - - /// Your secret API key - @override - ClientBrowser setKey(value) { - config['key'] = value; - addHeader('X-Appwrite-Key', value); - return this; - } - - /// Your secret JSON Web Token - @override - ClientBrowser setJWT(value) { - config['jWT'] = value; - addHeader('X-Appwrite-JWT', value); - return this; - } - - @override - ClientBrowser setLocale(value) { - config['locale'] = value; - addHeader('X-Appwrite-Locale', value); - return this; - } - - /// The user session to authenticate with - @override - ClientBrowser setSession(value) { - config['session'] = value; - addHeader('X-Appwrite-Session', value); - return this; - } - - /// The user agent string of the client that made the request - @override - ClientBrowser setForwardedUserAgent(value) { - config['forwardedUserAgent'] = value; - addHeader('X-Forwarded-User-Agent', value); - return this; - } + /// Your project ID + @override + ClientBrowser setProject(value) { + config['project'] = value; + addHeader('X-Appwrite-Project', value); + return this; + } + /// Your secret API key + @override + ClientBrowser setKey(value) { + config['key'] = value; + addHeader('X-Appwrite-Key', value); + return this; + } + /// Your secret JSON Web Token + @override + ClientBrowser setJWT(value) { + config['jWT'] = value; + addHeader('X-Appwrite-JWT', value); + return this; + } + @override + ClientBrowser setLocale(value) { + config['locale'] = value; + addHeader('X-Appwrite-Locale', value); + return this; + } + /// The user session to authenticate with + @override + ClientBrowser setSession(value) { + config['session'] = value; + addHeader('X-Appwrite-Session', value); + return this; + } + /// The user agent string of the client that made the request + @override + ClientBrowser setForwardedUserAgent(value) { + config['forwardedUserAgent'] = value; + addHeader('X-Forwarded-User-Agent', value); + return this; + } @override ClientBrowser setSelfSigned({bool status = true}) { @@ -110,6 +105,14 @@ class ClientBrowser extends ClientBase with ClientMixin { return this; } + @override + Future<String> ping() async { + final String apiPath = '/ping'; + final response = await call(HttpMethod.get, path: apiPath, responseType: ResponseType.plain); + + return response.data; + } + @override Future<String?> webAuth(Uri url) async { final request = http.Request('GET', url); @@ -136,8 +139,7 @@ class ClientBrowser extends ClientBase with ClientMixin { late Response res; if (size <= CHUNK_SIZE) { - params[paramName] = http.MultipartFile.fromBytes(paramName, file.bytes!, - filename: file.filename); + params[paramName] = http.MultipartFile.fromBytes(paramName, file.bytes!, filename: file.filename); return call( HttpMethod.post, path: path, @@ -147,7 +149,7 @@ class ClientBrowser extends ClientBase with ClientMixin { } var offset = 0; - if (idParamName.isNotEmpty && params[idParamName] != 'unique()') { + if (idParamName.isNotEmpty) { //make a request to check if a file already exists try { res = await call( @@ -164,8 +166,8 @@ class ClientBrowser extends ClientBase with ClientMixin { List<int> chunk = []; final end = min(offset + CHUNK_SIZE, size); chunk = file.bytes!.getRange(offset, end).toList(); - params[paramName] = http.MultipartFile.fromBytes(paramName, chunk, - filename: file.filename); + params[paramName] = + http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename); headers['content-range'] = 'bytes $offset-${min<int>((offset + CHUNK_SIZE - 1), size - 1)}/$size'; res = await call(HttpMethod.post, diff --git a/lib/src/client_io.dart b/lib/src/client_io.dart index f0b5c028..2c2ae44a 100644 --- a/lib/src/client_io.dart +++ b/lib/src/client_io.dart @@ -20,7 +20,7 @@ ClientBase createClient({ ); class ClientIO extends ClientBase with ClientMixin { - static const int CHUNK_SIZE = 5 * 1024 * 1024; + static const int CHUNK_SIZE = 5*1024*1024; String _endPoint; Map<String, String>? _headers; @override @@ -42,10 +42,9 @@ class ClientIO extends ClientBase with ClientMixin { 'x-sdk-name': 'Dart', 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', - 'x-sdk-version': '12.2.0', - 'user-agent': - 'AppwriteDartSDK/12.2.0 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', - 'X-Appwrite-Response-Format': '1.6.0', + 'x-sdk-version': '12.2.1', + 'user-agent' : 'AppwriteDartSDK/12.2.1 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', + 'X-Appwrite-Response-Format' : '1.6.0', }; config = {}; @@ -57,52 +56,47 @@ class ClientIO extends ClientBase with ClientMixin { @override String get endPoint => _endPoint; - /// Your project ID - @override - ClientIO setProject(value) { - config['project'] = value; - addHeader('X-Appwrite-Project', value); - return this; - } - - /// Your secret API key - @override - ClientIO setKey(value) { - config['key'] = value; - addHeader('X-Appwrite-Key', value); - return this; - } - - /// Your secret JSON Web Token - @override - ClientIO setJWT(value) { - config['jWT'] = value; - addHeader('X-Appwrite-JWT', value); - return this; - } - - @override - ClientIO setLocale(value) { - config['locale'] = value; - addHeader('X-Appwrite-Locale', value); - return this; - } - - /// The user session to authenticate with - @override - ClientIO setSession(value) { - config['session'] = value; - addHeader('X-Appwrite-Session', value); - return this; - } - - /// The user agent string of the client that made the request - @override - ClientIO setForwardedUserAgent(value) { - config['forwardedUserAgent'] = value; - addHeader('X-Forwarded-User-Agent', value); - return this; - } + /// Your project ID + @override + ClientIO setProject(value) { + config['project'] = value; + addHeader('X-Appwrite-Project', value); + return this; + } + /// Your secret API key + @override + ClientIO setKey(value) { + config['key'] = value; + addHeader('X-Appwrite-Key', value); + return this; + } + /// Your secret JSON Web Token + @override + ClientIO setJWT(value) { + config['jWT'] = value; + addHeader('X-Appwrite-JWT', value); + return this; + } + @override + ClientIO setLocale(value) { + config['locale'] = value; + addHeader('X-Appwrite-Locale', value); + return this; + } + /// The user session to authenticate with + @override + ClientIO setSession(value) { + config['session'] = value; + addHeader('X-Appwrite-Session', value); + return this; + } + /// The user agent string of the client that made the request + @override + ClientIO setForwardedUserAgent(value) { + config['forwardedUserAgent'] = value; + addHeader('X-Forwarded-User-Agent', value); + return this; + } @override ClientIO setSelfSigned({bool status = true}) { @@ -123,6 +117,14 @@ class ClientIO extends ClientBase with ClientMixin { return this; } + @override + Future<String> ping() async { + final String apiPath = '/ping'; + final response = await call(HttpMethod.get, path: apiPath, responseType: ResponseType.plain); + + return response.data; + } + @override Future<Response> chunkedUpload({ required String path, @@ -168,7 +170,7 @@ class ClientIO extends ClientBase with ClientMixin { } var offset = 0; - if (idParamName.isNotEmpty && params[idParamName] != 'unique()') { + if (idParamName.isNotEmpty) { //make a request to check if a file already exists try { res = await call( @@ -196,8 +198,8 @@ class ClientIO extends ClientBase with ClientMixin { raf!.setPositionSync(offset); chunk = raf.readSync(CHUNK_SIZE); } - params[paramName] = http.MultipartFile.fromBytes(paramName, chunk, - filename: file.filename); + params[paramName] = + http.MultipartFile.fromBytes(paramName, chunk, filename: file.filename); headers['content-range'] = 'bytes $offset-${min<int>((offset + CHUNK_SIZE - 1), size - 1)}/$size'; res = await call(HttpMethod.post, diff --git a/lib/src/client_mixin.dart b/lib/src/client_mixin.dart index 1078c313..36bcdbd3 100644 --- a/lib/src/client_mixin.dart +++ b/lib/src/client_mixin.dart @@ -40,7 +40,7 @@ class ClientMixin { } } else if (method == HttpMethod.get) { if (params.isNotEmpty) { - params = params.map((key, value) { + params = params.map((key, value){ if (value is int || value is double) { return MapEntry(key, value.toString()); } @@ -106,23 +106,18 @@ class ClientMixin { return Response(data: data); } - Future<http.Response> toResponse( - http.StreamedResponse streamedResponse) async { - if (streamedResponse.statusCode == 204) { - return http.Response( - '', - streamedResponse.statusCode, - headers: streamedResponse.headers.map((k, v) => - k.toLowerCase() == 'content-type' - ? MapEntry(k, 'text/plain') - : MapEntry(k, v)), - request: streamedResponse.request, - isRedirect: streamedResponse.isRedirect, - persistentConnection: streamedResponse.persistentConnection, - reasonPhrase: streamedResponse.reasonPhrase, - ); - } else { - return await http.Response.fromStream(streamedResponse); - } + Future<http.Response> toResponse(http.StreamedResponse streamedResponse) async { + if(streamedResponse.statusCode == 204) { + return http.Response('', + streamedResponse.statusCode, + headers: streamedResponse.headers.map((k,v) => k.toLowerCase()=='content-type' ? MapEntry(k, 'text/plain') : MapEntry(k,v)), + request: streamedResponse.request, + isRedirect: streamedResponse.isRedirect, + persistentConnection: streamedResponse.persistentConnection, + reasonPhrase: streamedResponse.reasonPhrase, + ); + } else { + return await http.Response.fromStream(streamedResponse); + } } } diff --git a/lib/src/enums/authentication_factor.dart b/lib/src/enums/authentication_factor.dart index 1d5271eb..00d12830 100644 --- a/lib/src/enums/authentication_factor.dart +++ b/lib/src/enums/authentication_factor.dart @@ -1,14 +1,16 @@ part of '../../enums.dart'; enum AuthenticationFactor { - email(value: 'email'), - phone(value: 'phone'), - totp(value: 'totp'), - recoverycode(value: 'recoverycode'); + email(value: 'email'), + phone(value: 'phone'), + totp(value: 'totp'), + recoverycode(value: 'recoverycode'); - const AuthenticationFactor({required this.value}); + const AuthenticationFactor({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/authenticator_type.dart b/lib/src/enums/authenticator_type.dart index c1fe8584..10460393 100644 --- a/lib/src/enums/authenticator_type.dart +++ b/lib/src/enums/authenticator_type.dart @@ -1,11 +1,13 @@ part of '../../enums.dart'; enum AuthenticatorType { - totp(value: 'totp'); + totp(value: 'totp'); - const AuthenticatorType({required this.value}); + const AuthenticatorType({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/browser.dart b/lib/src/enums/browser.dart index 949f4c47..386fa11d 100644 --- a/lib/src/enums/browser.dart +++ b/lib/src/enums/browser.dart @@ -1,24 +1,26 @@ part of '../../enums.dart'; enum Browser { - avantBrowser(value: 'aa'), - androidWebViewBeta(value: 'an'), - googleChrome(value: 'ch'), - googleChromeIOS(value: 'ci'), - googleChromeMobile(value: 'cm'), - chromium(value: 'cr'), - mozillaFirefox(value: 'ff'), - safari(value: 'sf'), - mobileSafari(value: 'mf'), - microsoftEdge(value: 'ps'), - microsoftEdgeIOS(value: 'oi'), - operaMini(value: 'om'), - opera(value: 'op'), - operaNext(value: 'on'); + avantBrowser(value: 'aa'), + androidWebViewBeta(value: 'an'), + googleChrome(value: 'ch'), + googleChromeIOS(value: 'ci'), + googleChromeMobile(value: 'cm'), + chromium(value: 'cr'), + mozillaFirefox(value: 'ff'), + safari(value: 'sf'), + mobileSafari(value: 'mf'), + microsoftEdge(value: 'ps'), + microsoftEdgeIOS(value: 'oi'), + operaMini(value: 'om'), + opera(value: 'op'), + operaNext(value: 'on'); - const Browser({required this.value}); + const Browser({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/compression.dart b/lib/src/enums/compression.dart index 768930d9..209acfb8 100644 --- a/lib/src/enums/compression.dart +++ b/lib/src/enums/compression.dart @@ -1,13 +1,15 @@ part of '../../enums.dart'; enum Compression { - none(value: 'none'), - gzip(value: 'gzip'), - zstd(value: 'zstd'); + none(value: 'none'), + gzip(value: 'gzip'), + zstd(value: 'zstd'); - const Compression({required this.value}); + const Compression({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/credit_card.dart b/lib/src/enums/credit_card.dart index 3a6b256a..7d54fa80 100644 --- a/lib/src/enums/credit_card.dart +++ b/lib/src/enums/credit_card.dart @@ -1,26 +1,28 @@ part of '../../enums.dart'; enum CreditCard { - americanExpress(value: 'amex'), - argencard(value: 'argencard'), - cabal(value: 'cabal'), - cencosud(value: 'cencosud'), - dinersClub(value: 'diners'), - discover(value: 'discover'), - elo(value: 'elo'), - hipercard(value: 'hipercard'), - jCB(value: 'jcb'), - mastercard(value: 'mastercard'), - naranja(value: 'naranja'), - tarjetaShopping(value: 'targeta-shopping'), - unionChinaPay(value: 'union-china-pay'), - visa(value: 'visa'), - mIR(value: 'mir'), - maestro(value: 'maestro'); + americanExpress(value: 'amex'), + argencard(value: 'argencard'), + cabal(value: 'cabal'), + cencosud(value: 'cencosud'), + dinersClub(value: 'diners'), + discover(value: 'discover'), + elo(value: 'elo'), + hipercard(value: 'hipercard'), + jCB(value: 'jcb'), + mastercard(value: 'mastercard'), + naranja(value: 'naranja'), + tarjetaShopping(value: 'targeta-shopping'), + unionChinaPay(value: 'union-china-pay'), + visa(value: 'visa'), + mIR(value: 'mir'), + maestro(value: 'maestro'); - const CreditCard({required this.value}); + const CreditCard({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/execution_method.dart b/lib/src/enums/execution_method.dart index 42954430..7d2d7016 100644 --- a/lib/src/enums/execution_method.dart +++ b/lib/src/enums/execution_method.dart @@ -1,16 +1,18 @@ part of '../../enums.dart'; enum ExecutionMethod { - gET(value: 'GET'), - pOST(value: 'POST'), - pUT(value: 'PUT'), - pATCH(value: 'PATCH'), - dELETE(value: 'DELETE'), - oPTIONS(value: 'OPTIONS'); + gET(value: 'GET'), + pOST(value: 'POST'), + pUT(value: 'PUT'), + pATCH(value: 'PATCH'), + dELETE(value: 'DELETE'), + oPTIONS(value: 'OPTIONS'); - const ExecutionMethod({required this.value}); + const ExecutionMethod({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/flag.dart b/lib/src/enums/flag.dart index a44cb81d..27c25cac 100644 --- a/lib/src/enums/flag.dart +++ b/lib/src/enums/flag.dart @@ -1,205 +1,207 @@ part of '../../enums.dart'; enum Flag { - afghanistan(value: 'af'), - angola(value: 'ao'), - albania(value: 'al'), - andorra(value: 'ad'), - unitedArabEmirates(value: 'ae'), - argentina(value: 'ar'), - armenia(value: 'am'), - antiguaAndBarbuda(value: 'ag'), - australia(value: 'au'), - austria(value: 'at'), - azerbaijan(value: 'az'), - burundi(value: 'bi'), - belgium(value: 'be'), - benin(value: 'bj'), - burkinaFaso(value: 'bf'), - bangladesh(value: 'bd'), - bulgaria(value: 'bg'), - bahrain(value: 'bh'), - bahamas(value: 'bs'), - bosniaAndHerzegovina(value: 'ba'), - belarus(value: 'by'), - belize(value: 'bz'), - bolivia(value: 'bo'), - brazil(value: 'br'), - barbados(value: 'bb'), - bruneiDarussalam(value: 'bn'), - bhutan(value: 'bt'), - botswana(value: 'bw'), - centralAfricanRepublic(value: 'cf'), - canada(value: 'ca'), - switzerland(value: 'ch'), - chile(value: 'cl'), - china(value: 'cn'), - coteDIvoire(value: 'ci'), - cameroon(value: 'cm'), - democraticRepublicOfTheCongo(value: 'cd'), - republicOfTheCongo(value: 'cg'), - colombia(value: 'co'), - comoros(value: 'km'), - capeVerde(value: 'cv'), - costaRica(value: 'cr'), - cuba(value: 'cu'), - cyprus(value: 'cy'), - czechRepublic(value: 'cz'), - germany(value: 'de'), - djibouti(value: 'dj'), - dominica(value: 'dm'), - denmark(value: 'dk'), - dominicanRepublic(value: 'do'), - algeria(value: 'dz'), - ecuador(value: 'ec'), - egypt(value: 'eg'), - eritrea(value: 'er'), - spain(value: 'es'), - estonia(value: 'ee'), - ethiopia(value: 'et'), - finland(value: 'fi'), - fiji(value: 'fj'), - france(value: 'fr'), - micronesiaFederatedStatesOf(value: 'fm'), - gabon(value: 'ga'), - unitedKingdom(value: 'gb'), - georgia(value: 'ge'), - ghana(value: 'gh'), - guinea(value: 'gn'), - gambia(value: 'gm'), - guineaBissau(value: 'gw'), - equatorialGuinea(value: 'gq'), - greece(value: 'gr'), - grenada(value: 'gd'), - guatemala(value: 'gt'), - guyana(value: 'gy'), - honduras(value: 'hn'), - croatia(value: 'hr'), - haiti(value: 'ht'), - hungary(value: 'hu'), - indonesia(value: 'id'), - india(value: 'in'), - ireland(value: 'ie'), - iranIslamicRepublicOf(value: 'ir'), - iraq(value: 'iq'), - iceland(value: 'is'), - israel(value: 'il'), - italy(value: 'it'), - jamaica(value: 'jm'), - jordan(value: 'jo'), - japan(value: 'jp'), - kazakhstan(value: 'kz'), - kenya(value: 'ke'), - kyrgyzstan(value: 'kg'), - cambodia(value: 'kh'), - kiribati(value: 'ki'), - saintKittsAndNevis(value: 'kn'), - southKorea(value: 'kr'), - kuwait(value: 'kw'), - laoPeopleSDemocraticRepublic(value: 'la'), - lebanon(value: 'lb'), - liberia(value: 'lr'), - libya(value: 'ly'), - saintLucia(value: 'lc'), - liechtenstein(value: 'li'), - sriLanka(value: 'lk'), - lesotho(value: 'ls'), - lithuania(value: 'lt'), - luxembourg(value: 'lu'), - latvia(value: 'lv'), - morocco(value: 'ma'), - monaco(value: 'mc'), - moldova(value: 'md'), - madagascar(value: 'mg'), - maldives(value: 'mv'), - mexico(value: 'mx'), - marshallIslands(value: 'mh'), - northMacedonia(value: 'mk'), - mali(value: 'ml'), - malta(value: 'mt'), - myanmar(value: 'mm'), - montenegro(value: 'me'), - mongolia(value: 'mn'), - mozambique(value: 'mz'), - mauritania(value: 'mr'), - mauritius(value: 'mu'), - malawi(value: 'mw'), - malaysia(value: 'my'), - namibia(value: 'na'), - niger(value: 'ne'), - nigeria(value: 'ng'), - nicaragua(value: 'ni'), - netherlands(value: 'nl'), - norway(value: 'no'), - nepal(value: 'np'), - nauru(value: 'nr'), - newZealand(value: 'nz'), - oman(value: 'om'), - pakistan(value: 'pk'), - panama(value: 'pa'), - peru(value: 'pe'), - philippines(value: 'ph'), - palau(value: 'pw'), - papuaNewGuinea(value: 'pg'), - poland(value: 'pl'), - frenchPolynesia(value: 'pf'), - northKorea(value: 'kp'), - portugal(value: 'pt'), - paraguay(value: 'py'), - qatar(value: 'qa'), - romania(value: 'ro'), - russia(value: 'ru'), - rwanda(value: 'rw'), - saudiArabia(value: 'sa'), - sudan(value: 'sd'), - senegal(value: 'sn'), - singapore(value: 'sg'), - solomonIslands(value: 'sb'), - sierraLeone(value: 'sl'), - elSalvador(value: 'sv'), - sanMarino(value: 'sm'), - somalia(value: 'so'), - serbia(value: 'rs'), - southSudan(value: 'ss'), - saoTomeAndPrincipe(value: 'st'), - suriname(value: 'sr'), - slovakia(value: 'sk'), - slovenia(value: 'si'), - sweden(value: 'se'), - eswatini(value: 'sz'), - seychelles(value: 'sc'), - syria(value: 'sy'), - chad(value: 'td'), - togo(value: 'tg'), - thailand(value: 'th'), - tajikistan(value: 'tj'), - turkmenistan(value: 'tm'), - timorLeste(value: 'tl'), - tonga(value: 'to'), - trinidadAndTobago(value: 'tt'), - tunisia(value: 'tn'), - turkey(value: 'tr'), - tuvalu(value: 'tv'), - tanzania(value: 'tz'), - uganda(value: 'ug'), - ukraine(value: 'ua'), - uruguay(value: 'uy'), - unitedStates(value: 'us'), - uzbekistan(value: 'uz'), - vaticanCity(value: 'va'), - saintVincentAndTheGrenadines(value: 'vc'), - venezuela(value: 've'), - vietnam(value: 'vn'), - vanuatu(value: 'vu'), - samoa(value: 'ws'), - yemen(value: 'ye'), - southAfrica(value: 'za'), - zambia(value: 'zm'), - zimbabwe(value: 'zw'); + afghanistan(value: 'af'), + angola(value: 'ao'), + albania(value: 'al'), + andorra(value: 'ad'), + unitedArabEmirates(value: 'ae'), + argentina(value: 'ar'), + armenia(value: 'am'), + antiguaAndBarbuda(value: 'ag'), + australia(value: 'au'), + austria(value: 'at'), + azerbaijan(value: 'az'), + burundi(value: 'bi'), + belgium(value: 'be'), + benin(value: 'bj'), + burkinaFaso(value: 'bf'), + bangladesh(value: 'bd'), + bulgaria(value: 'bg'), + bahrain(value: 'bh'), + bahamas(value: 'bs'), + bosniaAndHerzegovina(value: 'ba'), + belarus(value: 'by'), + belize(value: 'bz'), + bolivia(value: 'bo'), + brazil(value: 'br'), + barbados(value: 'bb'), + bruneiDarussalam(value: 'bn'), + bhutan(value: 'bt'), + botswana(value: 'bw'), + centralAfricanRepublic(value: 'cf'), + canada(value: 'ca'), + switzerland(value: 'ch'), + chile(value: 'cl'), + china(value: 'cn'), + coteDIvoire(value: 'ci'), + cameroon(value: 'cm'), + democraticRepublicOfTheCongo(value: 'cd'), + republicOfTheCongo(value: 'cg'), + colombia(value: 'co'), + comoros(value: 'km'), + capeVerde(value: 'cv'), + costaRica(value: 'cr'), + cuba(value: 'cu'), + cyprus(value: 'cy'), + czechRepublic(value: 'cz'), + germany(value: 'de'), + djibouti(value: 'dj'), + dominica(value: 'dm'), + denmark(value: 'dk'), + dominicanRepublic(value: 'do'), + algeria(value: 'dz'), + ecuador(value: 'ec'), + egypt(value: 'eg'), + eritrea(value: 'er'), + spain(value: 'es'), + estonia(value: 'ee'), + ethiopia(value: 'et'), + finland(value: 'fi'), + fiji(value: 'fj'), + france(value: 'fr'), + micronesiaFederatedStatesOf(value: 'fm'), + gabon(value: 'ga'), + unitedKingdom(value: 'gb'), + georgia(value: 'ge'), + ghana(value: 'gh'), + guinea(value: 'gn'), + gambia(value: 'gm'), + guineaBissau(value: 'gw'), + equatorialGuinea(value: 'gq'), + greece(value: 'gr'), + grenada(value: 'gd'), + guatemala(value: 'gt'), + guyana(value: 'gy'), + honduras(value: 'hn'), + croatia(value: 'hr'), + haiti(value: 'ht'), + hungary(value: 'hu'), + indonesia(value: 'id'), + india(value: 'in'), + ireland(value: 'ie'), + iranIslamicRepublicOf(value: 'ir'), + iraq(value: 'iq'), + iceland(value: 'is'), + israel(value: 'il'), + italy(value: 'it'), + jamaica(value: 'jm'), + jordan(value: 'jo'), + japan(value: 'jp'), + kazakhstan(value: 'kz'), + kenya(value: 'ke'), + kyrgyzstan(value: 'kg'), + cambodia(value: 'kh'), + kiribati(value: 'ki'), + saintKittsAndNevis(value: 'kn'), + southKorea(value: 'kr'), + kuwait(value: 'kw'), + laoPeopleSDemocraticRepublic(value: 'la'), + lebanon(value: 'lb'), + liberia(value: 'lr'), + libya(value: 'ly'), + saintLucia(value: 'lc'), + liechtenstein(value: 'li'), + sriLanka(value: 'lk'), + lesotho(value: 'ls'), + lithuania(value: 'lt'), + luxembourg(value: 'lu'), + latvia(value: 'lv'), + morocco(value: 'ma'), + monaco(value: 'mc'), + moldova(value: 'md'), + madagascar(value: 'mg'), + maldives(value: 'mv'), + mexico(value: 'mx'), + marshallIslands(value: 'mh'), + northMacedonia(value: 'mk'), + mali(value: 'ml'), + malta(value: 'mt'), + myanmar(value: 'mm'), + montenegro(value: 'me'), + mongolia(value: 'mn'), + mozambique(value: 'mz'), + mauritania(value: 'mr'), + mauritius(value: 'mu'), + malawi(value: 'mw'), + malaysia(value: 'my'), + namibia(value: 'na'), + niger(value: 'ne'), + nigeria(value: 'ng'), + nicaragua(value: 'ni'), + netherlands(value: 'nl'), + norway(value: 'no'), + nepal(value: 'np'), + nauru(value: 'nr'), + newZealand(value: 'nz'), + oman(value: 'om'), + pakistan(value: 'pk'), + panama(value: 'pa'), + peru(value: 'pe'), + philippines(value: 'ph'), + palau(value: 'pw'), + papuaNewGuinea(value: 'pg'), + poland(value: 'pl'), + frenchPolynesia(value: 'pf'), + northKorea(value: 'kp'), + portugal(value: 'pt'), + paraguay(value: 'py'), + qatar(value: 'qa'), + romania(value: 'ro'), + russia(value: 'ru'), + rwanda(value: 'rw'), + saudiArabia(value: 'sa'), + sudan(value: 'sd'), + senegal(value: 'sn'), + singapore(value: 'sg'), + solomonIslands(value: 'sb'), + sierraLeone(value: 'sl'), + elSalvador(value: 'sv'), + sanMarino(value: 'sm'), + somalia(value: 'so'), + serbia(value: 'rs'), + southSudan(value: 'ss'), + saoTomeAndPrincipe(value: 'st'), + suriname(value: 'sr'), + slovakia(value: 'sk'), + slovenia(value: 'si'), + sweden(value: 'se'), + eswatini(value: 'sz'), + seychelles(value: 'sc'), + syria(value: 'sy'), + chad(value: 'td'), + togo(value: 'tg'), + thailand(value: 'th'), + tajikistan(value: 'tj'), + turkmenistan(value: 'tm'), + timorLeste(value: 'tl'), + tonga(value: 'to'), + trinidadAndTobago(value: 'tt'), + tunisia(value: 'tn'), + turkey(value: 'tr'), + tuvalu(value: 'tv'), + tanzania(value: 'tz'), + uganda(value: 'ug'), + ukraine(value: 'ua'), + uruguay(value: 'uy'), + unitedStates(value: 'us'), + uzbekistan(value: 'uz'), + vaticanCity(value: 'va'), + saintVincentAndTheGrenadines(value: 'vc'), + venezuela(value: 've'), + vietnam(value: 'vn'), + vanuatu(value: 'vu'), + samoa(value: 'ws'), + yemen(value: 'ye'), + southAfrica(value: 'za'), + zambia(value: 'zm'), + zimbabwe(value: 'zw'); - const Flag({required this.value}); + const Flag({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/image_format.dart b/lib/src/enums/image_format.dart index acc07f27..2e4e2204 100644 --- a/lib/src/enums/image_format.dart +++ b/lib/src/enums/image_format.dart @@ -1,16 +1,19 @@ part of '../../enums.dart'; enum ImageFormat { - jpg(value: 'jpg'), - jpeg(value: 'jpeg'), - gif(value: 'gif'), - png(value: 'png'), - webp(value: 'webp'), - avif(value: 'avif'); + jpg(value: 'jpg'), + jpeg(value: 'jpeg'), + gif(value: 'gif'), + png(value: 'png'), + webp(value: 'webp'), + heic(value: 'heic'), + avif(value: 'avif'); - const ImageFormat({required this.value}); + const ImageFormat({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/image_gravity.dart b/lib/src/enums/image_gravity.dart index 88029044..79bc4d62 100644 --- a/lib/src/enums/image_gravity.dart +++ b/lib/src/enums/image_gravity.dart @@ -1,19 +1,21 @@ part of '../../enums.dart'; enum ImageGravity { - center(value: 'center'), - topLeft(value: 'top-left'), - top(value: 'top'), - topRight(value: 'top-right'), - left(value: 'left'), - right(value: 'right'), - bottomLeft(value: 'bottom-left'), - bottom(value: 'bottom'), - bottomRight(value: 'bottom-right'); + center(value: 'center'), + topLeft(value: 'top-left'), + top(value: 'top'), + topRight(value: 'top-right'), + left(value: 'left'), + right(value: 'right'), + bottomLeft(value: 'bottom-left'), + bottom(value: 'bottom'), + bottomRight(value: 'bottom-right'); - const ImageGravity({required this.value}); + const ImageGravity({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/index_type.dart b/lib/src/enums/index_type.dart index b101d35f..8d86530d 100644 --- a/lib/src/enums/index_type.dart +++ b/lib/src/enums/index_type.dart @@ -1,13 +1,15 @@ part of '../../enums.dart'; enum IndexType { - key(value: 'key'), - fulltext(value: 'fulltext'), - unique(value: 'unique'); + key(value: 'key'), + fulltext(value: 'fulltext'), + unique(value: 'unique'); - const IndexType({required this.value}); + const IndexType({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/message_priority.dart b/lib/src/enums/message_priority.dart index a07e6f76..375913e8 100644 --- a/lib/src/enums/message_priority.dart +++ b/lib/src/enums/message_priority.dart @@ -1,12 +1,14 @@ part of '../../enums.dart'; enum MessagePriority { - normal(value: 'normal'), - high(value: 'high'); + normal(value: 'normal'), + high(value: 'high'); - const MessagePriority({required this.value}); + const MessagePriority({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/messaging_provider_type.dart b/lib/src/enums/messaging_provider_type.dart index c69bf01e..a6859648 100644 --- a/lib/src/enums/messaging_provider_type.dart +++ b/lib/src/enums/messaging_provider_type.dart @@ -1,13 +1,15 @@ part of '../../enums.dart'; enum MessagingProviderType { - email(value: 'email'), - sms(value: 'sms'), - push(value: 'push'); + email(value: 'email'), + sms(value: 'sms'), + push(value: 'push'); - const MessagingProviderType({required this.value}); + const MessagingProviderType({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/name.dart b/lib/src/enums/name.dart index cb35c288..638017f7 100644 --- a/lib/src/enums/name.dart +++ b/lib/src/enums/name.dart @@ -1,22 +1,24 @@ part of '../../enums.dart'; enum Name { - v1Database(value: 'v1-database'), - v1Deletes(value: 'v1-deletes'), - v1Audits(value: 'v1-audits'), - v1Mails(value: 'v1-mails'), - v1Functions(value: 'v1-functions'), - v1Usage(value: 'v1-usage'), - v1UsageDump(value: 'v1-usage-dump'), - v1Webhooks(value: 'v1-webhooks'), - v1Certificates(value: 'v1-certificates'), - v1Builds(value: 'v1-builds'), - v1Messaging(value: 'v1-messaging'), - v1Migrations(value: 'v1-migrations'); + v1Database(value: 'v1-database'), + v1Deletes(value: 'v1-deletes'), + v1Audits(value: 'v1-audits'), + v1Mails(value: 'v1-mails'), + v1Functions(value: 'v1-functions'), + v1Usage(value: 'v1-usage'), + v1UsageDump(value: 'v1-usage-dump'), + v1Webhooks(value: 'v1-webhooks'), + v1Certificates(value: 'v1-certificates'), + v1Builds(value: 'v1-builds'), + v1Messaging(value: 'v1-messaging'), + v1Migrations(value: 'v1-migrations'); - const Name({required this.value}); + const Name({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/o_auth_provider.dart b/lib/src/enums/o_auth_provider.dart index 2bc1a82a..b09e9df2 100644 --- a/lib/src/enums/o_auth_provider.dart +++ b/lib/src/enums/o_auth_provider.dart @@ -1,49 +1,51 @@ part of '../../enums.dart'; enum OAuthProvider { - amazon(value: 'amazon'), - apple(value: 'apple'), - auth0(value: 'auth0'), - authentik(value: 'authentik'), - autodesk(value: 'autodesk'), - bitbucket(value: 'bitbucket'), - bitly(value: 'bitly'), - box(value: 'box'), - dailymotion(value: 'dailymotion'), - discord(value: 'discord'), - disqus(value: 'disqus'), - dropbox(value: 'dropbox'), - etsy(value: 'etsy'), - facebook(value: 'facebook'), - github(value: 'github'), - gitlab(value: 'gitlab'), - google(value: 'google'), - linkedin(value: 'linkedin'), - microsoft(value: 'microsoft'), - notion(value: 'notion'), - oidc(value: 'oidc'), - okta(value: 'okta'), - paypal(value: 'paypal'), - paypalSandbox(value: 'paypalSandbox'), - podio(value: 'podio'), - salesforce(value: 'salesforce'), - slack(value: 'slack'), - spotify(value: 'spotify'), - stripe(value: 'stripe'), - tradeshift(value: 'tradeshift'), - tradeshiftBox(value: 'tradeshiftBox'), - twitch(value: 'twitch'), - wordpress(value: 'wordpress'), - yahoo(value: 'yahoo'), - yammer(value: 'yammer'), - yandex(value: 'yandex'), - zoho(value: 'zoho'), - zoom(value: 'zoom'), - mock(value: 'mock'); + amazon(value: 'amazon'), + apple(value: 'apple'), + auth0(value: 'auth0'), + authentik(value: 'authentik'), + autodesk(value: 'autodesk'), + bitbucket(value: 'bitbucket'), + bitly(value: 'bitly'), + box(value: 'box'), + dailymotion(value: 'dailymotion'), + discord(value: 'discord'), + disqus(value: 'disqus'), + dropbox(value: 'dropbox'), + etsy(value: 'etsy'), + facebook(value: 'facebook'), + github(value: 'github'), + gitlab(value: 'gitlab'), + google(value: 'google'), + linkedin(value: 'linkedin'), + microsoft(value: 'microsoft'), + notion(value: 'notion'), + oidc(value: 'oidc'), + okta(value: 'okta'), + paypal(value: 'paypal'), + paypalSandbox(value: 'paypalSandbox'), + podio(value: 'podio'), + salesforce(value: 'salesforce'), + slack(value: 'slack'), + spotify(value: 'spotify'), + stripe(value: 'stripe'), + tradeshift(value: 'tradeshift'), + tradeshiftBox(value: 'tradeshiftBox'), + twitch(value: 'twitch'), + wordpress(value: 'wordpress'), + yahoo(value: 'yahoo'), + yammer(value: 'yammer'), + yandex(value: 'yandex'), + zoho(value: 'zoho'), + zoom(value: 'zoom'), + mock(value: 'mock'); - const OAuthProvider({required this.value}); + const OAuthProvider({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/password_hash.dart b/lib/src/enums/password_hash.dart index 9d98c26a..510ee260 100644 --- a/lib/src/enums/password_hash.dart +++ b/lib/src/enums/password_hash.dart @@ -1,21 +1,23 @@ part of '../../enums.dart'; enum PasswordHash { - sha1(value: 'sha1'), - sha224(value: 'sha224'), - sha256(value: 'sha256'), - sha384(value: 'sha384'), - sha512224(value: 'sha512/224'), - sha512256(value: 'sha512/256'), - sha512(value: 'sha512'), - sha3224(value: 'sha3-224'), - sha3256(value: 'sha3-256'), - sha3384(value: 'sha3-384'), - sha3512(value: 'sha3-512'); + sha1(value: 'sha1'), + sha224(value: 'sha224'), + sha256(value: 'sha256'), + sha384(value: 'sha384'), + sha512224(value: 'sha512/224'), + sha512256(value: 'sha512/256'), + sha512(value: 'sha512'), + sha3224(value: 'sha3-224'), + sha3256(value: 'sha3-256'), + sha3384(value: 'sha3-384'), + sha3512(value: 'sha3-512'); - const PasswordHash({required this.value}); + const PasswordHash({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/relation_mutate.dart b/lib/src/enums/relation_mutate.dart index b215a8fa..9f4c1a85 100644 --- a/lib/src/enums/relation_mutate.dart +++ b/lib/src/enums/relation_mutate.dart @@ -1,13 +1,15 @@ part of '../../enums.dart'; enum RelationMutate { - cascade(value: 'cascade'), - restrict(value: 'restrict'), - setNull(value: 'setNull'); + cascade(value: 'cascade'), + restrict(value: 'restrict'), + setNull(value: 'setNull'); - const RelationMutate({required this.value}); + const RelationMutate({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/relationship_type.dart b/lib/src/enums/relationship_type.dart index 30efc944..301bc61d 100644 --- a/lib/src/enums/relationship_type.dart +++ b/lib/src/enums/relationship_type.dart @@ -1,14 +1,16 @@ part of '../../enums.dart'; enum RelationshipType { - oneToOne(value: 'oneToOne'), - manyToOne(value: 'manyToOne'), - manyToMany(value: 'manyToMany'), - oneToMany(value: 'oneToMany'); + oneToOne(value: 'oneToOne'), + manyToOne(value: 'manyToOne'), + manyToMany(value: 'manyToMany'), + oneToMany(value: 'oneToMany'); - const RelationshipType({required this.value}); + const RelationshipType({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/runtime.dart b/lib/src/enums/runtime.dart index a71f5a65..b7dbd129 100644 --- a/lib/src/enums/runtime.dart +++ b/lib/src/enums/runtime.dart @@ -1,69 +1,71 @@ part of '../../enums.dart'; enum Runtime { - node145(value: 'node-14.5'), - node160(value: 'node-16.0'), - node180(value: 'node-18.0'), - node190(value: 'node-19.0'), - node200(value: 'node-20.0'), - node210(value: 'node-21.0'), - node22(value: 'node-22'), - php80(value: 'php-8.0'), - php81(value: 'php-8.1'), - php82(value: 'php-8.2'), - php83(value: 'php-8.3'), - ruby30(value: 'ruby-3.0'), - ruby31(value: 'ruby-3.1'), - ruby32(value: 'ruby-3.2'), - ruby33(value: 'ruby-3.3'), - python38(value: 'python-3.8'), - python39(value: 'python-3.9'), - python310(value: 'python-3.10'), - python311(value: 'python-3.11'), - python312(value: 'python-3.12'), - pythonMl311(value: 'python-ml-3.11'), - deno121(value: 'deno-1.21'), - deno124(value: 'deno-1.24'), - deno135(value: 'deno-1.35'), - deno140(value: 'deno-1.40'), - deno146(value: 'deno-1.46'), - deno20(value: 'deno-2.0'), - dart215(value: 'dart-2.15'), - dart216(value: 'dart-2.16'), - dart217(value: 'dart-2.17'), - dart218(value: 'dart-2.18'), - dart30(value: 'dart-3.0'), - dart31(value: 'dart-3.1'), - dart33(value: 'dart-3.3'), - dart35(value: 'dart-3.5'), - dotnet60(value: 'dotnet-6.0'), - dotnet70(value: 'dotnet-7.0'), - dotnet80(value: 'dotnet-8.0'), - java80(value: 'java-8.0'), - java110(value: 'java-11.0'), - java170(value: 'java-17.0'), - java180(value: 'java-18.0'), - java210(value: 'java-21.0'), - java22(value: 'java-22'), - swift55(value: 'swift-5.5'), - swift58(value: 'swift-5.8'), - swift59(value: 'swift-5.9'), - swift510(value: 'swift-5.10'), - kotlin16(value: 'kotlin-1.6'), - kotlin18(value: 'kotlin-1.8'), - kotlin19(value: 'kotlin-1.9'), - kotlin20(value: 'kotlin-2.0'), - cpp17(value: 'cpp-17'), - cpp20(value: 'cpp-20'), - bun10(value: 'bun-1.0'), - bun11(value: 'bun-1.1'), - go123(value: 'go-1.23'), - static1(value: 'static-1'), - flutter324(value: 'flutter-3.24'); + node145(value: 'node-14.5'), + node160(value: 'node-16.0'), + node180(value: 'node-18.0'), + node190(value: 'node-19.0'), + node200(value: 'node-20.0'), + node210(value: 'node-21.0'), + node22(value: 'node-22'), + php80(value: 'php-8.0'), + php81(value: 'php-8.1'), + php82(value: 'php-8.2'), + php83(value: 'php-8.3'), + ruby30(value: 'ruby-3.0'), + ruby31(value: 'ruby-3.1'), + ruby32(value: 'ruby-3.2'), + ruby33(value: 'ruby-3.3'), + python38(value: 'python-3.8'), + python39(value: 'python-3.9'), + python310(value: 'python-3.10'), + python311(value: 'python-3.11'), + python312(value: 'python-3.12'), + pythonMl311(value: 'python-ml-3.11'), + deno121(value: 'deno-1.21'), + deno124(value: 'deno-1.24'), + deno135(value: 'deno-1.35'), + deno140(value: 'deno-1.40'), + deno146(value: 'deno-1.46'), + deno20(value: 'deno-2.0'), + dart215(value: 'dart-2.15'), + dart216(value: 'dart-2.16'), + dart217(value: 'dart-2.17'), + dart218(value: 'dart-2.18'), + dart30(value: 'dart-3.0'), + dart31(value: 'dart-3.1'), + dart33(value: 'dart-3.3'), + dart35(value: 'dart-3.5'), + dotnet60(value: 'dotnet-6.0'), + dotnet70(value: 'dotnet-7.0'), + dotnet80(value: 'dotnet-8.0'), + java80(value: 'java-8.0'), + java110(value: 'java-11.0'), + java170(value: 'java-17.0'), + java180(value: 'java-18.0'), + java210(value: 'java-21.0'), + java22(value: 'java-22'), + swift55(value: 'swift-5.5'), + swift58(value: 'swift-5.8'), + swift59(value: 'swift-5.9'), + swift510(value: 'swift-5.10'), + kotlin16(value: 'kotlin-1.6'), + kotlin18(value: 'kotlin-1.8'), + kotlin19(value: 'kotlin-1.9'), + kotlin20(value: 'kotlin-2.0'), + cpp17(value: 'cpp-17'), + cpp20(value: 'cpp-20'), + bun10(value: 'bun-1.0'), + bun11(value: 'bun-1.1'), + go123(value: 'go-1.23'), + static1(value: 'static-1'), + flutter324(value: 'flutter-3.24'); - const Runtime({required this.value}); + const Runtime({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/enums/smtp_encryption.dart b/lib/src/enums/smtp_encryption.dart index cb6cee26..6c880ed6 100644 --- a/lib/src/enums/smtp_encryption.dart +++ b/lib/src/enums/smtp_encryption.dart @@ -1,13 +1,15 @@ part of '../../enums.dart'; enum SmtpEncryption { - none(value: 'none'), - ssl(value: 'ssl'), - tls(value: 'tls'); + none(value: 'none'), + ssl(value: 'ssl'), + tls(value: 'tls'); - const SmtpEncryption({required this.value}); + const SmtpEncryption({ + required this.value + }); - final String value; + final String value; - String toJson() => value; -} + String toJson() => value; +} \ No newline at end of file diff --git a/lib/src/exception.dart b/lib/src/exception.dart index 679e27b8..f579bfb8 100644 --- a/lib/src/exception.dart +++ b/lib/src/exception.dart @@ -13,7 +13,7 @@ class AppwriteException implements Exception { /// Initializes an Appwrite Exception. AppwriteException([this.message = "", this.code, this.type, this.response]); - + /// Returns the error type, message, and code. @override String toString() { diff --git a/lib/src/models/algo_argon2.dart b/lib/src/models/algo_argon2.dart index 4145f701..ccb40274 100644 --- a/lib/src/models/algo_argon2.dart +++ b/lib/src/models/algo_argon2.dart @@ -2,40 +2,37 @@ part of '../../models.dart'; /// AlgoArgon2 class AlgoArgon2 implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; + /// Memory used to compute hash. + final int memoryCost; + /// Amount of time consumed to compute hash + final int timeCost; + /// Number of threads used to compute hash. + final int threads; - /// Memory used to compute hash. - final int memoryCost; + AlgoArgon2({ + required this.type, + required this.memoryCost, + required this.timeCost, + required this.threads, + }); - /// Amount of time consumed to compute hash - final int timeCost; + factory AlgoArgon2.fromMap(Map<String, dynamic> map) { + return AlgoArgon2( + type: map['type'].toString(), + memoryCost: map['memoryCost'], + timeCost: map['timeCost'], + threads: map['threads'], + ); + } - /// Number of threads used to compute hash. - final int threads; - - AlgoArgon2({ - required this.type, - required this.memoryCost, - required this.timeCost, - required this.threads, - }); - - factory AlgoArgon2.fromMap(Map<String, dynamic> map) { - return AlgoArgon2( - type: map['type'].toString(), - memoryCost: map['memoryCost'], - timeCost: map['timeCost'], - threads: map['threads'], - ); - } - - Map<String, dynamic> toMap() { - return { - "type": type, - "memoryCost": memoryCost, - "timeCost": timeCost, - "threads": threads, - }; - } -} + Map<String, dynamic> toMap() { + return { + "type": type, + "memoryCost": memoryCost, + "timeCost": timeCost, + "threads": threads, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/algo_bcrypt.dart b/lib/src/models/algo_bcrypt.dart index 2ba0c398..ecfcbc16 100644 --- a/lib/src/models/algo_bcrypt.dart +++ b/lib/src/models/algo_bcrypt.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoBcrypt class AlgoBcrypt implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoBcrypt({ - required this.type, - }); + AlgoBcrypt({ + required this.type, + }); - factory AlgoBcrypt.fromMap(Map<String, dynamic> map) { - return AlgoBcrypt( - type: map['type'].toString(), - ); - } + factory AlgoBcrypt.fromMap(Map<String, dynamic> map) { + return AlgoBcrypt( + type: map['type'].toString(), + ); + } - Map<String, dynamic> toMap() { - return { - "type": type, - }; - } -} + Map<String, dynamic> toMap() { + return { + "type": type, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/algo_md5.dart b/lib/src/models/algo_md5.dart index 8bdfca6f..ddc19256 100644 --- a/lib/src/models/algo_md5.dart +++ b/lib/src/models/algo_md5.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoMD5 class AlgoMd5 implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoMd5({ - required this.type, - }); + AlgoMd5({ + required this.type, + }); - factory AlgoMd5.fromMap(Map<String, dynamic> map) { - return AlgoMd5( - type: map['type'].toString(), - ); - } + factory AlgoMd5.fromMap(Map<String, dynamic> map) { + return AlgoMd5( + type: map['type'].toString(), + ); + } - Map<String, dynamic> toMap() { - return { - "type": type, - }; - } -} + Map<String, dynamic> toMap() { + return { + "type": type, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/algo_phpass.dart b/lib/src/models/algo_phpass.dart index 4f5f9179..0118cf1c 100644 --- a/lib/src/models/algo_phpass.dart +++ b/lib/src/models/algo_phpass.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoPHPass class AlgoPhpass implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoPhpass({ - required this.type, - }); + AlgoPhpass({ + required this.type, + }); - factory AlgoPhpass.fromMap(Map<String, dynamic> map) { - return AlgoPhpass( - type: map['type'].toString(), - ); - } + factory AlgoPhpass.fromMap(Map<String, dynamic> map) { + return AlgoPhpass( + type: map['type'].toString(), + ); + } - Map<String, dynamic> toMap() { - return { - "type": type, - }; - } -} + Map<String, dynamic> toMap() { + return { + "type": type, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/algo_scrypt.dart b/lib/src/models/algo_scrypt.dart index fec6f65a..ead730a4 100644 --- a/lib/src/models/algo_scrypt.dart +++ b/lib/src/models/algo_scrypt.dart @@ -2,46 +2,42 @@ part of '../../models.dart'; /// AlgoScrypt class AlgoScrypt implements Model { - /// Algo type. - final String type; - - /// CPU complexity of computed hash. - final int costCpu; - - /// Memory complexity of computed hash. - final int costMemory; - - /// Parallelization of computed hash. - final int costParallel; - - /// Length used to compute hash. - final int length; - - AlgoScrypt({ - required this.type, - required this.costCpu, - required this.costMemory, - required this.costParallel, - required this.length, - }); - - factory AlgoScrypt.fromMap(Map<String, dynamic> map) { - return AlgoScrypt( - type: map['type'].toString(), - costCpu: map['costCpu'], - costMemory: map['costMemory'], - costParallel: map['costParallel'], - length: map['length'], - ); - } - - Map<String, dynamic> toMap() { - return { - "type": type, - "costCpu": costCpu, - "costMemory": costMemory, - "costParallel": costParallel, - "length": length, - }; - } -} + /// Algo type. + final String type; + /// CPU complexity of computed hash. + final int costCpu; + /// Memory complexity of computed hash. + final int costMemory; + /// Parallelization of computed hash. + final int costParallel; + /// Length used to compute hash. + final int length; + + AlgoScrypt({ + required this.type, + required this.costCpu, + required this.costMemory, + required this.costParallel, + required this.length, + }); + + factory AlgoScrypt.fromMap(Map<String, dynamic> map) { + return AlgoScrypt( + type: map['type'].toString(), + costCpu: map['costCpu'], + costMemory: map['costMemory'], + costParallel: map['costParallel'], + length: map['length'], + ); + } + + Map<String, dynamic> toMap() { + return { + "type": type, + "costCpu": costCpu, + "costMemory": costMemory, + "costParallel": costParallel, + "length": length, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/algo_scrypt_modified.dart b/lib/src/models/algo_scrypt_modified.dart index 0e80700f..2e5d0576 100644 --- a/lib/src/models/algo_scrypt_modified.dart +++ b/lib/src/models/algo_scrypt_modified.dart @@ -2,40 +2,37 @@ part of '../../models.dart'; /// AlgoScryptModified class AlgoScryptModified implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; + /// Salt used to compute hash. + final String salt; + /// Separator used to compute hash. + final String saltSeparator; + /// Key used to compute hash. + final String signerKey; - /// Salt used to compute hash. - final String salt; + AlgoScryptModified({ + required this.type, + required this.salt, + required this.saltSeparator, + required this.signerKey, + }); - /// Separator used to compute hash. - final String saltSeparator; + factory AlgoScryptModified.fromMap(Map<String, dynamic> map) { + return AlgoScryptModified( + type: map['type'].toString(), + salt: map['salt'].toString(), + saltSeparator: map['saltSeparator'].toString(), + signerKey: map['signerKey'].toString(), + ); + } - /// Key used to compute hash. - final String signerKey; - - AlgoScryptModified({ - required this.type, - required this.salt, - required this.saltSeparator, - required this.signerKey, - }); - - factory AlgoScryptModified.fromMap(Map<String, dynamic> map) { - return AlgoScryptModified( - type: map['type'].toString(), - salt: map['salt'].toString(), - saltSeparator: map['saltSeparator'].toString(), - signerKey: map['signerKey'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "type": type, - "salt": salt, - "saltSeparator": saltSeparator, - "signerKey": signerKey, - }; - } -} + Map<String, dynamic> toMap() { + return { + "type": type, + "salt": salt, + "saltSeparator": saltSeparator, + "signerKey": signerKey, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/algo_sha.dart b/lib/src/models/algo_sha.dart index 47068be0..23a9400d 100644 --- a/lib/src/models/algo_sha.dart +++ b/lib/src/models/algo_sha.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// AlgoSHA class AlgoSha implements Model { - /// Algo type. - final String type; + /// Algo type. + final String type; - AlgoSha({ - required this.type, - }); + AlgoSha({ + required this.type, + }); - factory AlgoSha.fromMap(Map<String, dynamic> map) { - return AlgoSha( - type: map['type'].toString(), - ); - } + factory AlgoSha.fromMap(Map<String, dynamic> map) { + return AlgoSha( + type: map['type'].toString(), + ); + } - Map<String, dynamic> toMap() { - return { - "type": type, - }; - } -} + Map<String, dynamic> toMap() { + return { + "type": type, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/attribute_boolean.dart b/lib/src/models/attribute_boolean.dart index 0ca54691..3ed9e9f1 100644 --- a/lib/src/models/attribute_boolean.dart +++ b/lib/src/models/attribute_boolean.dart @@ -2,70 +2,62 @@ part of '../../models.dart'; /// AttributeBoolean class AttributeBoolean implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final bool? xdefault; - - AttributeBoolean({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - this.xdefault, - }); - - factory AttributeBoolean.fromMap(Map<String, dynamic> map) { - return AttributeBoolean( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - xdefault: map['default'], - ); - } - - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "default": xdefault, - }; - } -} + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final bool? xdefault; + + AttributeBoolean({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + this.xdefault, + }); + + factory AttributeBoolean.fromMap(Map<String, dynamic> map) { + return AttributeBoolean( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + xdefault: map['default'], + ); + } + + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "default": xdefault, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/attribute_datetime.dart b/lib/src/models/attribute_datetime.dart index 1df01f19..164fcea6 100644 --- a/lib/src/models/attribute_datetime.dart +++ b/lib/src/models/attribute_datetime.dart @@ -2,76 +2,67 @@ part of '../../models.dart'; /// AttributeDatetime class AttributeDatetime implements Model { - /// Attribute Key. - final String key; + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + /// ISO 8601 format. + final String format; + /// Default value for attribute when not provided. Only null is optional + final String? xdefault; - /// Attribute type. - final String type; + AttributeDatetime({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + required this.format, + this.xdefault, + }); - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; + factory AttributeDatetime.fromMap(Map<String, dynamic> map) { + return AttributeDatetime( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - - /// ISO 8601 format. - final String format; - - /// Default value for attribute when not provided. Only null is optional - final String? xdefault; - - AttributeDatetime({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - required this.format, - this.xdefault, - }); - - factory AttributeDatetime.fromMap(Map<String, dynamic> map) { - return AttributeDatetime( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "format": format, - "default": xdefault, - }; - } -} + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "format": format, + "default": xdefault, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/attribute_email.dart b/lib/src/models/attribute_email.dart index 21f8e9a3..5814ac74 100644 --- a/lib/src/models/attribute_email.dart +++ b/lib/src/models/attribute_email.dart @@ -2,76 +2,67 @@ part of '../../models.dart'; /// AttributeEmail class AttributeEmail implements Model { - /// Attribute Key. - final String key; + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + /// String format. + final String format; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; - /// Attribute type. - final String type; + AttributeEmail({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + required this.format, + this.xdefault, + }); - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; + factory AttributeEmail.fromMap(Map<String, dynamic> map) { + return AttributeEmail( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - - /// String format. - final String format; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeEmail({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - required this.format, - this.xdefault, - }); - - factory AttributeEmail.fromMap(Map<String, dynamic> map) { - return AttributeEmail( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "format": format, - "default": xdefault, - }; - } -} + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "format": format, + "default": xdefault, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/attribute_enum.dart b/lib/src/models/attribute_enum.dart index 746f9864..0157cabb 100644 --- a/lib/src/models/attribute_enum.dart +++ b/lib/src/models/attribute_enum.dart @@ -2,82 +2,72 @@ part of '../../models.dart'; /// AttributeEnum class AttributeEnum implements Model { - /// Attribute Key. - final String key; + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + /// Array of elements in enumerated type. + final List<String> elements; + /// String format. + final String format; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; - /// Attribute type. - final String type; + AttributeEnum({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + required this.elements, + required this.format, + this.xdefault, + }); - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; + factory AttributeEnum.fromMap(Map<String, dynamic> map) { + return AttributeEnum( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + elements: List<String>.from(map['elements']?.map((x) => x.toString()) ?? []), + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - - /// Array of elements in enumerated type. - final List<String> elements; - - /// String format. - final String format; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeEnum({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - required this.elements, - required this.format, - this.xdefault, - }); - - factory AttributeEnum.fromMap(Map<String, dynamic> map) { - return AttributeEnum( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - elements: map['elements'] ?? [], - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "elements": elements, - "format": format, - "default": xdefault, - }; - } -} + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "elements": elements, + "format": format, + "default": xdefault, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/attribute_float.dart b/lib/src/models/attribute_float.dart index c6eecadd..22b6c9f6 100644 --- a/lib/src/models/attribute_float.dart +++ b/lib/src/models/attribute_float.dart @@ -2,82 +2,72 @@ part of '../../models.dart'; /// AttributeFloat class AttributeFloat implements Model { - /// Attribute Key. - final String key; + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + /// Minimum value to enforce for new documents. + final double? min; + /// Maximum value to enforce for new documents. + final double? max; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final double? xdefault; - /// Attribute type. - final String type; + AttributeFloat({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + this.min, + this.max, + this.xdefault, + }); - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; + factory AttributeFloat.fromMap(Map<String, dynamic> map) { + return AttributeFloat( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + min: map['min']?.toDouble(), + max: map['max']?.toDouble(), + xdefault: map['default']?.toDouble(), + ); + } - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - - /// Minimum value to enforce for new documents. - final double? min; - - /// Maximum value to enforce for new documents. - final double? max; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final double? xdefault; - - AttributeFloat({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - this.min, - this.max, - this.xdefault, - }); - - factory AttributeFloat.fromMap(Map<String, dynamic> map) { - return AttributeFloat( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - min: map['min']?.toDouble(), - max: map['max']?.toDouble(), - xdefault: map['default']?.toDouble(), - ); - } - - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "min": min, - "max": max, - "default": xdefault, - }; - } -} + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "min": min, + "max": max, + "default": xdefault, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/attribute_integer.dart b/lib/src/models/attribute_integer.dart index 1ef48332..6c2ef153 100644 --- a/lib/src/models/attribute_integer.dart +++ b/lib/src/models/attribute_integer.dart @@ -2,82 +2,72 @@ part of '../../models.dart'; /// AttributeInteger class AttributeInteger implements Model { - /// Attribute Key. - final String key; + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + /// Minimum value to enforce for new documents. + final int? min; + /// Maximum value to enforce for new documents. + final int? max; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final int? xdefault; - /// Attribute type. - final String type; + AttributeInteger({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + this.min, + this.max, + this.xdefault, + }); - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; + factory AttributeInteger.fromMap(Map<String, dynamic> map) { + return AttributeInteger( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + min: map['min'], + max: map['max'], + xdefault: map['default'], + ); + } - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - - /// Minimum value to enforce for new documents. - final int? min; - - /// Maximum value to enforce for new documents. - final int? max; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final int? xdefault; - - AttributeInteger({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - this.min, - this.max, - this.xdefault, - }); - - factory AttributeInteger.fromMap(Map<String, dynamic> map) { - return AttributeInteger( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - min: map['min'], - max: map['max'], - xdefault: map['default'], - ); - } - - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "min": min, - "max": max, - "default": xdefault, - }; - } -} + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "min": min, + "max": max, + "default": xdefault, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/attribute_ip.dart b/lib/src/models/attribute_ip.dart index 8c8fcb73..2c77e1e1 100644 --- a/lib/src/models/attribute_ip.dart +++ b/lib/src/models/attribute_ip.dart @@ -2,76 +2,67 @@ part of '../../models.dart'; /// AttributeIP class AttributeIp implements Model { - /// Attribute Key. - final String key; + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + /// String format. + final String format; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; - /// Attribute type. - final String type; + AttributeIp({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + required this.format, + this.xdefault, + }); - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; + factory AttributeIp.fromMap(Map<String, dynamic> map) { + return AttributeIp( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - - /// String format. - final String format; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeIp({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - required this.format, - this.xdefault, - }); - - factory AttributeIp.fromMap(Map<String, dynamic> map) { - return AttributeIp( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "format": format, - "default": xdefault, - }; - } -} + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "format": format, + "default": xdefault, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/attribute_list.dart b/lib/src/models/attribute_list.dart index 4d9846c1..6f782027 100644 --- a/lib/src/models/attribute_list.dart +++ b/lib/src/models/attribute_list.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Attributes List class AttributeList implements Model { - /// Total number of attributes in the given collection. - final int total; + /// Total number of attributes in the given collection. + final int total; + /// List of attributes. + final List attributes; - /// List of attributes. - final List attributes; + AttributeList({ + required this.total, + required this.attributes, + }); - AttributeList({ - required this.total, - required this.attributes, - }); + factory AttributeList.fromMap(Map<String, dynamic> map) { + return AttributeList( + total: map['total'], + attributes: List<>.from(map['attributes']?.map((x) => x) ?? []), + ); + } - factory AttributeList.fromMap(Map<String, dynamic> map) { - return AttributeList( - total: map['total'], - attributes: map['attributes'] ?? [], - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "attributes": attributes, - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "attributes": attributes, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/attribute_relationship.dart b/lib/src/models/attribute_relationship.dart index 903c6290..c47ba22c 100644 --- a/lib/src/models/attribute_relationship.dart +++ b/lib/src/models/attribute_relationship.dart @@ -2,100 +2,87 @@ part of '../../models.dart'; /// AttributeRelationship class AttributeRelationship implements Model { - /// Attribute Key. - final String key; - - /// Attribute type. - final String type; - - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - - /// The ID of the related collection. - final String relatedCollection; - - /// The type of the relationship. - final String relationType; - - /// Is the relationship two-way? - final bool twoWay; - - /// The key of the two-way relationship. - final String twoWayKey; - - /// How deleting the parent document will propagate to child documents. - final String onDelete; - - /// Whether this is the parent or child side of the relationship - final String side; - - AttributeRelationship({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - required this.relatedCollection, - required this.relationType, - required this.twoWay, - required this.twoWayKey, - required this.onDelete, - required this.side, - }); - - factory AttributeRelationship.fromMap(Map<String, dynamic> map) { - return AttributeRelationship( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - relatedCollection: map['relatedCollection'].toString(), - relationType: map['relationType'].toString(), - twoWay: map['twoWay'], - twoWayKey: map['twoWayKey'].toString(), - onDelete: map['onDelete'].toString(), - side: map['side'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "relatedCollection": relatedCollection, - "relationType": relationType, - "twoWay": twoWay, - "twoWayKey": twoWayKey, - "onDelete": onDelete, - "side": side, - }; - } -} + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + /// The ID of the related collection. + final String relatedCollection; + /// The type of the relationship. + final String relationType; + /// Is the relationship two-way? + final bool twoWay; + /// The key of the two-way relationship. + final String twoWayKey; + /// How deleting the parent document will propagate to child documents. + final String onDelete; + /// Whether this is the parent or child side of the relationship + final String side; + + AttributeRelationship({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + required this.relatedCollection, + required this.relationType, + required this.twoWay, + required this.twoWayKey, + required this.onDelete, + required this.side, + }); + + factory AttributeRelationship.fromMap(Map<String, dynamic> map) { + return AttributeRelationship( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + relatedCollection: map['relatedCollection'].toString(), + relationType: map['relationType'].toString(), + twoWay: map['twoWay'], + twoWayKey: map['twoWayKey'].toString(), + onDelete: map['onDelete'].toString(), + side: map['side'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "relatedCollection": relatedCollection, + "relationType": relationType, + "twoWay": twoWay, + "twoWayKey": twoWayKey, + "onDelete": onDelete, + "side": side, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/attribute_string.dart b/lib/src/models/attribute_string.dart index d32b6829..de6cf311 100644 --- a/lib/src/models/attribute_string.dart +++ b/lib/src/models/attribute_string.dart @@ -2,76 +2,67 @@ part of '../../models.dart'; /// AttributeString class AttributeString implements Model { - /// Attribute Key. - final String key; + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + /// Attribute size. + final int size; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; - /// Attribute type. - final String type; + AttributeString({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + required this.size, + this.xdefault, + }); - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; + factory AttributeString.fromMap(Map<String, dynamic> map) { + return AttributeString( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + size: map['size'], + xdefault: map['default']?.toString(), + ); + } - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - - /// Attribute size. - final int size; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeString({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - required this.size, - this.xdefault, - }); - - factory AttributeString.fromMap(Map<String, dynamic> map) { - return AttributeString( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - size: map['size'], - xdefault: map['default']?.toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "size": size, - "default": xdefault, - }; - } -} + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "size": size, + "default": xdefault, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/attribute_url.dart b/lib/src/models/attribute_url.dart index f0bc295e..b2e3ee44 100644 --- a/lib/src/models/attribute_url.dart +++ b/lib/src/models/attribute_url.dart @@ -2,76 +2,67 @@ part of '../../models.dart'; /// AttributeURL class AttributeUrl implements Model { - /// Attribute Key. - final String key; + /// Attribute Key. + final String key; + /// Attribute type. + final String type; + /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an attribute. + final String error; + /// Is attribute required? + final bool xrequired; + /// Is attribute an array? + final bool? array; + /// Attribute creation date in ISO 8601 format. + final String $createdAt; + /// Attribute update date in ISO 8601 format. + final String $updatedAt; + /// String format. + final String format; + /// Default value for attribute when not provided. Cannot be set when attribute is required. + final String? xdefault; - /// Attribute type. - final String type; + AttributeUrl({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.xrequired, + this.array, + required this.$createdAt, + required this.$updatedAt, + required this.format, + this.xdefault, + }); - /// Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; + factory AttributeUrl.fromMap(Map<String, dynamic> map) { + return AttributeUrl( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + xrequired: map['required'], + array: map['array'], + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + format: map['format'].toString(), + xdefault: map['default']?.toString(), + ); + } - /// Error message. Displays error generated on failure of creating or deleting an attribute. - final String error; - - /// Is attribute required? - final bool xrequired; - - /// Is attribute an array? - final bool? array; - - /// Attribute creation date in ISO 8601 format. - final String $createdAt; - - /// Attribute update date in ISO 8601 format. - final String $updatedAt; - - /// String format. - final String format; - - /// Default value for attribute when not provided. Cannot be set when attribute is required. - final String? xdefault; - - AttributeUrl({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.xrequired, - this.array, - required this.$createdAt, - required this.$updatedAt, - required this.format, - this.xdefault, - }); - - factory AttributeUrl.fromMap(Map<String, dynamic> map) { - return AttributeUrl( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - xrequired: map['required'], - array: map['array'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - format: map['format'].toString(), - xdefault: map['default']?.toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "required": xrequired, - "array": array, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "format": format, - "default": xdefault, - }; - } -} + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "required": xrequired, + "array": array, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "format": format, + "default": xdefault, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/bucket.dart b/lib/src/models/bucket.dart index e2aa51fe..5cecefd2 100644 --- a/lib/src/models/bucket.dart +++ b/lib/src/models/bucket.dart @@ -2,88 +2,77 @@ part of '../../models.dart'; /// Bucket class Bucket implements Model { - /// Bucket ID. - final String $id; + /// Bucket ID. + final String $id; + /// Bucket creation time in ISO 8601 format. + final String $createdAt; + /// Bucket update date in ISO 8601 format. + final String $updatedAt; + /// Bucket permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List<String> $permissions; + /// Whether file-level security is enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). + final bool fileSecurity; + /// Bucket name. + final String name; + /// Bucket enabled. + final bool enabled; + /// Maximum file size supported. + final int maximumFileSize; + /// Allowed file extensions. + final List<String> allowedFileExtensions; + /// Compression algorithm choosen for compression. Will be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd). + final String compression; + /// Bucket is encrypted. + final bool encryption; + /// Virus scanning is enabled. + final bool antivirus; - /// Bucket creation time in ISO 8601 format. - final String $createdAt; + Bucket({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.fileSecurity, + required this.name, + required this.enabled, + required this.maximumFileSize, + required this.allowedFileExtensions, + required this.compression, + required this.encryption, + required this.antivirus, + }); - /// Bucket update date in ISO 8601 format. - final String $updatedAt; + factory Bucket.fromMap(Map<String, dynamic> map) { + return Bucket( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: List<String>.from(map['\$permissions']?.map((x) => x.toString()) ?? []), + fileSecurity: map['fileSecurity'], + name: map['name'].toString(), + enabled: map['enabled'], + maximumFileSize: map['maximumFileSize'], + allowedFileExtensions: List<String>.from(map['allowedFileExtensions']?.map((x) => x.toString()) ?? []), + compression: map['compression'].toString(), + encryption: map['encryption'], + antivirus: map['antivirus'], + ); + } - /// Bucket permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List<String> $permissions; - - /// Whether file-level security is enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). - final bool fileSecurity; - - /// Bucket name. - final String name; - - /// Bucket enabled. - final bool enabled; - - /// Maximum file size supported. - final int maximumFileSize; - - /// Allowed file extensions. - final List<String> allowedFileExtensions; - - /// Compression algorithm choosen for compression. Will be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd). - final String compression; - - /// Bucket is encrypted. - final bool encryption; - - /// Virus scanning is enabled. - final bool antivirus; - - Bucket({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.fileSecurity, - required this.name, - required this.enabled, - required this.maximumFileSize, - required this.allowedFileExtensions, - required this.compression, - required this.encryption, - required this.antivirus, - }); - - factory Bucket.fromMap(Map<String, dynamic> map) { - return Bucket( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - fileSecurity: map['fileSecurity'], - name: map['name'].toString(), - enabled: map['enabled'], - maximumFileSize: map['maximumFileSize'], - allowedFileExtensions: map['allowedFileExtensions'] ?? [], - compression: map['compression'].toString(), - encryption: map['encryption'], - antivirus: map['antivirus'], - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "fileSecurity": fileSecurity, - "name": name, - "enabled": enabled, - "maximumFileSize": maximumFileSize, - "allowedFileExtensions": allowedFileExtensions, - "compression": compression, - "encryption": encryption, - "antivirus": antivirus, - }; - } -} + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "fileSecurity": fileSecurity, + "name": name, + "enabled": enabled, + "maximumFileSize": maximumFileSize, + "allowedFileExtensions": allowedFileExtensions, + "compression": compression, + "encryption": encryption, + "antivirus": antivirus, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/bucket_list.dart b/lib/src/models/bucket_list.dart index 849aea4a..5d7574fd 100644 --- a/lib/src/models/bucket_list.dart +++ b/lib/src/models/bucket_list.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Buckets List class BucketList implements Model { - /// Total number of buckets documents that matched your query. - final int total; + /// Total number of buckets documents that matched your query. + final int total; + /// List of buckets. + final List<Bucket> buckets; - /// List of buckets. - final List<Bucket> buckets; + BucketList({ + required this.total, + required this.buckets, + }); - BucketList({ - required this.total, - required this.buckets, - }); + factory BucketList.fromMap(Map<String, dynamic> map) { + return BucketList( + total: map['total'], + buckets: List<Bucket>.from(map['buckets'].map((p) => Bucket.fromMap(p))), + ); + } - factory BucketList.fromMap(Map<String, dynamic> map) { - return BucketList( - total: map['total'], - buckets: List<Bucket>.from(map['buckets'].map((p) => Bucket.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "buckets": buckets.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "buckets": buckets.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/build.dart b/lib/src/models/build.dart index ea4a3137..b4bc9340 100644 --- a/lib/src/models/build.dart +++ b/lib/src/models/build.dart @@ -2,70 +2,62 @@ part of '../../models.dart'; /// Build class Build implements Model { - /// Build ID. - final String $id; - - /// The deployment that created this build. - final String deploymentId; - - /// The build status. There are a few different types and each one means something different. \nFailed - The deployment build has failed. More details can usually be found in buildStderr\nReady - The deployment build was successful and the deployment is ready to be deployed\nProcessing - The deployment is currently waiting to have a build triggered\nBuilding - The deployment is currently being built - final String status; - - /// The stdout of the build. - final String stdout; - - /// The stderr of the build. - final String stderr; - - /// The deployment creation date in ISO 8601 format. - final String startTime; - - /// The time the build was finished in ISO 8601 format. - final String endTime; - - /// The build duration in seconds. - final int duration; - - /// The code size in bytes. - final int size; - - Build({ - required this.$id, - required this.deploymentId, - required this.status, - required this.stdout, - required this.stderr, - required this.startTime, - required this.endTime, - required this.duration, - required this.size, - }); - - factory Build.fromMap(Map<String, dynamic> map) { - return Build( - $id: map['\$id'].toString(), - deploymentId: map['deploymentId'].toString(), - status: map['status'].toString(), - stdout: map['stdout'].toString(), - stderr: map['stderr'].toString(), - startTime: map['startTime'].toString(), - endTime: map['endTime'].toString(), - duration: map['duration'], - size: map['size'], - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "deploymentId": deploymentId, - "status": status, - "stdout": stdout, - "stderr": stderr, - "startTime": startTime, - "endTime": endTime, - "duration": duration, - "size": size, - }; - } -} + /// Build ID. + final String $id; + /// The deployment that created this build. + final String deploymentId; + /// The build status. There are a few different types and each one means something different. \nFailed - The deployment build has failed. More details can usually be found in buildStderr\nReady - The deployment build was successful and the deployment is ready to be deployed\nProcessing - The deployment is currently waiting to have a build triggered\nBuilding - The deployment is currently being built + final String status; + /// The stdout of the build. + final String stdout; + /// The stderr of the build. + final String stderr; + /// The deployment creation date in ISO 8601 format. + final String startTime; + /// The time the build was finished in ISO 8601 format. + final String endTime; + /// The build duration in seconds. + final int duration; + /// The code size in bytes. + final int size; + + Build({ + required this.$id, + required this.deploymentId, + required this.status, + required this.stdout, + required this.stderr, + required this.startTime, + required this.endTime, + required this.duration, + required this.size, + }); + + factory Build.fromMap(Map<String, dynamic> map) { + return Build( + $id: map['\$id'].toString(), + deploymentId: map['deploymentId'].toString(), + status: map['status'].toString(), + stdout: map['stdout'].toString(), + stderr: map['stderr'].toString(), + startTime: map['startTime'].toString(), + endTime: map['endTime'].toString(), + duration: map['duration'], + size: map['size'], + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "deploymentId": deploymentId, + "status": status, + "stdout": stdout, + "stderr": stderr, + "startTime": startTime, + "endTime": endTime, + "duration": duration, + "size": size, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/collection.dart b/lib/src/models/collection.dart index ef572743..785889af 100644 --- a/lib/src/models/collection.dart +++ b/lib/src/models/collection.dart @@ -2,76 +2,67 @@ part of '../../models.dart'; /// Collection class Collection implements Model { - /// Collection ID. - final String $id; + /// Collection ID. + final String $id; + /// Collection creation date in ISO 8601 format. + final String $createdAt; + /// Collection update date in ISO 8601 format. + final String $updatedAt; + /// Collection permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List<String> $permissions; + /// Database ID. + final String databaseId; + /// Collection name. + final String name; + /// Collection enabled. Can be 'enabled' or 'disabled'. When disabled, the collection is inaccessible to users, but remains accessible to Server SDKs using API keys. + final bool enabled; + /// Whether document-level permissions are enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). + final bool documentSecurity; + /// Collection attributes. + final List attributes; + /// Collection indexes. + final List<Index> indexes; - /// Collection creation date in ISO 8601 format. - final String $createdAt; + Collection({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.databaseId, + required this.name, + required this.enabled, + required this.documentSecurity, + required this.attributes, + required this.indexes, + }); - /// Collection update date in ISO 8601 format. - final String $updatedAt; + factory Collection.fromMap(Map<String, dynamic> map) { + return Collection( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: List<String>.from(map['\$permissions']?.map((x) => x.toString()) ?? []), + databaseId: map['databaseId'].toString(), + name: map['name'].toString(), + enabled: map['enabled'], + documentSecurity: map['documentSecurity'], + attributes: List<>.from(map['attributes']?.map((x) => x) ?? []), + indexes: List<Index>.from(map['indexes'].map((p) => Index.fromMap(p))), + ); + } - /// Collection permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List<String> $permissions; - - /// Database ID. - final String databaseId; - - /// Collection name. - final String name; - - /// Collection enabled. Can be 'enabled' or 'disabled'. When disabled, the collection is inaccessible to users, but remains accessible to Server SDKs using API keys. - final bool enabled; - - /// Whether document-level permissions are enabled. [Learn more about permissions](https://appwrite.io/docs/permissions). - final bool documentSecurity; - - /// Collection attributes. - final List attributes; - - /// Collection indexes. - final List<Index> indexes; - - Collection({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.databaseId, - required this.name, - required this.enabled, - required this.documentSecurity, - required this.attributes, - required this.indexes, - }); - - factory Collection.fromMap(Map<String, dynamic> map) { - return Collection( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - databaseId: map['databaseId'].toString(), - name: map['name'].toString(), - enabled: map['enabled'], - documentSecurity: map['documentSecurity'], - attributes: map['attributes'] ?? [], - indexes: List<Index>.from(map['indexes'].map((p) => Index.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "databaseId": databaseId, - "name": name, - "enabled": enabled, - "documentSecurity": documentSecurity, - "attributes": attributes, - "indexes": indexes.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "databaseId": databaseId, + "name": name, + "enabled": enabled, + "documentSecurity": documentSecurity, + "attributes": attributes, + "indexes": indexes.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/collection_list.dart b/lib/src/models/collection_list.dart index 3f50e4b6..3a0396c6 100644 --- a/lib/src/models/collection_list.dart +++ b/lib/src/models/collection_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Collections List class CollectionList implements Model { - /// Total number of collections documents that matched your query. - final int total; + /// Total number of collections documents that matched your query. + final int total; + /// List of collections. + final List<Collection> collections; - /// List of collections. - final List<Collection> collections; + CollectionList({ + required this.total, + required this.collections, + }); - CollectionList({ - required this.total, - required this.collections, - }); + factory CollectionList.fromMap(Map<String, dynamic> map) { + return CollectionList( + total: map['total'], + collections: List<Collection>.from(map['collections'].map((p) => Collection.fromMap(p))), + ); + } - factory CollectionList.fromMap(Map<String, dynamic> map) { - return CollectionList( - total: map['total'], - collections: List<Collection>.from( - map['collections'].map((p) => Collection.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "collections": collections.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "collections": collections.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/continent.dart b/lib/src/models/continent.dart index 990b1064..7b0d774c 100644 --- a/lib/src/models/continent.dart +++ b/lib/src/models/continent.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Continent class Continent implements Model { - /// Continent name. - final String name; + /// Continent name. + final String name; + /// Continent two letter code. + final String code; - /// Continent two letter code. - final String code; + Continent({ + required this.name, + required this.code, + }); - Continent({ - required this.name, - required this.code, - }); + factory Continent.fromMap(Map<String, dynamic> map) { + return Continent( + name: map['name'].toString(), + code: map['code'].toString(), + ); + } - factory Continent.fromMap(Map<String, dynamic> map) { - return Continent( - name: map['name'].toString(), - code: map['code'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "name": name, - "code": code, - }; - } -} + Map<String, dynamic> toMap() { + return { + "name": name, + "code": code, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/continent_list.dart b/lib/src/models/continent_list.dart index fb4ee6f6..649f4786 100644 --- a/lib/src/models/continent_list.dart +++ b/lib/src/models/continent_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Continents List class ContinentList implements Model { - /// Total number of continents documents that matched your query. - final int total; + /// Total number of continents documents that matched your query. + final int total; + /// List of continents. + final List<Continent> continents; - /// List of continents. - final List<Continent> continents; + ContinentList({ + required this.total, + required this.continents, + }); - ContinentList({ - required this.total, - required this.continents, - }); + factory ContinentList.fromMap(Map<String, dynamic> map) { + return ContinentList( + total: map['total'], + continents: List<Continent>.from(map['continents'].map((p) => Continent.fromMap(p))), + ); + } - factory ContinentList.fromMap(Map<String, dynamic> map) { - return ContinentList( - total: map['total'], - continents: List<Continent>.from( - map['continents'].map((p) => Continent.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "continents": continents.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "continents": continents.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/country.dart b/lib/src/models/country.dart index d11c55db..4ea150e1 100644 --- a/lib/src/models/country.dart +++ b/lib/src/models/country.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Country class Country implements Model { - /// Country name. - final String name; + /// Country name. + final String name; + /// Country two-character ISO 3166-1 alpha code. + final String code; - /// Country two-character ISO 3166-1 alpha code. - final String code; + Country({ + required this.name, + required this.code, + }); - Country({ - required this.name, - required this.code, - }); + factory Country.fromMap(Map<String, dynamic> map) { + return Country( + name: map['name'].toString(), + code: map['code'].toString(), + ); + } - factory Country.fromMap(Map<String, dynamic> map) { - return Country( - name: map['name'].toString(), - code: map['code'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "name": name, - "code": code, - }; - } -} + Map<String, dynamic> toMap() { + return { + "name": name, + "code": code, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/country_list.dart b/lib/src/models/country_list.dart index a62f926d..fc7f22a4 100644 --- a/lib/src/models/country_list.dart +++ b/lib/src/models/country_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Countries List class CountryList implements Model { - /// Total number of countries documents that matched your query. - final int total; + /// Total number of countries documents that matched your query. + final int total; + /// List of countries. + final List<Country> countries; - /// List of countries. - final List<Country> countries; + CountryList({ + required this.total, + required this.countries, + }); - CountryList({ - required this.total, - required this.countries, - }); + factory CountryList.fromMap(Map<String, dynamic> map) { + return CountryList( + total: map['total'], + countries: List<Country>.from(map['countries'].map((p) => Country.fromMap(p))), + ); + } - factory CountryList.fromMap(Map<String, dynamic> map) { - return CountryList( - total: map['total'], - countries: - List<Country>.from(map['countries'].map((p) => Country.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "countries": countries.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "countries": countries.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/currency.dart b/lib/src/models/currency.dart index 27eef0c1..4569b655 100644 --- a/lib/src/models/currency.dart +++ b/lib/src/models/currency.dart @@ -2,58 +2,52 @@ part of '../../models.dart'; /// Currency class Currency implements Model { - /// Currency symbol. - final String symbol; - - /// Currency name. - final String name; - - /// Currency native symbol. - final String symbolNative; - - /// Number of decimal digits. - final int decimalDigits; - - /// Currency digit rounding. - final double rounding; - - /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format. - final String code; - - /// Currency plural name - final String namePlural; - - Currency({ - required this.symbol, - required this.name, - required this.symbolNative, - required this.decimalDigits, - required this.rounding, - required this.code, - required this.namePlural, - }); - - factory Currency.fromMap(Map<String, dynamic> map) { - return Currency( - symbol: map['symbol'].toString(), - name: map['name'].toString(), - symbolNative: map['symbolNative'].toString(), - decimalDigits: map['decimalDigits'], - rounding: map['rounding'].toDouble(), - code: map['code'].toString(), - namePlural: map['namePlural'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "symbol": symbol, - "name": name, - "symbolNative": symbolNative, - "decimalDigits": decimalDigits, - "rounding": rounding, - "code": code, - "namePlural": namePlural, - }; - } -} + /// Currency symbol. + final String symbol; + /// Currency name. + final String name; + /// Currency native symbol. + final String symbolNative; + /// Number of decimal digits. + final int decimalDigits; + /// Currency digit rounding. + final double rounding; + /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format. + final String code; + /// Currency plural name + final String namePlural; + + Currency({ + required this.symbol, + required this.name, + required this.symbolNative, + required this.decimalDigits, + required this.rounding, + required this.code, + required this.namePlural, + }); + + factory Currency.fromMap(Map<String, dynamic> map) { + return Currency( + symbol: map['symbol'].toString(), + name: map['name'].toString(), + symbolNative: map['symbolNative'].toString(), + decimalDigits: map['decimalDigits'], + rounding: map['rounding'].toDouble(), + code: map['code'].toString(), + namePlural: map['namePlural'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "symbol": symbol, + "name": name, + "symbolNative": symbolNative, + "decimalDigits": decimalDigits, + "rounding": rounding, + "code": code, + "namePlural": namePlural, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/currency_list.dart b/lib/src/models/currency_list.dart index e912ca0a..4fcfc931 100644 --- a/lib/src/models/currency_list.dart +++ b/lib/src/models/currency_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Currencies List class CurrencyList implements Model { - /// Total number of currencies documents that matched your query. - final int total; + /// Total number of currencies documents that matched your query. + final int total; + /// List of currencies. + final List<Currency> currencies; - /// List of currencies. - final List<Currency> currencies; + CurrencyList({ + required this.total, + required this.currencies, + }); - CurrencyList({ - required this.total, - required this.currencies, - }); + factory CurrencyList.fromMap(Map<String, dynamic> map) { + return CurrencyList( + total: map['total'], + currencies: List<Currency>.from(map['currencies'].map((p) => Currency.fromMap(p))), + ); + } - factory CurrencyList.fromMap(Map<String, dynamic> map) { - return CurrencyList( - total: map['total'], - currencies: List<Currency>.from( - map['currencies'].map((p) => Currency.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "currencies": currencies.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "currencies": currencies.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/database.dart b/lib/src/models/database.dart index 298a46a3..c107b422 100644 --- a/lib/src/models/database.dart +++ b/lib/src/models/database.dart @@ -2,46 +2,42 @@ part of '../../models.dart'; /// Database class Database implements Model { - /// Database ID. - final String $id; - - /// Database name. - final String name; - - /// Database creation date in ISO 8601 format. - final String $createdAt; - - /// Database update date in ISO 8601 format. - final String $updatedAt; - - /// If database is enabled. Can be 'enabled' or 'disabled'. When disabled, the database is inaccessible to users, but remains accessible to Server SDKs using API keys. - final bool enabled; - - Database({ - required this.$id, - required this.name, - required this.$createdAt, - required this.$updatedAt, - required this.enabled, - }); - - factory Database.fromMap(Map<String, dynamic> map) { - return Database( - $id: map['\$id'].toString(), - name: map['name'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - enabled: map['enabled'], - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "name": name, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "enabled": enabled, - }; - } -} + /// Database ID. + final String $id; + /// Database name. + final String name; + /// Database creation date in ISO 8601 format. + final String $createdAt; + /// Database update date in ISO 8601 format. + final String $updatedAt; + /// If database is enabled. Can be 'enabled' or 'disabled'. When disabled, the database is inaccessible to users, but remains accessible to Server SDKs using API keys. + final bool enabled; + + Database({ + required this.$id, + required this.name, + required this.$createdAt, + required this.$updatedAt, + required this.enabled, + }); + + factory Database.fromMap(Map<String, dynamic> map) { + return Database( + $id: map['\$id'].toString(), + name: map['name'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + enabled: map['enabled'], + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "name": name, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "enabled": enabled, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/database_list.dart b/lib/src/models/database_list.dart index 0ac639f0..f2481241 100644 --- a/lib/src/models/database_list.dart +++ b/lib/src/models/database_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Databases List class DatabaseList implements Model { - /// Total number of databases documents that matched your query. - final int total; + /// Total number of databases documents that matched your query. + final int total; + /// List of databases. + final List<Database> databases; - /// List of databases. - final List<Database> databases; + DatabaseList({ + required this.total, + required this.databases, + }); - DatabaseList({ - required this.total, - required this.databases, - }); + factory DatabaseList.fromMap(Map<String, dynamic> map) { + return DatabaseList( + total: map['total'], + databases: List<Database>.from(map['databases'].map((p) => Database.fromMap(p))), + ); + } - factory DatabaseList.fromMap(Map<String, dynamic> map) { - return DatabaseList( - total: map['total'], - databases: - List<Database>.from(map['databases'].map((p) => Database.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "databases": databases.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "databases": databases.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/deployment.dart b/lib/src/models/deployment.dart index f01fb11e..a8b6504d 100644 --- a/lib/src/models/deployment.dart +++ b/lib/src/models/deployment.dart @@ -2,160 +2,137 @@ part of '../../models.dart'; /// Deployment class Deployment implements Model { - /// Deployment ID. - final String $id; - - /// Deployment creation date in ISO 8601 format. - final String $createdAt; - - /// Deployment update date in ISO 8601 format. - final String $updatedAt; - - /// Type of deployment. - final String type; - - /// Resource ID. - final String resourceId; - - /// Resource type. - final String resourceType; - - /// The entrypoint file to use to execute the deployment code. - final String entrypoint; - - /// The code size in bytes. - final int size; - - /// The build output size in bytes. - final int buildSize; - - /// The current build ID. - final String buildId; - - /// Whether the deployment should be automatically activated. - final bool activate; - - /// The deployment status. Possible values are "processing", "building", "waiting", "ready", and "failed". - final String status; - - /// The build logs. - final String buildLogs; - - /// The current build time in seconds. - final int buildTime; - - /// The name of the vcs provider repository - final String providerRepositoryName; - - /// The name of the vcs provider repository owner - final String providerRepositoryOwner; - - /// The url of the vcs provider repository - final String providerRepositoryUrl; - - /// The branch of the vcs repository - final String providerBranch; - - /// The commit hash of the vcs commit - final String providerCommitHash; - - /// The url of vcs commit author - final String providerCommitAuthorUrl; - - /// The name of vcs commit author - final String providerCommitAuthor; - - /// The commit message - final String providerCommitMessage; - - /// The url of the vcs commit - final String providerCommitUrl; - - /// The branch of the vcs repository - final String providerBranchUrl; - - Deployment({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.type, - required this.resourceId, - required this.resourceType, - required this.entrypoint, - required this.size, - required this.buildSize, - required this.buildId, - required this.activate, - required this.status, - required this.buildLogs, - required this.buildTime, - required this.providerRepositoryName, - required this.providerRepositoryOwner, - required this.providerRepositoryUrl, - required this.providerBranch, - required this.providerCommitHash, - required this.providerCommitAuthorUrl, - required this.providerCommitAuthor, - required this.providerCommitMessage, - required this.providerCommitUrl, - required this.providerBranchUrl, - }); - - factory Deployment.fromMap(Map<String, dynamic> map) { - return Deployment( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - type: map['type'].toString(), - resourceId: map['resourceId'].toString(), - resourceType: map['resourceType'].toString(), - entrypoint: map['entrypoint'].toString(), - size: map['size'], - buildSize: map['buildSize'], - buildId: map['buildId'].toString(), - activate: map['activate'], - status: map['status'].toString(), - buildLogs: map['buildLogs'].toString(), - buildTime: map['buildTime'], - providerRepositoryName: map['providerRepositoryName'].toString(), - providerRepositoryOwner: map['providerRepositoryOwner'].toString(), - providerRepositoryUrl: map['providerRepositoryUrl'].toString(), - providerBranch: map['providerBranch'].toString(), - providerCommitHash: map['providerCommitHash'].toString(), - providerCommitAuthorUrl: map['providerCommitAuthorUrl'].toString(), - providerCommitAuthor: map['providerCommitAuthor'].toString(), - providerCommitMessage: map['providerCommitMessage'].toString(), - providerCommitUrl: map['providerCommitUrl'].toString(), - providerBranchUrl: map['providerBranchUrl'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "type": type, - "resourceId": resourceId, - "resourceType": resourceType, - "entrypoint": entrypoint, - "size": size, - "buildSize": buildSize, - "buildId": buildId, - "activate": activate, - "status": status, - "buildLogs": buildLogs, - "buildTime": buildTime, - "providerRepositoryName": providerRepositoryName, - "providerRepositoryOwner": providerRepositoryOwner, - "providerRepositoryUrl": providerRepositoryUrl, - "providerBranch": providerBranch, - "providerCommitHash": providerCommitHash, - "providerCommitAuthorUrl": providerCommitAuthorUrl, - "providerCommitAuthor": providerCommitAuthor, - "providerCommitMessage": providerCommitMessage, - "providerCommitUrl": providerCommitUrl, - "providerBranchUrl": providerBranchUrl, - }; - } -} + /// Deployment ID. + final String $id; + /// Deployment creation date in ISO 8601 format. + final String $createdAt; + /// Deployment update date in ISO 8601 format. + final String $updatedAt; + /// Type of deployment. + final String type; + /// Resource ID. + final String resourceId; + /// Resource type. + final String resourceType; + /// The entrypoint file to use to execute the deployment code. + final String entrypoint; + /// The code size in bytes. + final int size; + /// The build output size in bytes. + final int buildSize; + /// The current build ID. + final String buildId; + /// Whether the deployment should be automatically activated. + final bool activate; + /// The deployment status. Possible values are "processing", "building", "waiting", "ready", and "failed". + final String status; + /// The build logs. + final String buildLogs; + /// The current build time in seconds. + final int buildTime; + /// The name of the vcs provider repository + final String providerRepositoryName; + /// The name of the vcs provider repository owner + final String providerRepositoryOwner; + /// The url of the vcs provider repository + final String providerRepositoryUrl; + /// The branch of the vcs repository + final String providerBranch; + /// The commit hash of the vcs commit + final String providerCommitHash; + /// The url of vcs commit author + final String providerCommitAuthorUrl; + /// The name of vcs commit author + final String providerCommitAuthor; + /// The commit message + final String providerCommitMessage; + /// The url of the vcs commit + final String providerCommitUrl; + /// The branch of the vcs repository + final String providerBranchUrl; + + Deployment({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.type, + required this.resourceId, + required this.resourceType, + required this.entrypoint, + required this.size, + required this.buildSize, + required this.buildId, + required this.activate, + required this.status, + required this.buildLogs, + required this.buildTime, + required this.providerRepositoryName, + required this.providerRepositoryOwner, + required this.providerRepositoryUrl, + required this.providerBranch, + required this.providerCommitHash, + required this.providerCommitAuthorUrl, + required this.providerCommitAuthor, + required this.providerCommitMessage, + required this.providerCommitUrl, + required this.providerBranchUrl, + }); + + factory Deployment.fromMap(Map<String, dynamic> map) { + return Deployment( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + type: map['type'].toString(), + resourceId: map['resourceId'].toString(), + resourceType: map['resourceType'].toString(), + entrypoint: map['entrypoint'].toString(), + size: map['size'], + buildSize: map['buildSize'], + buildId: map['buildId'].toString(), + activate: map['activate'], + status: map['status'].toString(), + buildLogs: map['buildLogs'].toString(), + buildTime: map['buildTime'], + providerRepositoryName: map['providerRepositoryName'].toString(), + providerRepositoryOwner: map['providerRepositoryOwner'].toString(), + providerRepositoryUrl: map['providerRepositoryUrl'].toString(), + providerBranch: map['providerBranch'].toString(), + providerCommitHash: map['providerCommitHash'].toString(), + providerCommitAuthorUrl: map['providerCommitAuthorUrl'].toString(), + providerCommitAuthor: map['providerCommitAuthor'].toString(), + providerCommitMessage: map['providerCommitMessage'].toString(), + providerCommitUrl: map['providerCommitUrl'].toString(), + providerBranchUrl: map['providerBranchUrl'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "type": type, + "resourceId": resourceId, + "resourceType": resourceType, + "entrypoint": entrypoint, + "size": size, + "buildSize": buildSize, + "buildId": buildId, + "activate": activate, + "status": status, + "buildLogs": buildLogs, + "buildTime": buildTime, + "providerRepositoryName": providerRepositoryName, + "providerRepositoryOwner": providerRepositoryOwner, + "providerRepositoryUrl": providerRepositoryUrl, + "providerBranch": providerBranch, + "providerCommitHash": providerCommitHash, + "providerCommitAuthorUrl": providerCommitAuthorUrl, + "providerCommitAuthor": providerCommitAuthor, + "providerCommitMessage": providerCommitMessage, + "providerCommitUrl": providerCommitUrl, + "providerBranchUrl": providerBranchUrl, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/deployment_list.dart b/lib/src/models/deployment_list.dart index 03e03c98..96b9d368 100644 --- a/lib/src/models/deployment_list.dart +++ b/lib/src/models/deployment_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Deployments List class DeploymentList implements Model { - /// Total number of deployments documents that matched your query. - final int total; + /// Total number of deployments documents that matched your query. + final int total; + /// List of deployments. + final List<Deployment> deployments; - /// List of deployments. - final List<Deployment> deployments; + DeploymentList({ + required this.total, + required this.deployments, + }); - DeploymentList({ - required this.total, - required this.deployments, - }); + factory DeploymentList.fromMap(Map<String, dynamic> map) { + return DeploymentList( + total: map['total'], + deployments: List<Deployment>.from(map['deployments'].map((p) => Deployment.fromMap(p))), + ); + } - factory DeploymentList.fromMap(Map<String, dynamic> map) { - return DeploymentList( - total: map['total'], - deployments: List<Deployment>.from( - map['deployments'].map((p) => Deployment.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "deployments": deployments.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "deployments": deployments.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/document.dart b/lib/src/models/document.dart index f8164b61..54827e3f 100644 --- a/lib/src/models/document.dart +++ b/lib/src/models/document.dart @@ -2,58 +2,53 @@ part of '../../models.dart'; /// Document class Document implements Model { - /// Document ID. - final String $id; - - /// Collection ID. - final String $collectionId; - - /// Database ID. - final String $databaseId; - - /// Document creation date in ISO 8601 format. - final String $createdAt; - - /// Document update date in ISO 8601 format. - final String $updatedAt; - - /// Document permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List<String> $permissions; - final Map<String, dynamic> data; - - Document({ - required this.$id, - required this.$collectionId, - required this.$databaseId, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.data, - }); - - factory Document.fromMap(Map<String, dynamic> map) { - return Document( - $id: map['\$id'].toString(), - $collectionId: map['\$collectionId'].toString(), - $databaseId: map['\$databaseId'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - data: map, - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$collectionId": $collectionId, - "\$databaseId": $databaseId, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "data": data, - }; - } - - T convertTo<T>(T Function(Map) fromJson) => fromJson(data); -} + /// Document ID. + final String $id; + /// Collection ID. + final String $collectionId; + /// Database ID. + final String $databaseId; + /// Document creation date in ISO 8601 format. + final String $createdAt; + /// Document update date in ISO 8601 format. + final String $updatedAt; + /// Document permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List<String> $permissions; + final Map<String, dynamic> data; + + Document({ + required this.$id, + required this.$collectionId, + required this.$databaseId, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.data, + }); + + factory Document.fromMap(Map<String, dynamic> map) { + return Document( + $id: map['\$id'].toString(), + $collectionId: map['\$collectionId'].toString(), + $databaseId: map['\$databaseId'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: List<String>.from(map['\$permissions']?.map((x) => x.toString()) ?? []), + data: map, + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$collectionId": $collectionId, + "\$databaseId": $databaseId, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "data": data, + }; + } + + T convertTo<T>(T Function(Map) fromJson) => fromJson(data); +} \ No newline at end of file diff --git a/lib/src/models/document_list.dart b/lib/src/models/document_list.dart index b4fd20eb..bc464c92 100644 --- a/lib/src/models/document_list.dart +++ b/lib/src/models/document_list.dart @@ -2,32 +2,30 @@ part of '../../models.dart'; /// Documents List class DocumentList implements Model { - /// Total number of documents documents that matched your query. - final int total; + /// Total number of documents documents that matched your query. + final int total; + /// List of documents. + final List<Document> documents; - /// List of documents. - final List<Document> documents; + DocumentList({ + required this.total, + required this.documents, + }); - DocumentList({ - required this.total, - required this.documents, - }); + factory DocumentList.fromMap(Map<String, dynamic> map) { + return DocumentList( + total: map['total'], + documents: List<Document>.from(map['documents'].map((p) => Document.fromMap(p))), + ); + } - factory DocumentList.fromMap(Map<String, dynamic> map) { - return DocumentList( - total: map['total'], - documents: - List<Document>.from(map['documents'].map((p) => Document.fromMap(p))), - ); - } + Map<String, dynamic> toMap() { + return { + "total": total, + "documents": documents.map((p) => p.toMap()).toList(), + }; + } - Map<String, dynamic> toMap() { - return { - "total": total, - "documents": documents.map((p) => p.toMap()).toList(), - }; - } - - List<T> convertTo<T>(T Function(Map) fromJson) => - documents.map((d) => d.convertTo<T>(fromJson)).toList(); -} + List<T> convertTo<T>(T Function(Map) fromJson) => + documents.map((d) => d.convertTo<T>(fromJson)).toList(); +} \ No newline at end of file diff --git a/lib/src/models/execution.dart b/lib/src/models/execution.dart index 9f9b8917..92c56b96 100644 --- a/lib/src/models/execution.dart +++ b/lib/src/models/execution.dart @@ -2,120 +2,102 @@ part of '../../models.dart'; /// Execution class Execution implements Model { - /// Execution ID. - final String $id; - - /// Execution creation date in ISO 8601 format. - final String $createdAt; - - /// Execution upate date in ISO 8601 format. - final String $updatedAt; - - /// Execution roles. - final List<String> $permissions; - - /// Function ID. - final String functionId; - - /// The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`. - final String trigger; - - /// The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`. - final String status; - - /// HTTP request method type. - final String requestMethod; - - /// HTTP request path and query. - final String requestPath; - - /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. - final List<Headers> requestHeaders; - - /// HTTP response status code. - final int responseStatusCode; - - /// HTTP response body. This will return empty unless execution is created as synchronous. - final String responseBody; - - /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. - final List<Headers> responseHeaders; - - /// Function logs. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. - final String logs; - - /// Function errors. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. - final String errors; - - /// Function execution duration in seconds. - final double duration; - - /// The scheduled time for execution. If left empty, execution will be queued immediately. - final String? scheduledAt; - - Execution({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.functionId, - required this.trigger, - required this.status, - required this.requestMethod, - required this.requestPath, - required this.requestHeaders, - required this.responseStatusCode, - required this.responseBody, - required this.responseHeaders, - required this.logs, - required this.errors, - required this.duration, - this.scheduledAt, - }); - - factory Execution.fromMap(Map<String, dynamic> map) { - return Execution( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - functionId: map['functionId'].toString(), - trigger: map['trigger'].toString(), - status: map['status'].toString(), - requestMethod: map['requestMethod'].toString(), - requestPath: map['requestPath'].toString(), - requestHeaders: List<Headers>.from( - map['requestHeaders'].map((p) => Headers.fromMap(p))), - responseStatusCode: map['responseStatusCode'], - responseBody: map['responseBody'].toString(), - responseHeaders: List<Headers>.from( - map['responseHeaders'].map((p) => Headers.fromMap(p))), - logs: map['logs'].toString(), - errors: map['errors'].toString(), - duration: map['duration'].toDouble(), - scheduledAt: map['scheduledAt']?.toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "functionId": functionId, - "trigger": trigger, - "status": status, - "requestMethod": requestMethod, - "requestPath": requestPath, - "requestHeaders": requestHeaders.map((p) => p.toMap()).toList(), - "responseStatusCode": responseStatusCode, - "responseBody": responseBody, - "responseHeaders": responseHeaders.map((p) => p.toMap()).toList(), - "logs": logs, - "errors": errors, - "duration": duration, - "scheduledAt": scheduledAt, - }; - } -} + /// Execution ID. + final String $id; + /// Execution creation date in ISO 8601 format. + final String $createdAt; + /// Execution upate date in ISO 8601 format. + final String $updatedAt; + /// Execution roles. + final List<String> $permissions; + /// Function ID. + final String functionId; + /// The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`. + final String trigger; + /// The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`. + final String status; + /// HTTP request method type. + final String requestMethod; + /// HTTP request path and query. + final String requestPath; + /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. + final List<Headers> requestHeaders; + /// HTTP response status code. + final int responseStatusCode; + /// HTTP response body. This will return empty unless execution is created as synchronous. + final String responseBody; + /// HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. + final List<Headers> responseHeaders; + /// Function logs. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. + final String logs; + /// Function errors. Includes the last 4,000 characters. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. + final String errors; + /// Function execution duration in seconds. + final double duration; + /// The scheduled time for execution. If left empty, execution will be queued immediately. + final String? scheduledAt; + + Execution({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.functionId, + required this.trigger, + required this.status, + required this.requestMethod, + required this.requestPath, + required this.requestHeaders, + required this.responseStatusCode, + required this.responseBody, + required this.responseHeaders, + required this.logs, + required this.errors, + required this.duration, + this.scheduledAt, + }); + + factory Execution.fromMap(Map<String, dynamic> map) { + return Execution( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: List<String>.from(map['\$permissions']?.map((x) => x.toString()) ?? []), + functionId: map['functionId'].toString(), + trigger: map['trigger'].toString(), + status: map['status'].toString(), + requestMethod: map['requestMethod'].toString(), + requestPath: map['requestPath'].toString(), + requestHeaders: List<Headers>.from(map['requestHeaders'].map((p) => Headers.fromMap(p))), + responseStatusCode: map['responseStatusCode'], + responseBody: map['responseBody'].toString(), + responseHeaders: List<Headers>.from(map['responseHeaders'].map((p) => Headers.fromMap(p))), + logs: map['logs'].toString(), + errors: map['errors'].toString(), + duration: map['duration'].toDouble(), + scheduledAt: map['scheduledAt']?.toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "functionId": functionId, + "trigger": trigger, + "status": status, + "requestMethod": requestMethod, + "requestPath": requestPath, + "requestHeaders": requestHeaders.map((p) => p.toMap()).toList(), + "responseStatusCode": responseStatusCode, + "responseBody": responseBody, + "responseHeaders": responseHeaders.map((p) => p.toMap()).toList(), + "logs": logs, + "errors": errors, + "duration": duration, + "scheduledAt": scheduledAt, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/execution_list.dart b/lib/src/models/execution_list.dart index 32e40531..b7084929 100644 --- a/lib/src/models/execution_list.dart +++ b/lib/src/models/execution_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Executions List class ExecutionList implements Model { - /// Total number of executions documents that matched your query. - final int total; + /// Total number of executions documents that matched your query. + final int total; + /// List of executions. + final List<Execution> executions; - /// List of executions. - final List<Execution> executions; + ExecutionList({ + required this.total, + required this.executions, + }); - ExecutionList({ - required this.total, - required this.executions, - }); + factory ExecutionList.fromMap(Map<String, dynamic> map) { + return ExecutionList( + total: map['total'], + executions: List<Execution>.from(map['executions'].map((p) => Execution.fromMap(p))), + ); + } - factory ExecutionList.fromMap(Map<String, dynamic> map) { - return ExecutionList( - total: map['total'], - executions: List<Execution>.from( - map['executions'].map((p) => Execution.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "executions": executions.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "executions": executions.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/file.dart b/lib/src/models/file.dart index 4bca1fe3..c3815be9 100644 --- a/lib/src/models/file.dart +++ b/lib/src/models/file.dart @@ -2,82 +2,72 @@ part of '../../models.dart'; /// File class File implements Model { - /// File ID. - final String $id; + /// File ID. + final String $id; + /// Bucket ID. + final String bucketId; + /// File creation date in ISO 8601 format. + final String $createdAt; + /// File update date in ISO 8601 format. + final String $updatedAt; + /// File permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). + final List<String> $permissions; + /// File name. + final String name; + /// File MD5 signature. + final String signature; + /// File mime type. + final String mimeType; + /// File original size in bytes. + final int sizeOriginal; + /// Total number of chunks available + final int chunksTotal; + /// Total number of chunks uploaded + final int chunksUploaded; - /// Bucket ID. - final String bucketId; + File({ + required this.$id, + required this.bucketId, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.name, + required this.signature, + required this.mimeType, + required this.sizeOriginal, + required this.chunksTotal, + required this.chunksUploaded, + }); - /// File creation date in ISO 8601 format. - final String $createdAt; + factory File.fromMap(Map<String, dynamic> map) { + return File( + $id: map['\$id'].toString(), + bucketId: map['bucketId'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: List<String>.from(map['\$permissions']?.map((x) => x.toString()) ?? []), + name: map['name'].toString(), + signature: map['signature'].toString(), + mimeType: map['mimeType'].toString(), + sizeOriginal: map['sizeOriginal'], + chunksTotal: map['chunksTotal'], + chunksUploaded: map['chunksUploaded'], + ); + } - /// File update date in ISO 8601 format. - final String $updatedAt; - - /// File permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). - final List<String> $permissions; - - /// File name. - final String name; - - /// File MD5 signature. - final String signature; - - /// File mime type. - final String mimeType; - - /// File original size in bytes. - final int sizeOriginal; - - /// Total number of chunks available - final int chunksTotal; - - /// Total number of chunks uploaded - final int chunksUploaded; - - File({ - required this.$id, - required this.bucketId, - required this.$createdAt, - required this.$updatedAt, - required this.$permissions, - required this.name, - required this.signature, - required this.mimeType, - required this.sizeOriginal, - required this.chunksTotal, - required this.chunksUploaded, - }); - - factory File.fromMap(Map<String, dynamic> map) { - return File( - $id: map['\$id'].toString(), - bucketId: map['bucketId'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - $permissions: map['\$permissions'] ?? [], - name: map['name'].toString(), - signature: map['signature'].toString(), - mimeType: map['mimeType'].toString(), - sizeOriginal: map['sizeOriginal'], - chunksTotal: map['chunksTotal'], - chunksUploaded: map['chunksUploaded'], - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "bucketId": bucketId, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "\$permissions": $permissions, - "name": name, - "signature": signature, - "mimeType": mimeType, - "sizeOriginal": sizeOriginal, - "chunksTotal": chunksTotal, - "chunksUploaded": chunksUploaded, - }; - } -} + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "bucketId": bucketId, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "name": name, + "signature": signature, + "mimeType": mimeType, + "sizeOriginal": sizeOriginal, + "chunksTotal": chunksTotal, + "chunksUploaded": chunksUploaded, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/file_list.dart b/lib/src/models/file_list.dart index 3b695c93..3bc9ddf5 100644 --- a/lib/src/models/file_list.dart +++ b/lib/src/models/file_list.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Files List class FileList implements Model { - /// Total number of files documents that matched your query. - final int total; + /// Total number of files documents that matched your query. + final int total; + /// List of files. + final List<File> files; - /// List of files. - final List<File> files; + FileList({ + required this.total, + required this.files, + }); - FileList({ - required this.total, - required this.files, - }); + factory FileList.fromMap(Map<String, dynamic> map) { + return FileList( + total: map['total'], + files: List<File>.from(map['files'].map((p) => File.fromMap(p))), + ); + } - factory FileList.fromMap(Map<String, dynamic> map) { - return FileList( - total: map['total'], - files: List<File>.from(map['files'].map((p) => File.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "files": files.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "files": files.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/function.dart b/lib/src/models/function.dart index 83b5a60d..f7a36312 100644 --- a/lib/src/models/function.dart +++ b/lib/src/models/function.dart @@ -2,160 +2,137 @@ part of '../../models.dart'; /// Function class Func implements Model { - /// Function ID. - final String $id; - - /// Function creation date in ISO 8601 format. - final String $createdAt; - - /// Function update date in ISO 8601 format. - final String $updatedAt; - - /// Execution permissions. - final List<String> execute; - - /// Function name. - final String name; - - /// Function enabled. - final bool enabled; - - /// Is the function deployed with the latest configuration? This is set to false if you've changed an environment variables, entrypoint, commands, or other settings that needs redeploy to be applied. When the value is false, redeploy the function to update it with the latest configuration. - final bool live; - - /// Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project. - final bool logging; - - /// Function execution runtime. - final String runtime; - - /// Function's active deployment ID. - final String deployment; - - /// Allowed permission scopes. - final List<String> scopes; - - /// Function variables. - final List<Variable> vars; - - /// Function trigger events. - final List<String> events; - - /// Function execution schedule in CRON format. - final String schedule; - - /// Function execution timeout in seconds. - final int timeout; - - /// The entrypoint file used to execute the deployment. - final String entrypoint; - - /// The build command used to build the deployment. - final String commands; - - /// Version of Open Runtimes used for the function. - final String version; - - /// Function VCS (Version Control System) installation id. - final String installationId; - - /// VCS (Version Control System) Repository ID - final String providerRepositoryId; - - /// VCS (Version Control System) branch name - final String providerBranch; - - /// Path to function in VCS (Version Control System) repository - final String providerRootDirectory; - - /// Is VCS (Version Control System) connection is in silent mode? When in silence mode, no comments will be posted on the repository pull or merge requests - final bool providerSilentMode; - - /// Machine specification for builds and executions. - final String specification; - - Func({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.execute, - required this.name, - required this.enabled, - required this.live, - required this.logging, - required this.runtime, - required this.deployment, - required this.scopes, - required this.vars, - required this.events, - required this.schedule, - required this.timeout, - required this.entrypoint, - required this.commands, - required this.version, - required this.installationId, - required this.providerRepositoryId, - required this.providerBranch, - required this.providerRootDirectory, - required this.providerSilentMode, - required this.specification, - }); - - factory Func.fromMap(Map<String, dynamic> map) { - return Func( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - execute: map['execute'] ?? [], - name: map['name'].toString(), - enabled: map['enabled'], - live: map['live'], - logging: map['logging'], - runtime: map['runtime'].toString(), - deployment: map['deployment'].toString(), - scopes: map['scopes'] ?? [], - vars: List<Variable>.from(map['vars'].map((p) => Variable.fromMap(p))), - events: map['events'] ?? [], - schedule: map['schedule'].toString(), - timeout: map['timeout'], - entrypoint: map['entrypoint'].toString(), - commands: map['commands'].toString(), - version: map['version'].toString(), - installationId: map['installationId'].toString(), - providerRepositoryId: map['providerRepositoryId'].toString(), - providerBranch: map['providerBranch'].toString(), - providerRootDirectory: map['providerRootDirectory'].toString(), - providerSilentMode: map['providerSilentMode'], - specification: map['specification'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "execute": execute, - "name": name, - "enabled": enabled, - "live": live, - "logging": logging, - "runtime": runtime, - "deployment": deployment, - "scopes": scopes, - "vars": vars.map((p) => p.toMap()).toList(), - "events": events, - "schedule": schedule, - "timeout": timeout, - "entrypoint": entrypoint, - "commands": commands, - "version": version, - "installationId": installationId, - "providerRepositoryId": providerRepositoryId, - "providerBranch": providerBranch, - "providerRootDirectory": providerRootDirectory, - "providerSilentMode": providerSilentMode, - "specification": specification, - }; - } -} + /// Function ID. + final String $id; + /// Function creation date in ISO 8601 format. + final String $createdAt; + /// Function update date in ISO 8601 format. + final String $updatedAt; + /// Execution permissions. + final List<String> execute; + /// Function name. + final String name; + /// Function enabled. + final bool enabled; + /// Is the function deployed with the latest configuration? This is set to false if you've changed an environment variables, entrypoint, commands, or other settings that needs redeploy to be applied. When the value is false, redeploy the function to update it with the latest configuration. + final bool live; + /// Whether executions will be logged. When set to false, executions will not be logged, but will reduce resource used by your Appwrite project. + final bool logging; + /// Function execution runtime. + final String runtime; + /// Function's active deployment ID. + final String deployment; + /// Allowed permission scopes. + final List<String> scopes; + /// Function variables. + final List<Variable> vars; + /// Function trigger events. + final List<String> events; + /// Function execution schedule in CRON format. + final String schedule; + /// Function execution timeout in seconds. + final int timeout; + /// The entrypoint file used to execute the deployment. + final String entrypoint; + /// The build command used to build the deployment. + final String commands; + /// Version of Open Runtimes used for the function. + final String version; + /// Function VCS (Version Control System) installation id. + final String installationId; + /// VCS (Version Control System) Repository ID + final String providerRepositoryId; + /// VCS (Version Control System) branch name + final String providerBranch; + /// Path to function in VCS (Version Control System) repository + final String providerRootDirectory; + /// Is VCS (Version Control System) connection is in silent mode? When in silence mode, no comments will be posted on the repository pull or merge requests + final bool providerSilentMode; + /// Machine specification for builds and executions. + final String specification; + + Func({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.execute, + required this.name, + required this.enabled, + required this.live, + required this.logging, + required this.runtime, + required this.deployment, + required this.scopes, + required this.vars, + required this.events, + required this.schedule, + required this.timeout, + required this.entrypoint, + required this.commands, + required this.version, + required this.installationId, + required this.providerRepositoryId, + required this.providerBranch, + required this.providerRootDirectory, + required this.providerSilentMode, + required this.specification, + }); + + factory Func.fromMap(Map<String, dynamic> map) { + return Func( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + execute: List<String>.from(map['execute']?.map((x) => x.toString()) ?? []), + name: map['name'].toString(), + enabled: map['enabled'], + live: map['live'], + logging: map['logging'], + runtime: map['runtime'].toString(), + deployment: map['deployment'].toString(), + scopes: List<String>.from(map['scopes']?.map((x) => x.toString()) ?? []), + vars: List<Variable>.from(map['vars'].map((p) => Variable.fromMap(p))), + events: List<String>.from(map['events']?.map((x) => x.toString()) ?? []), + schedule: map['schedule'].toString(), + timeout: map['timeout'], + entrypoint: map['entrypoint'].toString(), + commands: map['commands'].toString(), + version: map['version'].toString(), + installationId: map['installationId'].toString(), + providerRepositoryId: map['providerRepositoryId'].toString(), + providerBranch: map['providerBranch'].toString(), + providerRootDirectory: map['providerRootDirectory'].toString(), + providerSilentMode: map['providerSilentMode'], + specification: map['specification'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "execute": execute, + "name": name, + "enabled": enabled, + "live": live, + "logging": logging, + "runtime": runtime, + "deployment": deployment, + "scopes": scopes, + "vars": vars.map((p) => p.toMap()).toList(), + "events": events, + "schedule": schedule, + "timeout": timeout, + "entrypoint": entrypoint, + "commands": commands, + "version": version, + "installationId": installationId, + "providerRepositoryId": providerRepositoryId, + "providerBranch": providerBranch, + "providerRootDirectory": providerRootDirectory, + "providerSilentMode": providerSilentMode, + "specification": specification, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/function_list.dart b/lib/src/models/function_list.dart index 5c53b276..5a23deed 100644 --- a/lib/src/models/function_list.dart +++ b/lib/src/models/function_list.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Functions List class FunctionList implements Model { - /// Total number of functions documents that matched your query. - final int total; + /// Total number of functions documents that matched your query. + final int total; + /// List of functions. + final List<Func> functions; - /// List of functions. - final List<Func> functions; + FunctionList({ + required this.total, + required this.functions, + }); - FunctionList({ - required this.total, - required this.functions, - }); + factory FunctionList.fromMap(Map<String, dynamic> map) { + return FunctionList( + total: map['total'], + functions: List<Func>.from(map['functions'].map((p) => Func.fromMap(p))), + ); + } - factory FunctionList.fromMap(Map<String, dynamic> map) { - return FunctionList( - total: map['total'], - functions: List<Func>.from(map['functions'].map((p) => Func.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "functions": functions.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "functions": functions.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/headers.dart b/lib/src/models/headers.dart index 22494998..6fc1988a 100644 --- a/lib/src/models/headers.dart +++ b/lib/src/models/headers.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Headers class Headers implements Model { - /// Header name. - final String name; + /// Header name. + final String name; + /// Header value. + final String value; - /// Header value. - final String value; + Headers({ + required this.name, + required this.value, + }); - Headers({ - required this.name, - required this.value, - }); + factory Headers.fromMap(Map<String, dynamic> map) { + return Headers( + name: map['name'].toString(), + value: map['value'].toString(), + ); + } - factory Headers.fromMap(Map<String, dynamic> map) { - return Headers( - name: map['name'].toString(), - value: map['value'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "name": name, - "value": value, - }; - } -} + Map<String, dynamic> toMap() { + return { + "name": name, + "value": value, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/health_antivirus.dart b/lib/src/models/health_antivirus.dart index aabc7d85..54950db9 100644 --- a/lib/src/models/health_antivirus.dart +++ b/lib/src/models/health_antivirus.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Health Antivirus class HealthAntivirus implements Model { - /// Antivirus version. - final String version; + /// Antivirus version. + final String version; + /// Antivirus status. Possible values can are: `disabled`, `offline`, `online` + final String status; - /// Antivirus status. Possible values can are: `disabled`, `offline`, `online` - final String status; + HealthAntivirus({ + required this.version, + required this.status, + }); - HealthAntivirus({ - required this.version, - required this.status, - }); + factory HealthAntivirus.fromMap(Map<String, dynamic> map) { + return HealthAntivirus( + version: map['version'].toString(), + status: map['status'].toString(), + ); + } - factory HealthAntivirus.fromMap(Map<String, dynamic> map) { - return HealthAntivirus( - version: map['version'].toString(), - status: map['status'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "version": version, - "status": status, - }; - } -} + Map<String, dynamic> toMap() { + return { + "version": version, + "status": status, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/health_certificate.dart b/lib/src/models/health_certificate.dart index d412eba9..2b58db30 100644 --- a/lib/src/models/health_certificate.dart +++ b/lib/src/models/health_certificate.dart @@ -2,52 +2,47 @@ part of '../../models.dart'; /// Health Certificate class HealthCertificate implements Model { - /// Certificate name - final String name; - - /// Subject SN - final String subjectSN; - - /// Issuer organisation - final String issuerOrganisation; - - /// Valid from - final String validFrom; - - /// Valid to - final String validTo; - - /// Signature type SN - final String signatureTypeSN; - - HealthCertificate({ - required this.name, - required this.subjectSN, - required this.issuerOrganisation, - required this.validFrom, - required this.validTo, - required this.signatureTypeSN, - }); - - factory HealthCertificate.fromMap(Map<String, dynamic> map) { - return HealthCertificate( - name: map['name'].toString(), - subjectSN: map['subjectSN'].toString(), - issuerOrganisation: map['issuerOrganisation'].toString(), - validFrom: map['validFrom'].toString(), - validTo: map['validTo'].toString(), - signatureTypeSN: map['signatureTypeSN'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "name": name, - "subjectSN": subjectSN, - "issuerOrganisation": issuerOrganisation, - "validFrom": validFrom, - "validTo": validTo, - "signatureTypeSN": signatureTypeSN, - }; - } -} + /// Certificate name + final String name; + /// Subject SN + final String subjectSN; + /// Issuer organisation + final String issuerOrganisation; + /// Valid from + final String validFrom; + /// Valid to + final String validTo; + /// Signature type SN + final String signatureTypeSN; + + HealthCertificate({ + required this.name, + required this.subjectSN, + required this.issuerOrganisation, + required this.validFrom, + required this.validTo, + required this.signatureTypeSN, + }); + + factory HealthCertificate.fromMap(Map<String, dynamic> map) { + return HealthCertificate( + name: map['name'].toString(), + subjectSN: map['subjectSN'].toString(), + issuerOrganisation: map['issuerOrganisation'].toString(), + validFrom: map['validFrom'].toString(), + validTo: map['validTo'].toString(), + signatureTypeSN: map['signatureTypeSN'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "name": name, + "subjectSN": subjectSN, + "issuerOrganisation": issuerOrganisation, + "validFrom": validFrom, + "validTo": validTo, + "signatureTypeSN": signatureTypeSN, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/health_queue.dart b/lib/src/models/health_queue.dart index 8b3aa1b6..ecb8c835 100644 --- a/lib/src/models/health_queue.dart +++ b/lib/src/models/health_queue.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// Health Queue class HealthQueue implements Model { - /// Amount of actions in the queue. - final int size; + /// Amount of actions in the queue. + final int size; - HealthQueue({ - required this.size, - }); + HealthQueue({ + required this.size, + }); - factory HealthQueue.fromMap(Map<String, dynamic> map) { - return HealthQueue( - size: map['size'], - ); - } + factory HealthQueue.fromMap(Map<String, dynamic> map) { + return HealthQueue( + size: map['size'], + ); + } - Map<String, dynamic> toMap() { - return { - "size": size, - }; - } -} + Map<String, dynamic> toMap() { + return { + "size": size, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/health_status.dart b/lib/src/models/health_status.dart index b22b2c8a..7b57bb13 100644 --- a/lib/src/models/health_status.dart +++ b/lib/src/models/health_status.dart @@ -2,34 +2,32 @@ part of '../../models.dart'; /// Health Status class HealthStatus implements Model { - /// Name of the service. - final String name; + /// Name of the service. + final String name; + /// Duration in milliseconds how long the health check took. + final int ping; + /// Service status. Possible values can are: `pass`, `fail` + final String status; - /// Duration in milliseconds how long the health check took. - final int ping; + HealthStatus({ + required this.name, + required this.ping, + required this.status, + }); - /// Service status. Possible values can are: `pass`, `fail` - final String status; + factory HealthStatus.fromMap(Map<String, dynamic> map) { + return HealthStatus( + name: map['name'].toString(), + ping: map['ping'], + status: map['status'].toString(), + ); + } - HealthStatus({ - required this.name, - required this.ping, - required this.status, - }); - - factory HealthStatus.fromMap(Map<String, dynamic> map) { - return HealthStatus( - name: map['name'].toString(), - ping: map['ping'], - status: map['status'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "name": name, - "ping": ping, - "status": status, - }; - } -} + Map<String, dynamic> toMap() { + return { + "name": name, + "ping": ping, + "status": status, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/health_time.dart b/lib/src/models/health_time.dart index 0ed15f0a..546da504 100644 --- a/lib/src/models/health_time.dart +++ b/lib/src/models/health_time.dart @@ -2,34 +2,32 @@ part of '../../models.dart'; /// Health Time class HealthTime implements Model { - /// Current unix timestamp on trustful remote server. - final int remoteTime; + /// Current unix timestamp on trustful remote server. + final int remoteTime; + /// Current unix timestamp of local server where Appwrite runs. + final int localTime; + /// Difference of unix remote and local timestamps in milliseconds. + final int diff; - /// Current unix timestamp of local server where Appwrite runs. - final int localTime; + HealthTime({ + required this.remoteTime, + required this.localTime, + required this.diff, + }); - /// Difference of unix remote and local timestamps in milliseconds. - final int diff; + factory HealthTime.fromMap(Map<String, dynamic> map) { + return HealthTime( + remoteTime: map['remoteTime'], + localTime: map['localTime'], + diff: map['diff'], + ); + } - HealthTime({ - required this.remoteTime, - required this.localTime, - required this.diff, - }); - - factory HealthTime.fromMap(Map<String, dynamic> map) { - return HealthTime( - remoteTime: map['remoteTime'], - localTime: map['localTime'], - diff: map['diff'], - ); - } - - Map<String, dynamic> toMap() { - return { - "remoteTime": remoteTime, - "localTime": localTime, - "diff": diff, - }; - } -} + Map<String, dynamic> toMap() { + return { + "remoteTime": remoteTime, + "localTime": localTime, + "diff": diff, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/identity.dart b/lib/src/models/identity.dart index 807bdfd0..e5ed0fd3 100644 --- a/lib/src/models/identity.dart +++ b/lib/src/models/identity.dart @@ -2,76 +2,67 @@ part of '../../models.dart'; /// Identity class Identity implements Model { - /// Identity ID. - final String $id; + /// Identity ID. + final String $id; + /// Identity creation date in ISO 8601 format. + final String $createdAt; + /// Identity update date in ISO 8601 format. + final String $updatedAt; + /// User ID. + final String userId; + /// Identity Provider. + final String provider; + /// ID of the User in the Identity Provider. + final String providerUid; + /// Email of the User in the Identity Provider. + final String providerEmail; + /// Identity Provider Access Token. + final String providerAccessToken; + /// The date of when the access token expires in ISO 8601 format. + final String providerAccessTokenExpiry; + /// Identity Provider Refresh Token. + final String providerRefreshToken; - /// Identity creation date in ISO 8601 format. - final String $createdAt; + Identity({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.userId, + required this.provider, + required this.providerUid, + required this.providerEmail, + required this.providerAccessToken, + required this.providerAccessTokenExpiry, + required this.providerRefreshToken, + }); - /// Identity update date in ISO 8601 format. - final String $updatedAt; + factory Identity.fromMap(Map<String, dynamic> map) { + return Identity( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + userId: map['userId'].toString(), + provider: map['provider'].toString(), + providerUid: map['providerUid'].toString(), + providerEmail: map['providerEmail'].toString(), + providerAccessToken: map['providerAccessToken'].toString(), + providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), + providerRefreshToken: map['providerRefreshToken'].toString(), + ); + } - /// User ID. - final String userId; - - /// Identity Provider. - final String provider; - - /// ID of the User in the Identity Provider. - final String providerUid; - - /// Email of the User in the Identity Provider. - final String providerEmail; - - /// Identity Provider Access Token. - final String providerAccessToken; - - /// The date of when the access token expires in ISO 8601 format. - final String providerAccessTokenExpiry; - - /// Identity Provider Refresh Token. - final String providerRefreshToken; - - Identity({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.userId, - required this.provider, - required this.providerUid, - required this.providerEmail, - required this.providerAccessToken, - required this.providerAccessTokenExpiry, - required this.providerRefreshToken, - }); - - factory Identity.fromMap(Map<String, dynamic> map) { - return Identity( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - userId: map['userId'].toString(), - provider: map['provider'].toString(), - providerUid: map['providerUid'].toString(), - providerEmail: map['providerEmail'].toString(), - providerAccessToken: map['providerAccessToken'].toString(), - providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), - providerRefreshToken: map['providerRefreshToken'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "userId": userId, - "provider": provider, - "providerUid": providerUid, - "providerEmail": providerEmail, - "providerAccessToken": providerAccessToken, - "providerAccessTokenExpiry": providerAccessTokenExpiry, - "providerRefreshToken": providerRefreshToken, - }; - } -} + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "userId": userId, + "provider": provider, + "providerUid": providerUid, + "providerEmail": providerEmail, + "providerAccessToken": providerAccessToken, + "providerAccessTokenExpiry": providerAccessTokenExpiry, + "providerRefreshToken": providerRefreshToken, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/identity_list.dart b/lib/src/models/identity_list.dart index eab513d8..09ed27bc 100644 --- a/lib/src/models/identity_list.dart +++ b/lib/src/models/identity_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Identities List class IdentityList implements Model { - /// Total number of identities documents that matched your query. - final int total; + /// Total number of identities documents that matched your query. + final int total; + /// List of identities. + final List<Identity> identities; - /// List of identities. - final List<Identity> identities; + IdentityList({ + required this.total, + required this.identities, + }); - IdentityList({ - required this.total, - required this.identities, - }); + factory IdentityList.fromMap(Map<String, dynamic> map) { + return IdentityList( + total: map['total'], + identities: List<Identity>.from(map['identities'].map((p) => Identity.fromMap(p))), + ); + } - factory IdentityList.fromMap(Map<String, dynamic> map) { - return IdentityList( - total: map['total'], - identities: List<Identity>.from( - map['identities'].map((p) => Identity.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "identities": identities.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "identities": identities.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/index.dart b/lib/src/models/index.dart index 322f1228..6e84b578 100644 --- a/lib/src/models/index.dart +++ b/lib/src/models/index.dart @@ -2,64 +2,57 @@ part of '../../models.dart'; /// Index class Index implements Model { - /// Index Key. - final String key; - - /// Index type. - final String type; - - /// Index status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` - final String status; - - /// Error message. Displays error generated on failure of creating or deleting an index. - final String error; - - /// Index attributes. - final List<String> attributes; - - /// Index orders. - final List<String>? orders; - - /// Index creation date in ISO 8601 format. - final String $createdAt; - - /// Index update date in ISO 8601 format. - final String $updatedAt; - - Index({ - required this.key, - required this.type, - required this.status, - required this.error, - required this.attributes, - this.orders, - required this.$createdAt, - required this.$updatedAt, - }); - - factory Index.fromMap(Map<String, dynamic> map) { - return Index( - key: map['key'].toString(), - type: map['type'].toString(), - status: map['status'].toString(), - error: map['error'].toString(), - attributes: map['attributes'] ?? [], - orders: map['orders'], - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "key": key, - "type": type, - "status": status, - "error": error, - "attributes": attributes, - "orders": orders, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - }; - } -} + /// Index Key. + final String key; + /// Index type. + final String type; + /// Index status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + final String status; + /// Error message. Displays error generated on failure of creating or deleting an index. + final String error; + /// Index attributes. + final List<String> attributes; + /// Index orders. + final List<String>? orders; + /// Index creation date in ISO 8601 format. + final String $createdAt; + /// Index update date in ISO 8601 format. + final String $updatedAt; + + Index({ + required this.key, + required this.type, + required this.status, + required this.error, + required this.attributes, + this.orders, + required this.$createdAt, + required this.$updatedAt, + }); + + factory Index.fromMap(Map<String, dynamic> map) { + return Index( + key: map['key'].toString(), + type: map['type'].toString(), + status: map['status'].toString(), + error: map['error'].toString(), + attributes: List<String>.from(map['attributes']?.map((x) => x.toString()) ?? []), + orders: List<String>.from(map['orders']?.map((x) => x.toString()) ?? []), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "key": key, + "type": type, + "status": status, + "error": error, + "attributes": attributes, + "orders": orders, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/index_list.dart b/lib/src/models/index_list.dart index 4b9ec280..bfc7ed8c 100644 --- a/lib/src/models/index_list.dart +++ b/lib/src/models/index_list.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Indexes List class IndexList implements Model { - /// Total number of indexes documents that matched your query. - final int total; + /// Total number of indexes documents that matched your query. + final int total; + /// List of indexes. + final List<Index> indexes; - /// List of indexes. - final List<Index> indexes; + IndexList({ + required this.total, + required this.indexes, + }); - IndexList({ - required this.total, - required this.indexes, - }); + factory IndexList.fromMap(Map<String, dynamic> map) { + return IndexList( + total: map['total'], + indexes: List<Index>.from(map['indexes'].map((p) => Index.fromMap(p))), + ); + } - factory IndexList.fromMap(Map<String, dynamic> map) { - return IndexList( - total: map['total'], - indexes: List<Index>.from(map['indexes'].map((p) => Index.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "indexes": indexes.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "indexes": indexes.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/jwt.dart b/lib/src/models/jwt.dart index e2e31bd2..cc398c64 100644 --- a/lib/src/models/jwt.dart +++ b/lib/src/models/jwt.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// JWT class Jwt implements Model { - /// JWT encoded string. - final String jwt; + /// JWT encoded string. + final String jwt; - Jwt({ - required this.jwt, - }); + Jwt({ + required this.jwt, + }); - factory Jwt.fromMap(Map<String, dynamic> map) { - return Jwt( - jwt: map['jwt'].toString(), - ); - } + factory Jwt.fromMap(Map<String, dynamic> map) { + return Jwt( + jwt: map['jwt'].toString(), + ); + } - Map<String, dynamic> toMap() { - return { - "jwt": jwt, - }; - } -} + Map<String, dynamic> toMap() { + return { + "jwt": jwt, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/language.dart b/lib/src/models/language.dart index b6ec6121..cd0af818 100644 --- a/lib/src/models/language.dart +++ b/lib/src/models/language.dart @@ -2,34 +2,32 @@ part of '../../models.dart'; /// Language class Language implements Model { - /// Language name. - final String name; + /// Language name. + final String name; + /// Language two-character ISO 639-1 codes. + final String code; + /// Language native name. + final String nativeName; - /// Language two-character ISO 639-1 codes. - final String code; + Language({ + required this.name, + required this.code, + required this.nativeName, + }); - /// Language native name. - final String nativeName; + factory Language.fromMap(Map<String, dynamic> map) { + return Language( + name: map['name'].toString(), + code: map['code'].toString(), + nativeName: map['nativeName'].toString(), + ); + } - Language({ - required this.name, - required this.code, - required this.nativeName, - }); - - factory Language.fromMap(Map<String, dynamic> map) { - return Language( - name: map['name'].toString(), - code: map['code'].toString(), - nativeName: map['nativeName'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "name": name, - "code": code, - "nativeName": nativeName, - }; - } -} + Map<String, dynamic> toMap() { + return { + "name": name, + "code": code, + "nativeName": nativeName, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/language_list.dart b/lib/src/models/language_list.dart index 29f49481..2e645b3a 100644 --- a/lib/src/models/language_list.dart +++ b/lib/src/models/language_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Languages List class LanguageList implements Model { - /// Total number of languages documents that matched your query. - final int total; + /// Total number of languages documents that matched your query. + final int total; + /// List of languages. + final List<Language> languages; - /// List of languages. - final List<Language> languages; + LanguageList({ + required this.total, + required this.languages, + }); - LanguageList({ - required this.total, - required this.languages, - }); + factory LanguageList.fromMap(Map<String, dynamic> map) { + return LanguageList( + total: map['total'], + languages: List<Language>.from(map['languages'].map((p) => Language.fromMap(p))), + ); + } - factory LanguageList.fromMap(Map<String, dynamic> map) { - return LanguageList( - total: map['total'], - languages: - List<Language>.from(map['languages'].map((p) => Language.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "languages": languages.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "languages": languages.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/locale.dart b/lib/src/models/locale.dart index 084475bf..795ec738 100644 --- a/lib/src/models/locale.dart +++ b/lib/src/models/locale.dart @@ -2,58 +2,52 @@ part of '../../models.dart'; /// Locale class Locale implements Model { - /// User IP address. - final String ip; - - /// Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format - final String countryCode; - - /// Country name. This field support localization. - final String country; - - /// Continent code. A two character continent code "AF" for Africa, "AN" for Antarctica, "AS" for Asia, "EU" for Europe, "NA" for North America, "OC" for Oceania, and "SA" for South America. - final String continentCode; - - /// Continent name. This field support localization. - final String continent; - - /// True if country is part of the European Union. - final bool eu; - - /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format - final String currency; - - Locale({ - required this.ip, - required this.countryCode, - required this.country, - required this.continentCode, - required this.continent, - required this.eu, - required this.currency, - }); - - factory Locale.fromMap(Map<String, dynamic> map) { - return Locale( - ip: map['ip'].toString(), - countryCode: map['countryCode'].toString(), - country: map['country'].toString(), - continentCode: map['continentCode'].toString(), - continent: map['continent'].toString(), - eu: map['eu'], - currency: map['currency'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "ip": ip, - "countryCode": countryCode, - "country": country, - "continentCode": continentCode, - "continent": continent, - "eu": eu, - "currency": currency, - }; - } -} + /// User IP address. + final String ip; + /// Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format + final String countryCode; + /// Country name. This field support localization. + final String country; + /// Continent code. A two character continent code "AF" for Africa, "AN" for Antarctica, "AS" for Asia, "EU" for Europe, "NA" for North America, "OC" for Oceania, and "SA" for South America. + final String continentCode; + /// Continent name. This field support localization. + final String continent; + /// True if country is part of the European Union. + final bool eu; + /// Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format + final String currency; + + Locale({ + required this.ip, + required this.countryCode, + required this.country, + required this.continentCode, + required this.continent, + required this.eu, + required this.currency, + }); + + factory Locale.fromMap(Map<String, dynamic> map) { + return Locale( + ip: map['ip'].toString(), + countryCode: map['countryCode'].toString(), + country: map['country'].toString(), + continentCode: map['continentCode'].toString(), + continent: map['continent'].toString(), + eu: map['eu'], + currency: map['currency'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "ip": ip, + "countryCode": countryCode, + "country": country, + "continentCode": continentCode, + "continent": continent, + "eu": eu, + "currency": currency, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/locale_code.dart b/lib/src/models/locale_code.dart index 678e40c4..7cacc3e6 100644 --- a/lib/src/models/locale_code.dart +++ b/lib/src/models/locale_code.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// LocaleCode class LocaleCode implements Model { - /// Locale codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) - final String code; + /// Locale codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) + final String code; + /// Locale name + final String name; - /// Locale name - final String name; + LocaleCode({ + required this.code, + required this.name, + }); - LocaleCode({ - required this.code, - required this.name, - }); + factory LocaleCode.fromMap(Map<String, dynamic> map) { + return LocaleCode( + code: map['code'].toString(), + name: map['name'].toString(), + ); + } - factory LocaleCode.fromMap(Map<String, dynamic> map) { - return LocaleCode( - code: map['code'].toString(), - name: map['name'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "code": code, - "name": name, - }; - } -} + Map<String, dynamic> toMap() { + return { + "code": code, + "name": name, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/locale_code_list.dart b/lib/src/models/locale_code_list.dart index c3f4e4be..22d38e96 100644 --- a/lib/src/models/locale_code_list.dart +++ b/lib/src/models/locale_code_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Locale codes list class LocaleCodeList implements Model { - /// Total number of localeCodes documents that matched your query. - final int total; + /// Total number of localeCodes documents that matched your query. + final int total; + /// List of localeCodes. + final List<LocaleCode> localeCodes; - /// List of localeCodes. - final List<LocaleCode> localeCodes; + LocaleCodeList({ + required this.total, + required this.localeCodes, + }); - LocaleCodeList({ - required this.total, - required this.localeCodes, - }); + factory LocaleCodeList.fromMap(Map<String, dynamic> map) { + return LocaleCodeList( + total: map['total'], + localeCodes: List<LocaleCode>.from(map['localeCodes'].map((p) => LocaleCode.fromMap(p))), + ); + } - factory LocaleCodeList.fromMap(Map<String, dynamic> map) { - return LocaleCodeList( - total: map['total'], - localeCodes: List<LocaleCode>.from( - map['localeCodes'].map((p) => LocaleCode.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "localeCodes": localeCodes.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "localeCodes": localeCodes.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/log.dart b/lib/src/models/log.dart index 7fb3f364..c443fc98 100644 --- a/lib/src/models/log.dart +++ b/lib/src/models/log.dart @@ -2,142 +2,122 @@ part of '../../models.dart'; /// Log class Log implements Model { - /// Event name. - final String event; - - /// User ID. - final String userId; - - /// User Email. - final String userEmail; - - /// User Name. - final String userName; - - /// API mode when event triggered. - final String mode; - - /// IP session in use when the session was created. - final String ip; - - /// Log creation date in ISO 8601 format. - final String time; - - /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). - final String osCode; - - /// Operating system name. - final String osName; - - /// Operating system version. - final String osVersion; - - /// Client type. - final String clientType; - - /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). - final String clientCode; - - /// Client name. - final String clientName; - - /// Client version. - final String clientVersion; - - /// Client engine name. - final String clientEngine; - - /// Client engine name. - final String clientEngineVersion; - - /// Device name. - final String deviceName; - - /// Device brand name. - final String deviceBrand; - - /// Device model name. - final String deviceModel; - - /// Country two-character ISO 3166-1 alpha code. - final String countryCode; - - /// Country name. - final String countryName; - - Log({ - required this.event, - required this.userId, - required this.userEmail, - required this.userName, - required this.mode, - required this.ip, - required this.time, - required this.osCode, - required this.osName, - required this.osVersion, - required this.clientType, - required this.clientCode, - required this.clientName, - required this.clientVersion, - required this.clientEngine, - required this.clientEngineVersion, - required this.deviceName, - required this.deviceBrand, - required this.deviceModel, - required this.countryCode, - required this.countryName, - }); - - factory Log.fromMap(Map<String, dynamic> map) { - return Log( - event: map['event'].toString(), - userId: map['userId'].toString(), - userEmail: map['userEmail'].toString(), - userName: map['userName'].toString(), - mode: map['mode'].toString(), - ip: map['ip'].toString(), - time: map['time'].toString(), - osCode: map['osCode'].toString(), - osName: map['osName'].toString(), - osVersion: map['osVersion'].toString(), - clientType: map['clientType'].toString(), - clientCode: map['clientCode'].toString(), - clientName: map['clientName'].toString(), - clientVersion: map['clientVersion'].toString(), - clientEngine: map['clientEngine'].toString(), - clientEngineVersion: map['clientEngineVersion'].toString(), - deviceName: map['deviceName'].toString(), - deviceBrand: map['deviceBrand'].toString(), - deviceModel: map['deviceModel'].toString(), - countryCode: map['countryCode'].toString(), - countryName: map['countryName'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "event": event, - "userId": userId, - "userEmail": userEmail, - "userName": userName, - "mode": mode, - "ip": ip, - "time": time, - "osCode": osCode, - "osName": osName, - "osVersion": osVersion, - "clientType": clientType, - "clientCode": clientCode, - "clientName": clientName, - "clientVersion": clientVersion, - "clientEngine": clientEngine, - "clientEngineVersion": clientEngineVersion, - "deviceName": deviceName, - "deviceBrand": deviceBrand, - "deviceModel": deviceModel, - "countryCode": countryCode, - "countryName": countryName, - }; - } -} + /// Event name. + final String event; + /// User ID. + final String userId; + /// User Email. + final String userEmail; + /// User Name. + final String userName; + /// API mode when event triggered. + final String mode; + /// IP session in use when the session was created. + final String ip; + /// Log creation date in ISO 8601 format. + final String time; + /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). + final String osCode; + /// Operating system name. + final String osName; + /// Operating system version. + final String osVersion; + /// Client type. + final String clientType; + /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). + final String clientCode; + /// Client name. + final String clientName; + /// Client version. + final String clientVersion; + /// Client engine name. + final String clientEngine; + /// Client engine name. + final String clientEngineVersion; + /// Device name. + final String deviceName; + /// Device brand name. + final String deviceBrand; + /// Device model name. + final String deviceModel; + /// Country two-character ISO 3166-1 alpha code. + final String countryCode; + /// Country name. + final String countryName; + + Log({ + required this.event, + required this.userId, + required this.userEmail, + required this.userName, + required this.mode, + required this.ip, + required this.time, + required this.osCode, + required this.osName, + required this.osVersion, + required this.clientType, + required this.clientCode, + required this.clientName, + required this.clientVersion, + required this.clientEngine, + required this.clientEngineVersion, + required this.deviceName, + required this.deviceBrand, + required this.deviceModel, + required this.countryCode, + required this.countryName, + }); + + factory Log.fromMap(Map<String, dynamic> map) { + return Log( + event: map['event'].toString(), + userId: map['userId'].toString(), + userEmail: map['userEmail'].toString(), + userName: map['userName'].toString(), + mode: map['mode'].toString(), + ip: map['ip'].toString(), + time: map['time'].toString(), + osCode: map['osCode'].toString(), + osName: map['osName'].toString(), + osVersion: map['osVersion'].toString(), + clientType: map['clientType'].toString(), + clientCode: map['clientCode'].toString(), + clientName: map['clientName'].toString(), + clientVersion: map['clientVersion'].toString(), + clientEngine: map['clientEngine'].toString(), + clientEngineVersion: map['clientEngineVersion'].toString(), + deviceName: map['deviceName'].toString(), + deviceBrand: map['deviceBrand'].toString(), + deviceModel: map['deviceModel'].toString(), + countryCode: map['countryCode'].toString(), + countryName: map['countryName'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "event": event, + "userId": userId, + "userEmail": userEmail, + "userName": userName, + "mode": mode, + "ip": ip, + "time": time, + "osCode": osCode, + "osName": osName, + "osVersion": osVersion, + "clientType": clientType, + "clientCode": clientCode, + "clientName": clientName, + "clientVersion": clientVersion, + "clientEngine": clientEngine, + "clientEngineVersion": clientEngineVersion, + "deviceName": deviceName, + "deviceBrand": deviceBrand, + "deviceModel": deviceModel, + "countryCode": countryCode, + "countryName": countryName, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/log_list.dart b/lib/src/models/log_list.dart index a686897c..0f860d80 100644 --- a/lib/src/models/log_list.dart +++ b/lib/src/models/log_list.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Logs List class LogList implements Model { - /// Total number of logs documents that matched your query. - final int total; + /// Total number of logs documents that matched your query. + final int total; + /// List of logs. + final List<Log> logs; - /// List of logs. - final List<Log> logs; + LogList({ + required this.total, + required this.logs, + }); - LogList({ - required this.total, - required this.logs, - }); + factory LogList.fromMap(Map<String, dynamic> map) { + return LogList( + total: map['total'], + logs: List<Log>.from(map['logs'].map((p) => Log.fromMap(p))), + ); + } - factory LogList.fromMap(Map<String, dynamic> map) { - return LogList( - total: map['total'], - logs: List<Log>.from(map['logs'].map((p) => Log.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "logs": logs.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "logs": logs.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/membership.dart b/lib/src/models/membership.dart index 1dd1186d..d0e5aab0 100644 --- a/lib/src/models/membership.dart +++ b/lib/src/models/membership.dart @@ -2,94 +2,82 @@ part of '../../models.dart'; /// Membership class Membership implements Model { - /// Membership ID. - final String $id; - - /// Membership creation date in ISO 8601 format. - final String $createdAt; - - /// Membership update date in ISO 8601 format. - final String $updatedAt; - - /// User ID. - final String userId; - - /// User name. Hide this attribute by toggling membership privacy in the Console. - final String userName; - - /// User email address. Hide this attribute by toggling membership privacy in the Console. - final String userEmail; - - /// Team ID. - final String teamId; - - /// Team name. - final String teamName; - - /// Date, the user has been invited to join the team in ISO 8601 format. - final String invited; - - /// Date, the user has accepted the invitation to join the team in ISO 8601 format. - final String joined; - - /// User confirmation status, true if the user has joined the team or false otherwise. - final bool confirm; - - /// Multi factor authentication status, true if the user has MFA enabled or false otherwise. Hide this attribute by toggling membership privacy in the Console. - final bool mfa; - - /// User list of roles - final List<String> roles; - - Membership({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.userId, - required this.userName, - required this.userEmail, - required this.teamId, - required this.teamName, - required this.invited, - required this.joined, - required this.confirm, - required this.mfa, - required this.roles, - }); - - factory Membership.fromMap(Map<String, dynamic> map) { - return Membership( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - userId: map['userId'].toString(), - userName: map['userName'].toString(), - userEmail: map['userEmail'].toString(), - teamId: map['teamId'].toString(), - teamName: map['teamName'].toString(), - invited: map['invited'].toString(), - joined: map['joined'].toString(), - confirm: map['confirm'], - mfa: map['mfa'], - roles: map['roles'] ?? [], - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "userId": userId, - "userName": userName, - "userEmail": userEmail, - "teamId": teamId, - "teamName": teamName, - "invited": invited, - "joined": joined, - "confirm": confirm, - "mfa": mfa, - "roles": roles, - }; - } -} + /// Membership ID. + final String $id; + /// Membership creation date in ISO 8601 format. + final String $createdAt; + /// Membership update date in ISO 8601 format. + final String $updatedAt; + /// User ID. + final String userId; + /// User name. Hide this attribute by toggling membership privacy in the Console. + final String userName; + /// User email address. Hide this attribute by toggling membership privacy in the Console. + final String userEmail; + /// Team ID. + final String teamId; + /// Team name. + final String teamName; + /// Date, the user has been invited to join the team in ISO 8601 format. + final String invited; + /// Date, the user has accepted the invitation to join the team in ISO 8601 format. + final String joined; + /// User confirmation status, true if the user has joined the team or false otherwise. + final bool confirm; + /// Multi factor authentication status, true if the user has MFA enabled or false otherwise. Hide this attribute by toggling membership privacy in the Console. + final bool mfa; + /// User list of roles + final List<String> roles; + + Membership({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.userId, + required this.userName, + required this.userEmail, + required this.teamId, + required this.teamName, + required this.invited, + required this.joined, + required this.confirm, + required this.mfa, + required this.roles, + }); + + factory Membership.fromMap(Map<String, dynamic> map) { + return Membership( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + userId: map['userId'].toString(), + userName: map['userName'].toString(), + userEmail: map['userEmail'].toString(), + teamId: map['teamId'].toString(), + teamName: map['teamName'].toString(), + invited: map['invited'].toString(), + joined: map['joined'].toString(), + confirm: map['confirm'], + mfa: map['mfa'], + roles: List<String>.from(map['roles']?.map((x) => x.toString()) ?? []), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "userId": userId, + "userName": userName, + "userEmail": userEmail, + "teamId": teamId, + "teamName": teamName, + "invited": invited, + "joined": joined, + "confirm": confirm, + "mfa": mfa, + "roles": roles, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/membership_list.dart b/lib/src/models/membership_list.dart index ee65133b..7f1cd871 100644 --- a/lib/src/models/membership_list.dart +++ b/lib/src/models/membership_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Memberships List class MembershipList implements Model { - /// Total number of memberships documents that matched your query. - final int total; + /// Total number of memberships documents that matched your query. + final int total; + /// List of memberships. + final List<Membership> memberships; - /// List of memberships. - final List<Membership> memberships; + MembershipList({ + required this.total, + required this.memberships, + }); - MembershipList({ - required this.total, - required this.memberships, - }); + factory MembershipList.fromMap(Map<String, dynamic> map) { + return MembershipList( + total: map['total'], + memberships: List<Membership>.from(map['memberships'].map((p) => Membership.fromMap(p))), + ); + } - factory MembershipList.fromMap(Map<String, dynamic> map) { - return MembershipList( - total: map['total'], - memberships: List<Membership>.from( - map['memberships'].map((p) => Membership.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "memberships": memberships.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "memberships": memberships.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/message.dart b/lib/src/models/message.dart index 9664cebb..97c8dedb 100644 --- a/lib/src/models/message.dart +++ b/lib/src/models/message.dart @@ -2,94 +2,82 @@ part of '../../models.dart'; /// Message class Message implements Model { - /// Message ID. - final String $id; - - /// Message creation time in ISO 8601 format. - final String $createdAt; - - /// Message update date in ISO 8601 format. - final String $updatedAt; - - /// Message provider type. - final String providerType; - - /// Topic IDs set as recipients. - final List<String> topics; - - /// User IDs set as recipients. - final List<String> users; - - /// Target IDs set as recipients. - final List<String> targets; - - /// The scheduled time for message. - final String? scheduledAt; - - /// The time when the message was delivered. - final String? deliveredAt; - - /// Delivery errors if any. - final List<String>? deliveryErrors; - - /// Number of recipients the message was delivered to. - final int deliveredTotal; - - /// Data of the message. - final Map<String, dynamic> data; - - /// Status of delivery. - final String status; - - Message({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.providerType, - required this.topics, - required this.users, - required this.targets, - this.scheduledAt, - this.deliveredAt, - this.deliveryErrors, - required this.deliveredTotal, - required this.data, - required this.status, - }); - - factory Message.fromMap(Map<String, dynamic> map) { - return Message( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - providerType: map['providerType'].toString(), - topics: map['topics'] ?? [], - users: map['users'] ?? [], - targets: map['targets'] ?? [], - scheduledAt: map['scheduledAt']?.toString(), - deliveredAt: map['deliveredAt']?.toString(), - deliveryErrors: map['deliveryErrors'], - deliveredTotal: map['deliveredTotal'], - data: map['data'], - status: map['status'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "providerType": providerType, - "topics": topics, - "users": users, - "targets": targets, - "scheduledAt": scheduledAt, - "deliveredAt": deliveredAt, - "deliveryErrors": deliveryErrors, - "deliveredTotal": deliveredTotal, - "data": data, - "status": status, - }; - } -} + /// Message ID. + final String $id; + /// Message creation time in ISO 8601 format. + final String $createdAt; + /// Message update date in ISO 8601 format. + final String $updatedAt; + /// Message provider type. + final String providerType; + /// Topic IDs set as recipients. + final List<String> topics; + /// User IDs set as recipients. + final List<String> users; + /// Target IDs set as recipients. + final List<String> targets; + /// The scheduled time for message. + final String? scheduledAt; + /// The time when the message was delivered. + final String? deliveredAt; + /// Delivery errors if any. + final List<String>? deliveryErrors; + /// Number of recipients the message was delivered to. + final int deliveredTotal; + /// Data of the message. + final Map<String, dynamic> data; + /// Status of delivery. + final String status; + + Message({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.providerType, + required this.topics, + required this.users, + required this.targets, + this.scheduledAt, + this.deliveredAt, + this.deliveryErrors, + required this.deliveredTotal, + required this.data, + required this.status, + }); + + factory Message.fromMap(Map<String, dynamic> map) { + return Message( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + providerType: map['providerType'].toString(), + topics: List<String>.from(map['topics']?.map((x) => x.toString()) ?? []), + users: List<String>.from(map['users']?.map((x) => x.toString()) ?? []), + targets: List<String>.from(map['targets']?.map((x) => x.toString()) ?? []), + scheduledAt: map['scheduledAt']?.toString(), + deliveredAt: map['deliveredAt']?.toString(), + deliveryErrors: List<String>.from(map['deliveryErrors']?.map((x) => x.toString()) ?? []), + deliveredTotal: map['deliveredTotal'], + data: map['data'], + status: map['status'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "providerType": providerType, + "topics": topics, + "users": users, + "targets": targets, + "scheduledAt": scheduledAt, + "deliveredAt": deliveredAt, + "deliveryErrors": deliveryErrors, + "deliveredTotal": deliveredTotal, + "data": data, + "status": status, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/message_list.dart b/lib/src/models/message_list.dart index 4960c39d..6977eb95 100644 --- a/lib/src/models/message_list.dart +++ b/lib/src/models/message_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Message list class MessageList implements Model { - /// Total number of messages documents that matched your query. - final int total; + /// Total number of messages documents that matched your query. + final int total; + /// List of messages. + final List<Message> messages; - /// List of messages. - final List<Message> messages; + MessageList({ + required this.total, + required this.messages, + }); - MessageList({ - required this.total, - required this.messages, - }); + factory MessageList.fromMap(Map<String, dynamic> map) { + return MessageList( + total: map['total'], + messages: List<Message>.from(map['messages'].map((p) => Message.fromMap(p))), + ); + } - factory MessageList.fromMap(Map<String, dynamic> map) { - return MessageList( - total: map['total'], - messages: - List<Message>.from(map['messages'].map((p) => Message.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "messages": messages.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "messages": messages.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/mfa_challenge.dart b/lib/src/models/mfa_challenge.dart index 96bf3c65..c85b35ed 100644 --- a/lib/src/models/mfa_challenge.dart +++ b/lib/src/models/mfa_challenge.dart @@ -2,40 +2,37 @@ part of '../../models.dart'; /// MFA Challenge class MfaChallenge implements Model { - /// Token ID. - final String $id; + /// Token ID. + final String $id; + /// Token creation date in ISO 8601 format. + final String $createdAt; + /// User ID. + final String userId; + /// Token expiration date in ISO 8601 format. + final String expire; - /// Token creation date in ISO 8601 format. - final String $createdAt; + MfaChallenge({ + required this.$id, + required this.$createdAt, + required this.userId, + required this.expire, + }); - /// User ID. - final String userId; + factory MfaChallenge.fromMap(Map<String, dynamic> map) { + return MfaChallenge( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + userId: map['userId'].toString(), + expire: map['expire'].toString(), + ); + } - /// Token expiration date in ISO 8601 format. - final String expire; - - MfaChallenge({ - required this.$id, - required this.$createdAt, - required this.userId, - required this.expire, - }); - - factory MfaChallenge.fromMap(Map<String, dynamic> map) { - return MfaChallenge( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - userId: map['userId'].toString(), - expire: map['expire'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "userId": userId, - "expire": expire, - }; - } -} + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "userId": userId, + "expire": expire, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/mfa_factors.dart b/lib/src/models/mfa_factors.dart index c930a23e..1a969942 100644 --- a/lib/src/models/mfa_factors.dart +++ b/lib/src/models/mfa_factors.dart @@ -2,40 +2,37 @@ part of '../../models.dart'; /// MFAFactors class MfaFactors implements Model { - /// Can TOTP be used for MFA challenge for this account. - final bool totp; + /// Can TOTP be used for MFA challenge for this account. + final bool totp; + /// Can phone (SMS) be used for MFA challenge for this account. + final bool phone; + /// Can email be used for MFA challenge for this account. + final bool email; + /// Can recovery code be used for MFA challenge for this account. + final bool recoveryCode; - /// Can phone (SMS) be used for MFA challenge for this account. - final bool phone; + MfaFactors({ + required this.totp, + required this.phone, + required this.email, + required this.recoveryCode, + }); - /// Can email be used for MFA challenge for this account. - final bool email; + factory MfaFactors.fromMap(Map<String, dynamic> map) { + return MfaFactors( + totp: map['totp'], + phone: map['phone'], + email: map['email'], + recoveryCode: map['recoveryCode'], + ); + } - /// Can recovery code be used for MFA challenge for this account. - final bool recoveryCode; - - MfaFactors({ - required this.totp, - required this.phone, - required this.email, - required this.recoveryCode, - }); - - factory MfaFactors.fromMap(Map<String, dynamic> map) { - return MfaFactors( - totp: map['totp'], - phone: map['phone'], - email: map['email'], - recoveryCode: map['recoveryCode'], - ); - } - - Map<String, dynamic> toMap() { - return { - "totp": totp, - "phone": phone, - "email": email, - "recoveryCode": recoveryCode, - }; - } -} + Map<String, dynamic> toMap() { + return { + "totp": totp, + "phone": phone, + "email": email, + "recoveryCode": recoveryCode, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/mfa_recovery_codes.dart b/lib/src/models/mfa_recovery_codes.dart index c304de00..351bf107 100644 --- a/lib/src/models/mfa_recovery_codes.dart +++ b/lib/src/models/mfa_recovery_codes.dart @@ -2,22 +2,22 @@ part of '../../models.dart'; /// MFA Recovery Codes class MfaRecoveryCodes implements Model { - /// Recovery codes. - final List<String> recoveryCodes; + /// Recovery codes. + final List<String> recoveryCodes; - MfaRecoveryCodes({ - required this.recoveryCodes, - }); + MfaRecoveryCodes({ + required this.recoveryCodes, + }); - factory MfaRecoveryCodes.fromMap(Map<String, dynamic> map) { - return MfaRecoveryCodes( - recoveryCodes: map['recoveryCodes'] ?? [], - ); - } + factory MfaRecoveryCodes.fromMap(Map<String, dynamic> map) { + return MfaRecoveryCodes( + recoveryCodes: List<String>.from(map['recoveryCodes']?.map((x) => x.toString()) ?? []), + ); + } - Map<String, dynamic> toMap() { - return { - "recoveryCodes": recoveryCodes, - }; - } -} + Map<String, dynamic> toMap() { + return { + "recoveryCodes": recoveryCodes, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/mfa_type.dart b/lib/src/models/mfa_type.dart index 0573166e..3b874607 100644 --- a/lib/src/models/mfa_type.dart +++ b/lib/src/models/mfa_type.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// MFAType class MfaType implements Model { - /// Secret token used for TOTP factor. - final String secret; + /// Secret token used for TOTP factor. + final String secret; + /// URI for authenticator apps. + final String uri; - /// URI for authenticator apps. - final String uri; + MfaType({ + required this.secret, + required this.uri, + }); - MfaType({ - required this.secret, - required this.uri, - }); + factory MfaType.fromMap(Map<String, dynamic> map) { + return MfaType( + secret: map['secret'].toString(), + uri: map['uri'].toString(), + ); + } - factory MfaType.fromMap(Map<String, dynamic> map) { - return MfaType( - secret: map['secret'].toString(), - uri: map['uri'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "secret": secret, - "uri": uri, - }; - } -} + Map<String, dynamic> toMap() { + return { + "secret": secret, + "uri": uri, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/model.dart b/lib/src/models/model.dart index f810a35b..48e5b84a 100644 --- a/lib/src/models/model.dart +++ b/lib/src/models/model.dart @@ -2,4 +2,4 @@ part of '../../models.dart'; abstract class Model { Map<String, dynamic> toMap(); -} +} \ No newline at end of file diff --git a/lib/src/models/phone.dart b/lib/src/models/phone.dart index 40f7bcd2..f4b084c2 100644 --- a/lib/src/models/phone.dart +++ b/lib/src/models/phone.dart @@ -2,34 +2,32 @@ part of '../../models.dart'; /// Phone class Phone implements Model { - /// Phone code. - final String code; + /// Phone code. + final String code; + /// Country two-character ISO 3166-1 alpha code. + final String countryCode; + /// Country name. + final String countryName; - /// Country two-character ISO 3166-1 alpha code. - final String countryCode; + Phone({ + required this.code, + required this.countryCode, + required this.countryName, + }); - /// Country name. - final String countryName; + factory Phone.fromMap(Map<String, dynamic> map) { + return Phone( + code: map['code'].toString(), + countryCode: map['countryCode'].toString(), + countryName: map['countryName'].toString(), + ); + } - Phone({ - required this.code, - required this.countryCode, - required this.countryName, - }); - - factory Phone.fromMap(Map<String, dynamic> map) { - return Phone( - code: map['code'].toString(), - countryCode: map['countryCode'].toString(), - countryName: map['countryName'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "code": code, - "countryCode": countryCode, - "countryName": countryName, - }; - } -} + Map<String, dynamic> toMap() { + return { + "code": code, + "countryCode": countryCode, + "countryName": countryName, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/phone_list.dart b/lib/src/models/phone_list.dart index 1ae5a351..a8c6fe25 100644 --- a/lib/src/models/phone_list.dart +++ b/lib/src/models/phone_list.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Phones List class PhoneList implements Model { - /// Total number of phones documents that matched your query. - final int total; + /// Total number of phones documents that matched your query. + final int total; + /// List of phones. + final List<Phone> phones; - /// List of phones. - final List<Phone> phones; + PhoneList({ + required this.total, + required this.phones, + }); - PhoneList({ - required this.total, - required this.phones, - }); + factory PhoneList.fromMap(Map<String, dynamic> map) { + return PhoneList( + total: map['total'], + phones: List<Phone>.from(map['phones'].map((p) => Phone.fromMap(p))), + ); + } - factory PhoneList.fromMap(Map<String, dynamic> map) { - return PhoneList( - total: map['total'], - phones: List<Phone>.from(map['phones'].map((p) => Phone.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "phones": phones.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "phones": phones.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/preferences.dart b/lib/src/models/preferences.dart index 3549cff0..dc378efe 100644 --- a/lib/src/models/preferences.dart +++ b/lib/src/models/preferences.dart @@ -2,23 +2,23 @@ part of '../../models.dart'; /// Preferences class Preferences implements Model { - final Map<String, dynamic> data; + final Map<String, dynamic> data; - Preferences({ - required this.data, - }); + Preferences({ + required this.data, + }); - factory Preferences.fromMap(Map<String, dynamic> map) { - return Preferences( - data: map, - ); - } + factory Preferences.fromMap(Map<String, dynamic> map) { + return Preferences( + data: map, + ); + } - Map<String, dynamic> toMap() { - return { - "data": data, - }; - } + Map<String, dynamic> toMap() { + return { + "data": data, + }; + } - T convertTo<T>(T Function(Map) fromJson) => fromJson(data); -} + T convertTo<T>(T Function(Map) fromJson) => fromJson(data); +} \ No newline at end of file diff --git a/lib/src/models/provider.dart b/lib/src/models/provider.dart index 1a762f85..8a34b6fd 100644 --- a/lib/src/models/provider.dart +++ b/lib/src/models/provider.dart @@ -2,70 +2,62 @@ part of '../../models.dart'; /// Provider class Provider implements Model { - /// Provider ID. - final String $id; - - /// Provider creation time in ISO 8601 format. - final String $createdAt; - - /// Provider update date in ISO 8601 format. - final String $updatedAt; - - /// The name for the provider instance. - final String name; - - /// The name of the provider service. - final String provider; - - /// Is provider enabled? - final bool enabled; - - /// Type of provider. - final String type; - - /// Provider credentials. - final Map<String, dynamic> credentials; - - /// Provider options. - final Map<String, dynamic>? options; - - Provider({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.provider, - required this.enabled, - required this.type, - required this.credentials, - this.options, - }); - - factory Provider.fromMap(Map<String, dynamic> map) { - return Provider( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - provider: map['provider'].toString(), - enabled: map['enabled'], - type: map['type'].toString(), - credentials: map['credentials'], - options: map['options'], - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "provider": provider, - "enabled": enabled, - "type": type, - "credentials": credentials, - "options": options, - }; - } -} + /// Provider ID. + final String $id; + /// Provider creation time in ISO 8601 format. + final String $createdAt; + /// Provider update date in ISO 8601 format. + final String $updatedAt; + /// The name for the provider instance. + final String name; + /// The name of the provider service. + final String provider; + /// Is provider enabled? + final bool enabled; + /// Type of provider. + final String type; + /// Provider credentials. + final Map<String, dynamic> credentials; + /// Provider options. + final Map<String, dynamic>? options; + + Provider({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.provider, + required this.enabled, + required this.type, + required this.credentials, + this.options, + }); + + factory Provider.fromMap(Map<String, dynamic> map) { + return Provider( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + provider: map['provider'].toString(), + enabled: map['enabled'], + type: map['type'].toString(), + credentials: map['credentials'], + options: map['options'], + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "provider": provider, + "enabled": enabled, + "type": type, + "credentials": credentials, + "options": options, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/provider_list.dart b/lib/src/models/provider_list.dart index a4f980f6..12779186 100644 --- a/lib/src/models/provider_list.dart +++ b/lib/src/models/provider_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Provider list class ProviderList implements Model { - /// Total number of providers documents that matched your query. - final int total; + /// Total number of providers documents that matched your query. + final int total; + /// List of providers. + final List<Provider> providers; - /// List of providers. - final List<Provider> providers; + ProviderList({ + required this.total, + required this.providers, + }); - ProviderList({ - required this.total, - required this.providers, - }); + factory ProviderList.fromMap(Map<String, dynamic> map) { + return ProviderList( + total: map['total'], + providers: List<Provider>.from(map['providers'].map((p) => Provider.fromMap(p))), + ); + } - factory ProviderList.fromMap(Map<String, dynamic> map) { - return ProviderList( - total: map['total'], - providers: - List<Provider>.from(map['providers'].map((p) => Provider.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "providers": providers.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "providers": providers.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/runtime.dart b/lib/src/models/runtime.dart index 249690f8..c0a078db 100644 --- a/lib/src/models/runtime.dart +++ b/lib/src/models/runtime.dart @@ -2,64 +2,57 @@ part of '../../models.dart'; /// Runtime class Runtime implements Model { - /// Runtime ID. - final String $id; - - /// Parent runtime key. - final String key; - - /// Runtime Name. - final String name; - - /// Runtime version. - final String version; - - /// Base Docker image used to build the runtime. - final String base; - - /// Image name of Docker Hub. - final String image; - - /// Name of the logo image. - final String logo; - - /// List of supported architectures. - final List<String> supports; - - Runtime({ - required this.$id, - required this.key, - required this.name, - required this.version, - required this.base, - required this.image, - required this.logo, - required this.supports, - }); - - factory Runtime.fromMap(Map<String, dynamic> map) { - return Runtime( - $id: map['\$id'].toString(), - key: map['key'].toString(), - name: map['name'].toString(), - version: map['version'].toString(), - base: map['base'].toString(), - image: map['image'].toString(), - logo: map['logo'].toString(), - supports: map['supports'] ?? [], - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "key": key, - "name": name, - "version": version, - "base": base, - "image": image, - "logo": logo, - "supports": supports, - }; - } -} + /// Runtime ID. + final String $id; + /// Parent runtime key. + final String key; + /// Runtime Name. + final String name; + /// Runtime version. + final String version; + /// Base Docker image used to build the runtime. + final String base; + /// Image name of Docker Hub. + final String image; + /// Name of the logo image. + final String logo; + /// List of supported architectures. + final List<String> supports; + + Runtime({ + required this.$id, + required this.key, + required this.name, + required this.version, + required this.base, + required this.image, + required this.logo, + required this.supports, + }); + + factory Runtime.fromMap(Map<String, dynamic> map) { + return Runtime( + $id: map['\$id'].toString(), + key: map['key'].toString(), + name: map['name'].toString(), + version: map['version'].toString(), + base: map['base'].toString(), + image: map['image'].toString(), + logo: map['logo'].toString(), + supports: List<String>.from(map['supports']?.map((x) => x.toString()) ?? []), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "key": key, + "name": name, + "version": version, + "base": base, + "image": image, + "logo": logo, + "supports": supports, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/runtime_list.dart b/lib/src/models/runtime_list.dart index 7845cd8b..fa997a66 100644 --- a/lib/src/models/runtime_list.dart +++ b/lib/src/models/runtime_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Runtimes List class RuntimeList implements Model { - /// Total number of runtimes documents that matched your query. - final int total; + /// Total number of runtimes documents that matched your query. + final int total; + /// List of runtimes. + final List<Runtime> runtimes; - /// List of runtimes. - final List<Runtime> runtimes; + RuntimeList({ + required this.total, + required this.runtimes, + }); - RuntimeList({ - required this.total, - required this.runtimes, - }); + factory RuntimeList.fromMap(Map<String, dynamic> map) { + return RuntimeList( + total: map['total'], + runtimes: List<Runtime>.from(map['runtimes'].map((p) => Runtime.fromMap(p))), + ); + } - factory RuntimeList.fromMap(Map<String, dynamic> map) { - return RuntimeList( - total: map['total'], - runtimes: - List<Runtime>.from(map['runtimes'].map((p) => Runtime.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "runtimes": runtimes.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "runtimes": runtimes.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/session.dart b/lib/src/models/session.dart index 11732bd1..243bc2f8 100644 --- a/lib/src/models/session.dart +++ b/lib/src/models/session.dart @@ -2,190 +2,162 @@ part of '../../models.dart'; /// Session class Session implements Model { - /// Session ID. - final String $id; - - /// Session creation date in ISO 8601 format. - final String $createdAt; - - /// Session update date in ISO 8601 format. - final String $updatedAt; - - /// User ID. - final String userId; - - /// Session expiration date in ISO 8601 format. - final String expire; - - /// Session Provider. - final String provider; - - /// Session Provider User ID. - final String providerUid; - - /// Session Provider Access Token. - final String providerAccessToken; - - /// The date of when the access token expires in ISO 8601 format. - final String providerAccessTokenExpiry; - - /// Session Provider Refresh Token. - final String providerRefreshToken; - - /// IP in use when the session was created. - final String ip; - - /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). - final String osCode; - - /// Operating system name. - final String osName; - - /// Operating system version. - final String osVersion; - - /// Client type. - final String clientType; - - /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). - final String clientCode; - - /// Client name. - final String clientName; - - /// Client version. - final String clientVersion; - - /// Client engine name. - final String clientEngine; - - /// Client engine name. - final String clientEngineVersion; - - /// Device name. - final String deviceName; - - /// Device brand name. - final String deviceBrand; - - /// Device model name. - final String deviceModel; - - /// Country two-character ISO 3166-1 alpha code. - final String countryCode; - - /// Country name. - final String countryName; - - /// Returns true if this the current user session. - final bool current; - - /// Returns a list of active session factors. - final List<String> factors; - - /// Secret used to authenticate the user. Only included if the request was made with an API key - final String secret; - - /// Most recent date in ISO 8601 format when the session successfully passed MFA challenge. - final String mfaUpdatedAt; - - Session({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.userId, - required this.expire, - required this.provider, - required this.providerUid, - required this.providerAccessToken, - required this.providerAccessTokenExpiry, - required this.providerRefreshToken, - required this.ip, - required this.osCode, - required this.osName, - required this.osVersion, - required this.clientType, - required this.clientCode, - required this.clientName, - required this.clientVersion, - required this.clientEngine, - required this.clientEngineVersion, - required this.deviceName, - required this.deviceBrand, - required this.deviceModel, - required this.countryCode, - required this.countryName, - required this.current, - required this.factors, - required this.secret, - required this.mfaUpdatedAt, - }); - - factory Session.fromMap(Map<String, dynamic> map) { - return Session( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - userId: map['userId'].toString(), - expire: map['expire'].toString(), - provider: map['provider'].toString(), - providerUid: map['providerUid'].toString(), - providerAccessToken: map['providerAccessToken'].toString(), - providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), - providerRefreshToken: map['providerRefreshToken'].toString(), - ip: map['ip'].toString(), - osCode: map['osCode'].toString(), - osName: map['osName'].toString(), - osVersion: map['osVersion'].toString(), - clientType: map['clientType'].toString(), - clientCode: map['clientCode'].toString(), - clientName: map['clientName'].toString(), - clientVersion: map['clientVersion'].toString(), - clientEngine: map['clientEngine'].toString(), - clientEngineVersion: map['clientEngineVersion'].toString(), - deviceName: map['deviceName'].toString(), - deviceBrand: map['deviceBrand'].toString(), - deviceModel: map['deviceModel'].toString(), - countryCode: map['countryCode'].toString(), - countryName: map['countryName'].toString(), - current: map['current'], - factors: map['factors'] ?? [], - secret: map['secret'].toString(), - mfaUpdatedAt: map['mfaUpdatedAt'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "userId": userId, - "expire": expire, - "provider": provider, - "providerUid": providerUid, - "providerAccessToken": providerAccessToken, - "providerAccessTokenExpiry": providerAccessTokenExpiry, - "providerRefreshToken": providerRefreshToken, - "ip": ip, - "osCode": osCode, - "osName": osName, - "osVersion": osVersion, - "clientType": clientType, - "clientCode": clientCode, - "clientName": clientName, - "clientVersion": clientVersion, - "clientEngine": clientEngine, - "clientEngineVersion": clientEngineVersion, - "deviceName": deviceName, - "deviceBrand": deviceBrand, - "deviceModel": deviceModel, - "countryCode": countryCode, - "countryName": countryName, - "current": current, - "factors": factors, - "secret": secret, - "mfaUpdatedAt": mfaUpdatedAt, - }; - } -} + /// Session ID. + final String $id; + /// Session creation date in ISO 8601 format. + final String $createdAt; + /// Session update date in ISO 8601 format. + final String $updatedAt; + /// User ID. + final String userId; + /// Session expiration date in ISO 8601 format. + final String expire; + /// Session Provider. + final String provider; + /// Session Provider User ID. + final String providerUid; + /// Session Provider Access Token. + final String providerAccessToken; + /// The date of when the access token expires in ISO 8601 format. + final String providerAccessTokenExpiry; + /// Session Provider Refresh Token. + final String providerRefreshToken; + /// IP in use when the session was created. + final String ip; + /// Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). + final String osCode; + /// Operating system name. + final String osName; + /// Operating system version. + final String osVersion; + /// Client type. + final String clientType; + /// Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json). + final String clientCode; + /// Client name. + final String clientName; + /// Client version. + final String clientVersion; + /// Client engine name. + final String clientEngine; + /// Client engine name. + final String clientEngineVersion; + /// Device name. + final String deviceName; + /// Device brand name. + final String deviceBrand; + /// Device model name. + final String deviceModel; + /// Country two-character ISO 3166-1 alpha code. + final String countryCode; + /// Country name. + final String countryName; + /// Returns true if this the current user session. + final bool current; + /// Returns a list of active session factors. + final List<String> factors; + /// Secret used to authenticate the user. Only included if the request was made with an API key + final String secret; + /// Most recent date in ISO 8601 format when the session successfully passed MFA challenge. + final String mfaUpdatedAt; + + Session({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.userId, + required this.expire, + required this.provider, + required this.providerUid, + required this.providerAccessToken, + required this.providerAccessTokenExpiry, + required this.providerRefreshToken, + required this.ip, + required this.osCode, + required this.osName, + required this.osVersion, + required this.clientType, + required this.clientCode, + required this.clientName, + required this.clientVersion, + required this.clientEngine, + required this.clientEngineVersion, + required this.deviceName, + required this.deviceBrand, + required this.deviceModel, + required this.countryCode, + required this.countryName, + required this.current, + required this.factors, + required this.secret, + required this.mfaUpdatedAt, + }); + + factory Session.fromMap(Map<String, dynamic> map) { + return Session( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + userId: map['userId'].toString(), + expire: map['expire'].toString(), + provider: map['provider'].toString(), + providerUid: map['providerUid'].toString(), + providerAccessToken: map['providerAccessToken'].toString(), + providerAccessTokenExpiry: map['providerAccessTokenExpiry'].toString(), + providerRefreshToken: map['providerRefreshToken'].toString(), + ip: map['ip'].toString(), + osCode: map['osCode'].toString(), + osName: map['osName'].toString(), + osVersion: map['osVersion'].toString(), + clientType: map['clientType'].toString(), + clientCode: map['clientCode'].toString(), + clientName: map['clientName'].toString(), + clientVersion: map['clientVersion'].toString(), + clientEngine: map['clientEngine'].toString(), + clientEngineVersion: map['clientEngineVersion'].toString(), + deviceName: map['deviceName'].toString(), + deviceBrand: map['deviceBrand'].toString(), + deviceModel: map['deviceModel'].toString(), + countryCode: map['countryCode'].toString(), + countryName: map['countryName'].toString(), + current: map['current'], + factors: List<String>.from(map['factors']?.map((x) => x.toString()) ?? []), + secret: map['secret'].toString(), + mfaUpdatedAt: map['mfaUpdatedAt'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "userId": userId, + "expire": expire, + "provider": provider, + "providerUid": providerUid, + "providerAccessToken": providerAccessToken, + "providerAccessTokenExpiry": providerAccessTokenExpiry, + "providerRefreshToken": providerRefreshToken, + "ip": ip, + "osCode": osCode, + "osName": osName, + "osVersion": osVersion, + "clientType": clientType, + "clientCode": clientCode, + "clientName": clientName, + "clientVersion": clientVersion, + "clientEngine": clientEngine, + "clientEngineVersion": clientEngineVersion, + "deviceName": deviceName, + "deviceBrand": deviceBrand, + "deviceModel": deviceModel, + "countryCode": countryCode, + "countryName": countryName, + "current": current, + "factors": factors, + "secret": secret, + "mfaUpdatedAt": mfaUpdatedAt, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/session_list.dart b/lib/src/models/session_list.dart index e4739c9b..341ed406 100644 --- a/lib/src/models/session_list.dart +++ b/lib/src/models/session_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Sessions List class SessionList implements Model { - /// Total number of sessions documents that matched your query. - final int total; + /// Total number of sessions documents that matched your query. + final int total; + /// List of sessions. + final List<Session> sessions; - /// List of sessions. - final List<Session> sessions; + SessionList({ + required this.total, + required this.sessions, + }); - SessionList({ - required this.total, - required this.sessions, - }); + factory SessionList.fromMap(Map<String, dynamic> map) { + return SessionList( + total: map['total'], + sessions: List<Session>.from(map['sessions'].map((p) => Session.fromMap(p))), + ); + } - factory SessionList.fromMap(Map<String, dynamic> map) { - return SessionList( - total: map['total'], - sessions: - List<Session>.from(map['sessions'].map((p) => Session.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "sessions": sessions.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "sessions": sessions.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/specification.dart b/lib/src/models/specification.dart index cf2fb838..e0cb8210 100644 --- a/lib/src/models/specification.dart +++ b/lib/src/models/specification.dart @@ -2,40 +2,37 @@ part of '../../models.dart'; /// Specification class Specification implements Model { - /// Memory size in MB. - final int memory; + /// Memory size in MB. + final int memory; + /// Number of CPUs. + final double cpus; + /// Is size enabled. + final bool enabled; + /// Size slug. + final String slug; - /// Number of CPUs. - final double cpus; + Specification({ + required this.memory, + required this.cpus, + required this.enabled, + required this.slug, + }); - /// Is size enabled. - final bool enabled; + factory Specification.fromMap(Map<String, dynamic> map) { + return Specification( + memory: map['memory'], + cpus: map['cpus'].toDouble(), + enabled: map['enabled'], + slug: map['slug'].toString(), + ); + } - /// Size slug. - final String slug; - - Specification({ - required this.memory, - required this.cpus, - required this.enabled, - required this.slug, - }); - - factory Specification.fromMap(Map<String, dynamic> map) { - return Specification( - memory: map['memory'], - cpus: map['cpus'].toDouble(), - enabled: map['enabled'], - slug: map['slug'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "memory": memory, - "cpus": cpus, - "enabled": enabled, - "slug": slug, - }; - } -} + Map<String, dynamic> toMap() { + return { + "memory": memory, + "cpus": cpus, + "enabled": enabled, + "slug": slug, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/specification_list.dart b/lib/src/models/specification_list.dart index c66d5ac3..38baca4f 100644 --- a/lib/src/models/specification_list.dart +++ b/lib/src/models/specification_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Specifications List class SpecificationList implements Model { - /// Total number of specifications documents that matched your query. - final int total; + /// Total number of specifications documents that matched your query. + final int total; + /// List of specifications. + final List<Specification> specifications; - /// List of specifications. - final List<Specification> specifications; + SpecificationList({ + required this.total, + required this.specifications, + }); - SpecificationList({ - required this.total, - required this.specifications, - }); + factory SpecificationList.fromMap(Map<String, dynamic> map) { + return SpecificationList( + total: map['total'], + specifications: List<Specification>.from(map['specifications'].map((p) => Specification.fromMap(p))), + ); + } - factory SpecificationList.fromMap(Map<String, dynamic> map) { - return SpecificationList( - total: map['total'], - specifications: List<Specification>.from( - map['specifications'].map((p) => Specification.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "specifications": specifications.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "specifications": specifications.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/subscriber.dart b/lib/src/models/subscriber.dart index 0c926297..90cb82ef 100644 --- a/lib/src/models/subscriber.dart +++ b/lib/src/models/subscriber.dart @@ -2,70 +2,62 @@ part of '../../models.dart'; /// Subscriber class Subscriber implements Model { - /// Subscriber ID. - final String $id; - - /// Subscriber creation time in ISO 8601 format. - final String $createdAt; - - /// Subscriber update date in ISO 8601 format. - final String $updatedAt; - - /// Target ID. - final String targetId; - - /// Target. - final Target target; - - /// Topic ID. - final String userId; - - /// User Name. - final String userName; - - /// Topic ID. - final String topicId; - - /// The target provider type. Can be one of the following: `email`, `sms` or `push`. - final String providerType; - - Subscriber({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.targetId, - required this.target, - required this.userId, - required this.userName, - required this.topicId, - required this.providerType, - }); - - factory Subscriber.fromMap(Map<String, dynamic> map) { - return Subscriber( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - targetId: map['targetId'].toString(), - target: Target.fromMap(map['target']), - userId: map['userId'].toString(), - userName: map['userName'].toString(), - topicId: map['topicId'].toString(), - providerType: map['providerType'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "targetId": targetId, - "target": target.toMap(), - "userId": userId, - "userName": userName, - "topicId": topicId, - "providerType": providerType, - }; - } -} + /// Subscriber ID. + final String $id; + /// Subscriber creation time in ISO 8601 format. + final String $createdAt; + /// Subscriber update date in ISO 8601 format. + final String $updatedAt; + /// Target ID. + final String targetId; + /// Target. + final Target target; + /// Topic ID. + final String userId; + /// User Name. + final String userName; + /// Topic ID. + final String topicId; + /// The target provider type. Can be one of the following: `email`, `sms` or `push`. + final String providerType; + + Subscriber({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.targetId, + required this.target, + required this.userId, + required this.userName, + required this.topicId, + required this.providerType, + }); + + factory Subscriber.fromMap(Map<String, dynamic> map) { + return Subscriber( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + targetId: map['targetId'].toString(), + target: Target.fromMap(map['target']), + userId: map['userId'].toString(), + userName: map['userName'].toString(), + topicId: map['topicId'].toString(), + providerType: map['providerType'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "targetId": targetId, + "target": target.toMap(), + "userId": userId, + "userName": userName, + "topicId": topicId, + "providerType": providerType, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/subscriber_list.dart b/lib/src/models/subscriber_list.dart index 14577a7e..8001dd18 100644 --- a/lib/src/models/subscriber_list.dart +++ b/lib/src/models/subscriber_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Subscriber list class SubscriberList implements Model { - /// Total number of subscribers documents that matched your query. - final int total; + /// Total number of subscribers documents that matched your query. + final int total; + /// List of subscribers. + final List<Subscriber> subscribers; - /// List of subscribers. - final List<Subscriber> subscribers; + SubscriberList({ + required this.total, + required this.subscribers, + }); - SubscriberList({ - required this.total, - required this.subscribers, - }); + factory SubscriberList.fromMap(Map<String, dynamic> map) { + return SubscriberList( + total: map['total'], + subscribers: List<Subscriber>.from(map['subscribers'].map((p) => Subscriber.fromMap(p))), + ); + } - factory SubscriberList.fromMap(Map<String, dynamic> map) { - return SubscriberList( - total: map['total'], - subscribers: List<Subscriber>.from( - map['subscribers'].map((p) => Subscriber.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "subscribers": subscribers.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "subscribers": subscribers.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/target.dart b/lib/src/models/target.dart index 4be8b545..348c0620 100644 --- a/lib/src/models/target.dart +++ b/lib/src/models/target.dart @@ -2,70 +2,62 @@ part of '../../models.dart'; /// Target class Target implements Model { - /// Target ID. - final String $id; - - /// Target creation time in ISO 8601 format. - final String $createdAt; - - /// Target update date in ISO 8601 format. - final String $updatedAt; - - /// Target Name. - final String name; - - /// User ID. - final String userId; - - /// Provider ID. - final String? providerId; - - /// The target provider type. Can be one of the following: `email`, `sms` or `push`. - final String providerType; - - /// The target identifier. - final String identifier; - - /// Is the target expired. - final bool expired; - - Target({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.userId, - this.providerId, - required this.providerType, - required this.identifier, - required this.expired, - }); - - factory Target.fromMap(Map<String, dynamic> map) { - return Target( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - userId: map['userId'].toString(), - providerId: map['providerId']?.toString(), - providerType: map['providerType'].toString(), - identifier: map['identifier'].toString(), - expired: map['expired'], - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "userId": userId, - "providerId": providerId, - "providerType": providerType, - "identifier": identifier, - "expired": expired, - }; - } -} + /// Target ID. + final String $id; + /// Target creation time in ISO 8601 format. + final String $createdAt; + /// Target update date in ISO 8601 format. + final String $updatedAt; + /// Target Name. + final String name; + /// User ID. + final String userId; + /// Provider ID. + final String? providerId; + /// The target provider type. Can be one of the following: `email`, `sms` or `push`. + final String providerType; + /// The target identifier. + final String identifier; + /// Is the target expired. + final bool expired; + + Target({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.userId, + this.providerId, + required this.providerType, + required this.identifier, + required this.expired, + }); + + factory Target.fromMap(Map<String, dynamic> map) { + return Target( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + userId: map['userId'].toString(), + providerId: map['providerId']?.toString(), + providerType: map['providerType'].toString(), + identifier: map['identifier'].toString(), + expired: map['expired'], + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "userId": userId, + "providerId": providerId, + "providerType": providerType, + "identifier": identifier, + "expired": expired, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/target_list.dart b/lib/src/models/target_list.dart index 8b0ef79d..47864ab5 100644 --- a/lib/src/models/target_list.dart +++ b/lib/src/models/target_list.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Target list class TargetList implements Model { - /// Total number of targets documents that matched your query. - final int total; + /// Total number of targets documents that matched your query. + final int total; + /// List of targets. + final List<Target> targets; - /// List of targets. - final List<Target> targets; + TargetList({ + required this.total, + required this.targets, + }); - TargetList({ - required this.total, - required this.targets, - }); + factory TargetList.fromMap(Map<String, dynamic> map) { + return TargetList( + total: map['total'], + targets: List<Target>.from(map['targets'].map((p) => Target.fromMap(p))), + ); + } - factory TargetList.fromMap(Map<String, dynamic> map) { - return TargetList( - total: map['total'], - targets: List<Target>.from(map['targets'].map((p) => Target.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "targets": targets.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "targets": targets.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/team.dart b/lib/src/models/team.dart index 43df33a8..5aebd588 100644 --- a/lib/src/models/team.dart +++ b/lib/src/models/team.dart @@ -2,52 +2,47 @@ part of '../../models.dart'; /// Team class Team implements Model { - /// Team ID. - final String $id; - - /// Team creation date in ISO 8601 format. - final String $createdAt; - - /// Team update date in ISO 8601 format. - final String $updatedAt; - - /// Team name. - final String name; - - /// Total number of team members. - final int total; - - /// Team preferences as a key-value object - final Preferences prefs; - - Team({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.total, - required this.prefs, - }); - - factory Team.fromMap(Map<String, dynamic> map) { - return Team( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - total: map['total'], - prefs: Preferences.fromMap(map['prefs']), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "total": total, - "prefs": prefs.toMap(), - }; - } -} + /// Team ID. + final String $id; + /// Team creation date in ISO 8601 format. + final String $createdAt; + /// Team update date in ISO 8601 format. + final String $updatedAt; + /// Team name. + final String name; + /// Total number of team members. + final int total; + /// Team preferences as a key-value object + final Preferences prefs; + + Team({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.total, + required this.prefs, + }); + + factory Team.fromMap(Map<String, dynamic> map) { + return Team( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + total: map['total'], + prefs: Preferences.fromMap(map['prefs']), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "total": total, + "prefs": prefs.toMap(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/team_list.dart b/lib/src/models/team_list.dart index 817e944f..2ae10d8b 100644 --- a/lib/src/models/team_list.dart +++ b/lib/src/models/team_list.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Teams List class TeamList implements Model { - /// Total number of teams documents that matched your query. - final int total; + /// Total number of teams documents that matched your query. + final int total; + /// List of teams. + final List<Team> teams; - /// List of teams. - final List<Team> teams; + TeamList({ + required this.total, + required this.teams, + }); - TeamList({ - required this.total, - required this.teams, - }); + factory TeamList.fromMap(Map<String, dynamic> map) { + return TeamList( + total: map['total'], + teams: List<Team>.from(map['teams'].map((p) => Team.fromMap(p))), + ); + } - factory TeamList.fromMap(Map<String, dynamic> map) { - return TeamList( - total: map['total'], - teams: List<Team>.from(map['teams'].map((p) => Team.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "teams": teams.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "teams": teams.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/token.dart b/lib/src/models/token.dart index 35115467..7c33c4d4 100644 --- a/lib/src/models/token.dart +++ b/lib/src/models/token.dart @@ -2,52 +2,47 @@ part of '../../models.dart'; /// Token class Token implements Model { - /// Token ID. - final String $id; - - /// Token creation date in ISO 8601 format. - final String $createdAt; - - /// User ID. - final String userId; - - /// Token secret key. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. - final String secret; - - /// Token expiration date in ISO 8601 format. - final String expire; - - /// Security phrase of a token. Empty if security phrase was not requested when creating a token. It includes randomly generated phrase which is also sent in the external resource such as email. - final String phrase; - - Token({ - required this.$id, - required this.$createdAt, - required this.userId, - required this.secret, - required this.expire, - required this.phrase, - }); - - factory Token.fromMap(Map<String, dynamic> map) { - return Token( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - userId: map['userId'].toString(), - secret: map['secret'].toString(), - expire: map['expire'].toString(), - phrase: map['phrase'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "userId": userId, - "secret": secret, - "expire": expire, - "phrase": phrase, - }; - } -} + /// Token ID. + final String $id; + /// Token creation date in ISO 8601 format. + final String $createdAt; + /// User ID. + final String userId; + /// Token secret key. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. + final String secret; + /// Token expiration date in ISO 8601 format. + final String expire; + /// Security phrase of a token. Empty if security phrase was not requested when creating a token. It includes randomly generated phrase which is also sent in the external resource such as email. + final String phrase; + + Token({ + required this.$id, + required this.$createdAt, + required this.userId, + required this.secret, + required this.expire, + required this.phrase, + }); + + factory Token.fromMap(Map<String, dynamic> map) { + return Token( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + userId: map['userId'].toString(), + secret: map['secret'].toString(), + expire: map['expire'].toString(), + phrase: map['phrase'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "userId": userId, + "secret": secret, + "expire": expire, + "phrase": phrase, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/topic.dart b/lib/src/models/topic.dart index 9714abba..cbca0436 100644 --- a/lib/src/models/topic.dart +++ b/lib/src/models/topic.dart @@ -2,64 +2,57 @@ part of '../../models.dart'; /// Topic class Topic implements Model { - /// Topic ID. - final String $id; - - /// Topic creation time in ISO 8601 format. - final String $createdAt; - - /// Topic update date in ISO 8601 format. - final String $updatedAt; - - /// The name of the topic. - final String name; - - /// Total count of email subscribers subscribed to the topic. - final int emailTotal; - - /// Total count of SMS subscribers subscribed to the topic. - final int smsTotal; - - /// Total count of push subscribers subscribed to the topic. - final int pushTotal; - - /// Subscribe permissions. - final List<String> subscribe; - - Topic({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - required this.emailTotal, - required this.smsTotal, - required this.pushTotal, - required this.subscribe, - }); - - factory Topic.fromMap(Map<String, dynamic> map) { - return Topic( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - emailTotal: map['emailTotal'], - smsTotal: map['smsTotal'], - pushTotal: map['pushTotal'], - subscribe: map['subscribe'] ?? [], - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "emailTotal": emailTotal, - "smsTotal": smsTotal, - "pushTotal": pushTotal, - "subscribe": subscribe, - }; - } -} + /// Topic ID. + final String $id; + /// Topic creation time in ISO 8601 format. + final String $createdAt; + /// Topic update date in ISO 8601 format. + final String $updatedAt; + /// The name of the topic. + final String name; + /// Total count of email subscribers subscribed to the topic. + final int emailTotal; + /// Total count of SMS subscribers subscribed to the topic. + final int smsTotal; + /// Total count of push subscribers subscribed to the topic. + final int pushTotal; + /// Subscribe permissions. + final List<String> subscribe; + + Topic({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.emailTotal, + required this.smsTotal, + required this.pushTotal, + required this.subscribe, + }); + + factory Topic.fromMap(Map<String, dynamic> map) { + return Topic( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + emailTotal: map['emailTotal'], + smsTotal: map['smsTotal'], + pushTotal: map['pushTotal'], + subscribe: List<String>.from(map['subscribe']?.map((x) => x.toString()) ?? []), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "emailTotal": emailTotal, + "smsTotal": smsTotal, + "pushTotal": pushTotal, + "subscribe": subscribe, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/topic_list.dart b/lib/src/models/topic_list.dart index be78a61f..44a22f33 100644 --- a/lib/src/models/topic_list.dart +++ b/lib/src/models/topic_list.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Topic list class TopicList implements Model { - /// Total number of topics documents that matched your query. - final int total; + /// Total number of topics documents that matched your query. + final int total; + /// List of topics. + final List<Topic> topics; - /// List of topics. - final List<Topic> topics; + TopicList({ + required this.total, + required this.topics, + }); - TopicList({ - required this.total, - required this.topics, - }); + factory TopicList.fromMap(Map<String, dynamic> map) { + return TopicList( + total: map['total'], + topics: List<Topic>.from(map['topics'].map((p) => Topic.fromMap(p))), + ); + } - factory TopicList.fromMap(Map<String, dynamic> map) { - return TopicList( - total: map['total'], - topics: List<Topic>.from(map['topics'].map((p) => Topic.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "topics": topics.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "topics": topics.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/user.dart b/lib/src/models/user.dart index e5942793..e0e4e9df 100644 --- a/lib/src/models/user.dart +++ b/lib/src/models/user.dart @@ -2,130 +2,112 @@ part of '../../models.dart'; /// User class User implements Model { - /// User ID. - final String $id; - - /// User creation date in ISO 8601 format. - final String $createdAt; - - /// User update date in ISO 8601 format. - final String $updatedAt; - - /// User name. - final String name; - - /// Hashed user password. - final String? password; - - /// Password hashing algorithm. - final String? hash; - - /// Password hashing algorithm configuration. - final Map? hashOptions; - - /// User registration date in ISO 8601 format. - final String registration; - - /// User status. Pass `true` for enabled and `false` for disabled. - final bool status; - - /// Labels for the user. - final List<String> labels; - - /// Password update time in ISO 8601 format. - final String passwordUpdate; - - /// User email address. - final String email; - - /// User phone number in E.164 format. - final String phone; - - /// Email verification status. - final bool emailVerification; - - /// Phone verification status. - final bool phoneVerification; - - /// Multi factor authentication status. - final bool mfa; - - /// User preferences as a key-value object - final Preferences prefs; - - /// A user-owned message receiver. A single user may have multiple e.g. emails, phones, and a browser. Each target is registered with a single provider. - final List<Target> targets; - - /// Most recent access date in ISO 8601 format. This attribute is only updated again after 24 hours. - final String accessedAt; - - User({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.name, - this.password, - this.hash, - this.hashOptions, - required this.registration, - required this.status, - required this.labels, - required this.passwordUpdate, - required this.email, - required this.phone, - required this.emailVerification, - required this.phoneVerification, - required this.mfa, - required this.prefs, - required this.targets, - required this.accessedAt, - }); - - factory User.fromMap(Map<String, dynamic> map) { - return User( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - name: map['name'].toString(), - password: map['password']?.toString(), - hash: map['hash']?.toString(), - hashOptions: map['hashOptions'], - registration: map['registration'].toString(), - status: map['status'], - labels: map['labels'] ?? [], - passwordUpdate: map['passwordUpdate'].toString(), - email: map['email'].toString(), - phone: map['phone'].toString(), - emailVerification: map['emailVerification'], - phoneVerification: map['phoneVerification'], - mfa: map['mfa'], - prefs: Preferences.fromMap(map['prefs']), - targets: List<Target>.from(map['targets'].map((p) => Target.fromMap(p))), - accessedAt: map['accessedAt'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "name": name, - "password": password, - "hash": hash, - "hashOptions": hashOptions, - "registration": registration, - "status": status, - "labels": labels, - "passwordUpdate": passwordUpdate, - "email": email, - "phone": phone, - "emailVerification": emailVerification, - "phoneVerification": phoneVerification, - "mfa": mfa, - "prefs": prefs.toMap(), - "targets": targets.map((p) => p.toMap()).toList(), - "accessedAt": accessedAt, - }; - } -} + /// User ID. + final String $id; + /// User creation date in ISO 8601 format. + final String $createdAt; + /// User update date in ISO 8601 format. + final String $updatedAt; + /// User name. + final String name; + /// Hashed user password. + final String? password; + /// Password hashing algorithm. + final String? hash; + /// Password hashing algorithm configuration. + final Map? hashOptions; + /// User registration date in ISO 8601 format. + final String registration; + /// User status. Pass `true` for enabled and `false` for disabled. + final bool status; + /// Labels for the user. + final List<String> labels; + /// Password update time in ISO 8601 format. + final String passwordUpdate; + /// User email address. + final String email; + /// User phone number in E.164 format. + final String phone; + /// Email verification status. + final bool emailVerification; + /// Phone verification status. + final bool phoneVerification; + /// Multi factor authentication status. + final bool mfa; + /// User preferences as a key-value object + final Preferences prefs; + /// A user-owned message receiver. A single user may have multiple e.g. emails, phones, and a browser. Each target is registered with a single provider. + final List<Target> targets; + /// Most recent access date in ISO 8601 format. This attribute is only updated again after 24 hours. + final String accessedAt; + + User({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + this.password, + this.hash, + this.hashOptions, + required this.registration, + required this.status, + required this.labels, + required this.passwordUpdate, + required this.email, + required this.phone, + required this.emailVerification, + required this.phoneVerification, + required this.mfa, + required this.prefs, + required this.targets, + required this.accessedAt, + }); + + factory User.fromMap(Map<String, dynamic> map) { + return User( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + password: map['password']?.toString(), + hash: map['hash']?.toString(), + hashOptions: map['hashOptions'], + registration: map['registration'].toString(), + status: map['status'], + labels: List<String>.from(map['labels']?.map((x) => x.toString()) ?? []), + passwordUpdate: map['passwordUpdate'].toString(), + email: map['email'].toString(), + phone: map['phone'].toString(), + emailVerification: map['emailVerification'], + phoneVerification: map['phoneVerification'], + mfa: map['mfa'], + prefs: Preferences.fromMap(map['prefs']), + targets: List<Target>.from(map['targets'].map((p) => Target.fromMap(p))), + accessedAt: map['accessedAt'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "password": password, + "hash": hash, + "hashOptions": hashOptions, + "registration": registration, + "status": status, + "labels": labels, + "passwordUpdate": passwordUpdate, + "email": email, + "phone": phone, + "emailVerification": emailVerification, + "phoneVerification": phoneVerification, + "mfa": mfa, + "prefs": prefs.toMap(), + "targets": targets.map((p) => p.toMap()).toList(), + "accessedAt": accessedAt, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/user_list.dart b/lib/src/models/user_list.dart index a9a78f63..ac674f14 100644 --- a/lib/src/models/user_list.dart +++ b/lib/src/models/user_list.dart @@ -2,28 +2,27 @@ part of '../../models.dart'; /// Users List class UserList implements Model { - /// Total number of users documents that matched your query. - final int total; + /// Total number of users documents that matched your query. + final int total; + /// List of users. + final List<User> users; - /// List of users. - final List<User> users; + UserList({ + required this.total, + required this.users, + }); - UserList({ - required this.total, - required this.users, - }); + factory UserList.fromMap(Map<String, dynamic> map) { + return UserList( + total: map['total'], + users: List<User>.from(map['users'].map((p) => User.fromMap(p))), + ); + } - factory UserList.fromMap(Map<String, dynamic> map) { - return UserList( - total: map['total'], - users: List<User>.from(map['users'].map((p) => User.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "users": users.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "users": users.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/lib/src/models/variable.dart b/lib/src/models/variable.dart index a233010a..b1bc1f67 100644 --- a/lib/src/models/variable.dart +++ b/lib/src/models/variable.dart @@ -2,58 +2,52 @@ part of '../../models.dart'; /// Variable class Variable implements Model { - /// Variable ID. - final String $id; - - /// Variable creation date in ISO 8601 format. - final String $createdAt; - - /// Variable creation date in ISO 8601 format. - final String $updatedAt; - - /// Variable key. - final String key; - - /// Variable value. - final String value; - - /// Service to which the variable belongs. Possible values are "project", "function" - final String resourceType; - - /// ID of resource to which the variable belongs. If resourceType is "project", it is empty. If resourceType is "function", it is ID of the function. - final String resourceId; - - Variable({ - required this.$id, - required this.$createdAt, - required this.$updatedAt, - required this.key, - required this.value, - required this.resourceType, - required this.resourceId, - }); - - factory Variable.fromMap(Map<String, dynamic> map) { - return Variable( - $id: map['\$id'].toString(), - $createdAt: map['\$createdAt'].toString(), - $updatedAt: map['\$updatedAt'].toString(), - key: map['key'].toString(), - value: map['value'].toString(), - resourceType: map['resourceType'].toString(), - resourceId: map['resourceId'].toString(), - ); - } - - Map<String, dynamic> toMap() { - return { - "\$id": $id, - "\$createdAt": $createdAt, - "\$updatedAt": $updatedAt, - "key": key, - "value": value, - "resourceType": resourceType, - "resourceId": resourceId, - }; - } -} + /// Variable ID. + final String $id; + /// Variable creation date in ISO 8601 format. + final String $createdAt; + /// Variable creation date in ISO 8601 format. + final String $updatedAt; + /// Variable key. + final String key; + /// Variable value. + final String value; + /// Service to which the variable belongs. Possible values are "project", "function" + final String resourceType; + /// ID of resource to which the variable belongs. If resourceType is "project", it is empty. If resourceType is "function", it is ID of the function. + final String resourceId; + + Variable({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.key, + required this.value, + required this.resourceType, + required this.resourceId, + }); + + factory Variable.fromMap(Map<String, dynamic> map) { + return Variable( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + key: map['key'].toString(), + value: map['value'].toString(), + resourceType: map['resourceType'].toString(), + resourceId: map['resourceId'].toString(), + ); + } + + Map<String, dynamic> toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "key": key, + "value": value, + "resourceType": resourceType, + "resourceId": resourceId, + }; + } +} \ No newline at end of file diff --git a/lib/src/models/variable_list.dart b/lib/src/models/variable_list.dart index b2f550a6..e82a1b76 100644 --- a/lib/src/models/variable_list.dart +++ b/lib/src/models/variable_list.dart @@ -2,29 +2,27 @@ part of '../../models.dart'; /// Variables List class VariableList implements Model { - /// Total number of variables documents that matched your query. - final int total; + /// Total number of variables documents that matched your query. + final int total; + /// List of variables. + final List<Variable> variables; - /// List of variables. - final List<Variable> variables; + VariableList({ + required this.total, + required this.variables, + }); - VariableList({ - required this.total, - required this.variables, - }); + factory VariableList.fromMap(Map<String, dynamic> map) { + return VariableList( + total: map['total'], + variables: List<Variable>.from(map['variables'].map((p) => Variable.fromMap(p))), + ); + } - factory VariableList.fromMap(Map<String, dynamic> map) { - return VariableList( - total: map['total'], - variables: - List<Variable>.from(map['variables'].map((p) => Variable.fromMap(p))), - ); - } - - Map<String, dynamic> toMap() { - return { - "total": total, - "variables": variables.map((p) => p.toMap()).toList(), - }; - } -} + Map<String, dynamic> toMap() { + return { + "total": total, + "variables": variables.map((p) => p.toMap()).toList(), + }; + } +} \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index bffe869e..59f97f64 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: dart_appwrite -version: 12.2.0 +version: 12.2.1 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-dart diff --git a/test/services/account_test.dart b/test/services/account_test.dart index 67144409..55679f3f 100644 --- a/test/services/account_test.dart +++ b/test/services/account_test.dart @@ -332,7 +332,37 @@ void main() { }); test('test method updateMfaChallenge()', () async { - final data = ''; + final Map<String, dynamic> data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'userId': '5e5bb8c16897e', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'provider': 'email', + 'providerUid': 'user@example.com', + 'providerAccessToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'providerAccessTokenExpiry': '2020-10-15T06:38:00.000+00:00', + 'providerRefreshToken': 'MTQ0NjJkZmQ5OTM2NDE1ZTZjNGZmZjI3', + 'ip': '127.0.0.1', + 'osCode': 'Mac', + 'osName': 'Mac', + 'osVersion': 'Mac', + 'clientType': 'browser', + 'clientCode': 'CM', + 'clientName': 'Chrome Mobile iOS', + 'clientVersion': '84.0', + 'clientEngine': 'WebKit', + 'clientEngineVersion': '605.1.15', + 'deviceName': 'smartphone', + 'deviceBrand': 'Google', + 'deviceModel': 'Nexus 5', + 'countryCode': 'US', + 'countryName': 'United States', + 'current': true, + 'factors': [], + 'secret': '5e5bb8c16897e', + 'mfaUpdatedAt': '2020-10-15T06:38:00.000+00:00',}; + when(client.call( HttpMethod.put, @@ -343,6 +373,8 @@ void main() { challengeId: '<CHALLENGE_ID>', otp: '<OTP>', ); + expect(response, isA<models.Session>()); + }); test('test method listMfaFactors()', () async { diff --git a/test/services/users_test.dart b/test/services/users_test.dart index d5ac88da..9f05493d 100644 --- a/test/services/users_test.dart +++ b/test/services/users_test.dart @@ -577,24 +577,7 @@ void main() { }); test('test method deleteMfaAuthenticator()', () async { - final Map<String, dynamic> data = { - '\$id': '5e5ea5c16897e', - '\$createdAt': '2020-10-15T06:38:00.000+00:00', - '\$updatedAt': '2020-10-15T06:38:00.000+00:00', - 'name': 'John Doe', - 'registration': '2020-10-15T06:38:00.000+00:00', - 'status': true, - 'labels': [], - 'passwordUpdate': '2020-10-15T06:38:00.000+00:00', - 'email': 'john@appwrite.io', - 'phone': '+4930901820', - 'emailVerification': true, - 'phoneVerification': true, - 'mfa': true, - 'prefs': <String, dynamic>{}, - 'targets': [], - 'accessedAt': '2020-10-15T06:38:00.000+00:00',}; - + final data = ''; when(client.call( HttpMethod.delete, @@ -605,8 +588,6 @@ void main() { userId: '<USER_ID>', type: 'totp', ); - expect(response, isA<models.User>()); - }); test('test method listMfaFactors()', () async {