diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d0f2fa8..d6b62f24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## 21.1.0 + +* Add `queries` parameter to Realtime subscriptions for filtering events +* Fix `Roles` enum removed from Teams service; `roles` parameter now accepts `List` +* Fix doc examples with proper formatting and syntax highlighting + ## 21.0.0 * Add array-based enum parameters (e.g., `permissions: List`). diff --git a/README.md b/README.md index a42d0372..98986069 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) -**This SDK is compatible with Appwrite server version 1.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-flutter/releases).** +**This SDK is compatible with Appwrite server version latest. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-flutter/releases).** Appwrite is an open-source backend as a service server that abstracts and simplifies complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Flutter SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) @@ -19,7 +19,7 @@ Add this to your package's `pubspec.yaml` file: ```yml dependencies: - appwrite: ^21.0.0 + appwrite: ^21.1.0 ``` You can install packages from the command line: diff --git a/docs/examples/account/create-anonymous-session.md b/docs/examples/account/create-anonymous-session.md index cdcd98dd..0cdedf8f 100644 --- a/docs/examples/account/create-anonymous-session.md +++ b/docs/examples/account/create-anonymous-session.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Account account = Account(client); Session result = await account.createAnonymousSession(); +``` diff --git a/docs/examples/account/create-email-password-session.md b/docs/examples/account/create-email-password-session.md index 66bc2ab5..d444996d 100644 --- a/docs/examples/account/create-email-password-session.md +++ b/docs/examples/account/create-email-password-session.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ Session result = await account.createEmailPasswordSession( email: 'email@example.com', password: 'password', ); +``` diff --git a/docs/examples/account/create-email-token.md b/docs/examples/account/create-email-token.md index 26408945..73890581 100644 --- a/docs/examples/account/create-email-token.md +++ b/docs/examples/account/create-email-token.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -11,3 +12,4 @@ Token result = await account.createEmailToken( email: 'email@example.com', phrase: false, // optional ); +``` diff --git a/docs/examples/account/create-email-verification.md b/docs/examples/account/create-email-verification.md index 823ea2f2..d88979c8 100644 --- a/docs/examples/account/create-email-verification.md +++ b/docs/examples/account/create-email-verification.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Account account = Account(client); Token result = await account.createEmailVerification( url: 'https://example.com', ); +``` diff --git a/docs/examples/account/create-jwt.md b/docs/examples/account/create-jwt.md index 58dbdffb..72ff1180 100644 --- a/docs/examples/account/create-jwt.md +++ b/docs/examples/account/create-jwt.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Account account = Account(client); Jwt result = await account.createJWT( duration: 0, // optional ); +``` diff --git a/docs/examples/account/create-key.md b/docs/examples/account/create-key.md new file mode 100644 index 00000000..212bf437 --- /dev/null +++ b/docs/examples/account/create-key.md @@ -0,0 +1,16 @@ +```dart +import 'package:appwrite/appwrite.dart'; +import 'package:appwrite/enums.dart' as enums; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +Account account = Account(client); + +Key result = await account.createKey( + name: '', + scopes: [enums.Scopes.account], + expire: '', // optional +); +``` diff --git a/docs/examples/account/create-magic-url-token.md b/docs/examples/account/create-magic-url-token.md index 454a9510..59d1cc24 100644 --- a/docs/examples/account/create-magic-url-token.md +++ b/docs/examples/account/create-magic-url-token.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -12,3 +13,4 @@ Token result = await account.createMagicURLToken( url: 'https://example.com', // optional phrase: false, // optional ); +``` diff --git a/docs/examples/account/create-mfa-authenticator.md b/docs/examples/account/create-mfa-authenticator.md index 2cb96dff..c86de3ba 100644 --- a/docs/examples/account/create-mfa-authenticator.md +++ b/docs/examples/account/create-mfa-authenticator.md @@ -1,4 +1,6 @@ +```dart import 'package:appwrite/appwrite.dart'; +import 'package:appwrite/enums.dart' as enums; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint @@ -9,3 +11,4 @@ Account account = Account(client); MfaType result = await account.createMFAAuthenticator( type: enums.AuthenticatorType.totp, ); +``` diff --git a/docs/examples/account/create-mfa-challenge.md b/docs/examples/account/create-mfa-challenge.md index 8e7d1668..c7007d32 100644 --- a/docs/examples/account/create-mfa-challenge.md +++ b/docs/examples/account/create-mfa-challenge.md @@ -1,4 +1,6 @@ +```dart import 'package:appwrite/appwrite.dart'; +import 'package:appwrite/enums.dart' as enums; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint @@ -9,3 +11,4 @@ Account account = Account(client); MfaChallenge result = await account.createMFAChallenge( factor: enums.AuthenticationFactor.email, ); +``` diff --git a/docs/examples/account/create-mfa-recovery-codes.md b/docs/examples/account/create-mfa-recovery-codes.md index 9b69ad1b..252dec7a 100644 --- a/docs/examples/account/create-mfa-recovery-codes.md +++ b/docs/examples/account/create-mfa-recovery-codes.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Account account = Account(client); MfaRecoveryCodes result = await account.createMFARecoveryCodes(); +``` diff --git a/docs/examples/account/create-o-auth-2-session.md b/docs/examples/account/create-o-auth-2-session.md index c013d90b..75abae31 100644 --- a/docs/examples/account/create-o-auth-2-session.md +++ b/docs/examples/account/create-o-auth-2-session.md @@ -1,4 +1,6 @@ +```dart import 'package:appwrite/appwrite.dart'; +import 'package:appwrite/enums.dart' as enums; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint @@ -12,3 +14,4 @@ await account.createOAuth2Session( failure: 'https://example.com', // optional scopes: [], // optional ); +``` diff --git a/docs/examples/account/create-o-auth-2-token.md b/docs/examples/account/create-o-auth-2-token.md index 2b2d246e..be098a62 100644 --- a/docs/examples/account/create-o-auth-2-token.md +++ b/docs/examples/account/create-o-auth-2-token.md @@ -1,4 +1,6 @@ +```dart import 'package:appwrite/appwrite.dart'; +import 'package:appwrite/enums.dart' as enums; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint @@ -12,3 +14,4 @@ await account.createOAuth2Token( failure: 'https://example.com', // optional scopes: [], // optional ); +``` diff --git a/docs/examples/account/create-payment-method.md b/docs/examples/account/create-payment-method.md new file mode 100644 index 00000000..02e35b1b --- /dev/null +++ b/docs/examples/account/create-payment-method.md @@ -0,0 +1,11 @@ +```dart +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +Account account = Account(client); + +PaymentMethod result = await account.createPaymentMethod(); +``` diff --git a/docs/examples/account/create-phone-token.md b/docs/examples/account/create-phone-token.md index ff0187f0..95799d62 100644 --- a/docs/examples/account/create-phone-token.md +++ b/docs/examples/account/create-phone-token.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ Token result = await account.createPhoneToken( userId: '', phone: '+12065550100', ); +``` diff --git a/docs/examples/account/create-phone-verification.md b/docs/examples/account/create-phone-verification.md index 11e215a0..9fc84dfc 100644 --- a/docs/examples/account/create-phone-verification.md +++ b/docs/examples/account/create-phone-verification.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Account account = Account(client); Token result = await account.createPhoneVerification(); +``` diff --git a/docs/examples/account/create-push-target.md b/docs/examples/account/create-push-target.md index fd1755e3..d493b2a0 100644 --- a/docs/examples/account/create-push-target.md +++ b/docs/examples/account/create-push-target.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -11,3 +12,4 @@ Target result = await account.createPushTarget( identifier: '', providerId: '', // optional ); +``` diff --git a/docs/examples/account/create-recovery.md b/docs/examples/account/create-recovery.md index 44985beb..fe5ecfa0 100644 --- a/docs/examples/account/create-recovery.md +++ b/docs/examples/account/create-recovery.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ Token result = await account.createRecovery( email: 'email@example.com', url: 'https://example.com', ); +``` diff --git a/docs/examples/account/create-session.md b/docs/examples/account/create-session.md index e54e68a3..ebac1f93 100644 --- a/docs/examples/account/create-session.md +++ b/docs/examples/account/create-session.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ Session result = await account.createSession( userId: '', secret: '', ); +``` diff --git a/docs/examples/account/create-verification.md b/docs/examples/account/create-verification.md index 8f969972..c36cb8f3 100644 --- a/docs/examples/account/create-verification.md +++ b/docs/examples/account/create-verification.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Account account = Account(client); Token result = await account.createVerification( url: 'https://example.com', ); +``` diff --git a/docs/examples/account/create.md b/docs/examples/account/create.md index ae0d5269..d4bf5757 100644 --- a/docs/examples/account/create.md +++ b/docs/examples/account/create.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -12,3 +13,4 @@ User result = await account.create( password: '', name: '', // optional ); +``` diff --git a/docs/examples/account/delete-identity.md b/docs/examples/account/delete-identity.md index 849fa726..47407e7f 100644 --- a/docs/examples/account/delete-identity.md +++ b/docs/examples/account/delete-identity.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Account account = Account(client); await account.deleteIdentity( identityId: '', ); +``` diff --git a/docs/examples/account/delete-key.md b/docs/examples/account/delete-key.md new file mode 100644 index 00000000..c1b79228 --- /dev/null +++ b/docs/examples/account/delete-key.md @@ -0,0 +1,13 @@ +```dart +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +Account account = Account(client); + +await account.deleteKey( + keyId: '', +); +``` diff --git a/docs/examples/account/delete-mfa-authenticator.md b/docs/examples/account/delete-mfa-authenticator.md index 0ed6d5bc..eac79766 100644 --- a/docs/examples/account/delete-mfa-authenticator.md +++ b/docs/examples/account/delete-mfa-authenticator.md @@ -1,4 +1,6 @@ +```dart import 'package:appwrite/appwrite.dart'; +import 'package:appwrite/enums.dart' as enums; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint @@ -9,3 +11,4 @@ Account account = Account(client); await account.deleteMFAAuthenticator( type: enums.AuthenticatorType.totp, ); +``` diff --git a/docs/examples/account/delete-payment-method.md b/docs/examples/account/delete-payment-method.md new file mode 100644 index 00000000..ceb4e6c2 --- /dev/null +++ b/docs/examples/account/delete-payment-method.md @@ -0,0 +1,13 @@ +```dart +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +Account account = Account(client); + +await account.deletePaymentMethod( + paymentMethodId: '', +); +``` diff --git a/docs/examples/account/delete-push-target.md b/docs/examples/account/delete-push-target.md index 6393d4ed..477a0446 100644 --- a/docs/examples/account/delete-push-target.md +++ b/docs/examples/account/delete-push-target.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Account account = Account(client); await account.deletePushTarget( targetId: '', ); +``` diff --git a/docs/examples/account/delete-session.md b/docs/examples/account/delete-session.md index 55abb18c..513f2146 100644 --- a/docs/examples/account/delete-session.md +++ b/docs/examples/account/delete-session.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Account account = Account(client); await account.deleteSession( sessionId: '', ); +``` diff --git a/docs/examples/account/delete-sessions.md b/docs/examples/account/delete-sessions.md index c50b611c..e8e8ba1a 100644 --- a/docs/examples/account/delete-sessions.md +++ b/docs/examples/account/delete-sessions.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Account account = Account(client); await account.deleteSessions(); +``` diff --git a/docs/examples/account/get-key.md b/docs/examples/account/get-key.md new file mode 100644 index 00000000..edbdf4c5 --- /dev/null +++ b/docs/examples/account/get-key.md @@ -0,0 +1,13 @@ +```dart +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +Account account = Account(client); + +Key result = await account.getKey( + keyId: '', +); +``` diff --git a/docs/examples/account/get-mfa-recovery-codes.md b/docs/examples/account/get-mfa-recovery-codes.md index 09bff7ff..ed5531a3 100644 --- a/docs/examples/account/get-mfa-recovery-codes.md +++ b/docs/examples/account/get-mfa-recovery-codes.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Account account = Account(client); MfaRecoveryCodes result = await account.getMFARecoveryCodes(); +``` diff --git a/docs/examples/account/get-payment-method.md b/docs/examples/account/get-payment-method.md new file mode 100644 index 00000000..d9516590 --- /dev/null +++ b/docs/examples/account/get-payment-method.md @@ -0,0 +1,13 @@ +```dart +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +Account account = Account(client); + +PaymentMethod result = await account.getPaymentMethod( + paymentMethodId: '', +); +``` diff --git a/docs/examples/account/get-prefs.md b/docs/examples/account/get-prefs.md index 9332da3a..dc359f9c 100644 --- a/docs/examples/account/get-prefs.md +++ b/docs/examples/account/get-prefs.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Account account = Account(client); Preferences result = await account.getPrefs(); +``` diff --git a/docs/examples/account/get-session.md b/docs/examples/account/get-session.md index d68afcec..c27058a8 100644 --- a/docs/examples/account/get-session.md +++ b/docs/examples/account/get-session.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Account account = Account(client); Session result = await account.getSession( sessionId: '', ); +``` diff --git a/docs/examples/account/get.md b/docs/examples/account/get.md index a318617f..1bd67c6a 100644 --- a/docs/examples/account/get.md +++ b/docs/examples/account/get.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Account account = Account(client); User result = await account.get(); +``` diff --git a/docs/examples/account/list-identities.md b/docs/examples/account/list-identities.md index 31f30b41..d0c0e5b6 100644 --- a/docs/examples/account/list-identities.md +++ b/docs/examples/account/list-identities.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ IdentityList result = await account.listIdentities( queries: [], // optional total: false, // optional ); +``` diff --git a/docs/examples/account/list-keys.md b/docs/examples/account/list-keys.md new file mode 100644 index 00000000..716f71c6 --- /dev/null +++ b/docs/examples/account/list-keys.md @@ -0,0 +1,13 @@ +```dart +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +Account account = Account(client); + +KeyList result = await account.listKeys( + total: false, // optional +); +``` diff --git a/docs/examples/account/list-logs.md b/docs/examples/account/list-logs.md index a7bb5214..924470de 100644 --- a/docs/examples/account/list-logs.md +++ b/docs/examples/account/list-logs.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ LogList result = await account.listLogs( queries: [], // optional total: false, // optional ); +``` diff --git a/docs/examples/account/list-mfa-factors.md b/docs/examples/account/list-mfa-factors.md index 5e87cbaa..4cfcf88b 100644 --- a/docs/examples/account/list-mfa-factors.md +++ b/docs/examples/account/list-mfa-factors.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Account account = Account(client); MfaFactors result = await account.listMFAFactors(); +``` diff --git a/docs/examples/account/list-payment-methods.md b/docs/examples/account/list-payment-methods.md new file mode 100644 index 00000000..2afe564c --- /dev/null +++ b/docs/examples/account/list-payment-methods.md @@ -0,0 +1,13 @@ +```dart +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +Account account = Account(client); + +PaymentMethodList result = await account.listPaymentMethods( + queries: [], // optional +); +``` diff --git a/docs/examples/account/list-sessions.md b/docs/examples/account/list-sessions.md index fd1d0e08..18db93bb 100644 --- a/docs/examples/account/list-sessions.md +++ b/docs/examples/account/list-sessions.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Account account = Account(client); SessionList result = await account.listSessions(); +``` diff --git a/docs/examples/account/update-email-verification.md b/docs/examples/account/update-email-verification.md index 927aadf1..7e3975e9 100644 --- a/docs/examples/account/update-email-verification.md +++ b/docs/examples/account/update-email-verification.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ Token result = await account.updateEmailVerification( userId: '', secret: '', ); +``` diff --git a/docs/examples/account/update-email.md b/docs/examples/account/update-email.md index 0f3d9982..e5e1a169 100644 --- a/docs/examples/account/update-email.md +++ b/docs/examples/account/update-email.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ User result = await account.updateEmail( email: 'email@example.com', password: 'password', ); +``` diff --git a/docs/examples/account/update-key.md b/docs/examples/account/update-key.md new file mode 100644 index 00000000..b3e03b84 --- /dev/null +++ b/docs/examples/account/update-key.md @@ -0,0 +1,17 @@ +```dart +import 'package:appwrite/appwrite.dart'; +import 'package:appwrite/enums.dart' as enums; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +Account account = Account(client); + +Key result = await account.updateKey( + keyId: '', + name: '', + scopes: [enums.Scopes.account], + expire: '', // optional +); +``` diff --git a/docs/examples/account/update-magic-url-session.md b/docs/examples/account/update-magic-url-session.md index d0f91eb0..c45dcf1e 100644 --- a/docs/examples/account/update-magic-url-session.md +++ b/docs/examples/account/update-magic-url-session.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ Session result = await account.updateMagicURLSession( userId: '', secret: '', ); +``` diff --git a/docs/examples/account/update-mfa-authenticator.md b/docs/examples/account/update-mfa-authenticator.md index 641ae8fb..539c5e28 100644 --- a/docs/examples/account/update-mfa-authenticator.md +++ b/docs/examples/account/update-mfa-authenticator.md @@ -1,4 +1,6 @@ +```dart import 'package:appwrite/appwrite.dart'; +import 'package:appwrite/enums.dart' as enums; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint @@ -10,3 +12,4 @@ User result = await account.updateMFAAuthenticator( type: enums.AuthenticatorType.totp, otp: '', ); +``` diff --git a/docs/examples/account/update-mfa-challenge.md b/docs/examples/account/update-mfa-challenge.md index b917e411..55f4ebee 100644 --- a/docs/examples/account/update-mfa-challenge.md +++ b/docs/examples/account/update-mfa-challenge.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ Session result = await account.updateMFAChallenge( challengeId: '', otp: '', ); +``` diff --git a/docs/examples/account/update-mfa-recovery-codes.md b/docs/examples/account/update-mfa-recovery-codes.md index 377149bf..7a188d40 100644 --- a/docs/examples/account/update-mfa-recovery-codes.md +++ b/docs/examples/account/update-mfa-recovery-codes.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Account account = Account(client); MfaRecoveryCodes result = await account.updateMFARecoveryCodes(); +``` diff --git a/docs/examples/account/update-mfa.md b/docs/examples/account/update-mfa.md index fc81c565..db9addd6 100644 --- a/docs/examples/account/update-mfa.md +++ b/docs/examples/account/update-mfa.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Account account = Account(client); User result = await account.updateMFA( mfa: false, ); +``` diff --git a/docs/examples/account/update-name.md b/docs/examples/account/update-name.md index 303a1235..8ab71223 100644 --- a/docs/examples/account/update-name.md +++ b/docs/examples/account/update-name.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Account account = Account(client); User result = await account.updateName( name: '', ); +``` diff --git a/docs/examples/account/update-password.md b/docs/examples/account/update-password.md index 835d2383..33ae55f4 100644 --- a/docs/examples/account/update-password.md +++ b/docs/examples/account/update-password.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ User result = await account.updatePassword( password: '', oldPassword: 'password', // optional ); +``` diff --git a/docs/examples/account/update-payment-method-mandate-options.md b/docs/examples/account/update-payment-method-mandate-options.md new file mode 100644 index 00000000..3e5d07cc --- /dev/null +++ b/docs/examples/account/update-payment-method-mandate-options.md @@ -0,0 +1,13 @@ +```dart +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +Account account = Account(client); + +PaymentMethod result = await account.updatePaymentMethodMandateOptions( + paymentMethodId: '', +); +``` diff --git a/docs/examples/account/update-payment-method-provider.md b/docs/examples/account/update-payment-method-provider.md new file mode 100644 index 00000000..0aae172d --- /dev/null +++ b/docs/examples/account/update-payment-method-provider.md @@ -0,0 +1,16 @@ +```dart +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +Account account = Account(client); + +PaymentMethod result = await account.updatePaymentMethodProvider( + paymentMethodId: '', + providerMethodId: '', + name: '', + state: '', // optional +); +``` diff --git a/docs/examples/account/update-payment-method.md b/docs/examples/account/update-payment-method.md new file mode 100644 index 00000000..53909398 --- /dev/null +++ b/docs/examples/account/update-payment-method.md @@ -0,0 +1,16 @@ +```dart +import 'package:appwrite/appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject(''); // Your project ID + +Account account = Account(client); + +PaymentMethod result = await account.updatePaymentMethod( + paymentMethodId: '', + expiryMonth: 1, + expiryYear: 2026, + state: '', // optional +); +``` diff --git a/docs/examples/account/update-phone-session.md b/docs/examples/account/update-phone-session.md index 36801792..f538680a 100644 --- a/docs/examples/account/update-phone-session.md +++ b/docs/examples/account/update-phone-session.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ Session result = await account.updatePhoneSession( userId: '', secret: '', ); +``` diff --git a/docs/examples/account/update-phone-verification.md b/docs/examples/account/update-phone-verification.md index f5bbb773..de226a7c 100644 --- a/docs/examples/account/update-phone-verification.md +++ b/docs/examples/account/update-phone-verification.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ Token result = await account.updatePhoneVerification( userId: '', secret: '', ); +``` diff --git a/docs/examples/account/update-phone.md b/docs/examples/account/update-phone.md index 6390d142..f631c5df 100644 --- a/docs/examples/account/update-phone.md +++ b/docs/examples/account/update-phone.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ User result = await account.updatePhone( phone: '+12065550100', password: 'password', ); +``` diff --git a/docs/examples/account/update-prefs.md b/docs/examples/account/update-prefs.md index a084c13e..6f9863d3 100644 --- a/docs/examples/account/update-prefs.md +++ b/docs/examples/account/update-prefs.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -13,3 +14,4 @@ User result = await account.updatePrefs( "darkTheme": true }, ); +``` diff --git a/docs/examples/account/update-push-target.md b/docs/examples/account/update-push-target.md index c695ea09..601f3aec 100644 --- a/docs/examples/account/update-push-target.md +++ b/docs/examples/account/update-push-target.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ Target result = await account.updatePushTarget( targetId: '', identifier: '', ); +``` diff --git a/docs/examples/account/update-recovery.md b/docs/examples/account/update-recovery.md index 5ca0239f..87ff07bd 100644 --- a/docs/examples/account/update-recovery.md +++ b/docs/examples/account/update-recovery.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -11,3 +12,4 @@ Token result = await account.updateRecovery( secret: '', password: '', ); +``` diff --git a/docs/examples/account/update-session.md b/docs/examples/account/update-session.md index 4c78ebb1..7fb334aa 100644 --- a/docs/examples/account/update-session.md +++ b/docs/examples/account/update-session.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Account account = Account(client); Session result = await account.updateSession( sessionId: '', ); +``` diff --git a/docs/examples/account/update-status.md b/docs/examples/account/update-status.md index 289a3f0a..d7b0d0dc 100644 --- a/docs/examples/account/update-status.md +++ b/docs/examples/account/update-status.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Account account = Account(client); User result = await account.updateStatus(); +``` diff --git a/docs/examples/account/update-verification.md b/docs/examples/account/update-verification.md index 15c7ed19..339b4b91 100644 --- a/docs/examples/account/update-verification.md +++ b/docs/examples/account/update-verification.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ Token result = await account.updateVerification( userId: '', secret: '', ); +``` diff --git a/docs/examples/avatars/get-browser.md b/docs/examples/avatars/get-browser.md index 7528a622..19026083 100644 --- a/docs/examples/avatars/get-browser.md +++ b/docs/examples/avatars/get-browser.md @@ -1,4 +1,6 @@ +```dart import 'package:appwrite/appwrite.dart'; +import 'package:appwrite/enums.dart' as enums; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint @@ -31,3 +33,4 @@ FutureBuilder( : CircularProgressIndicator(); } ); +``` diff --git a/docs/examples/avatars/get-credit-card.md b/docs/examples/avatars/get-credit-card.md index 2586613c..395608a4 100644 --- a/docs/examples/avatars/get-credit-card.md +++ b/docs/examples/avatars/get-credit-card.md @@ -1,4 +1,6 @@ +```dart import 'package:appwrite/appwrite.dart'; +import 'package:appwrite/enums.dart' as enums; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint @@ -31,3 +33,4 @@ FutureBuilder( : CircularProgressIndicator(); } ); +``` diff --git a/docs/examples/avatars/get-favicon.md b/docs/examples/avatars/get-favicon.md index abd61a09..fd1d0df7 100644 --- a/docs/examples/avatars/get-favicon.md +++ b/docs/examples/avatars/get-favicon.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -25,3 +26,4 @@ FutureBuilder( : CircularProgressIndicator(); } ); +``` diff --git a/docs/examples/avatars/get-flag.md b/docs/examples/avatars/get-flag.md index 8d2649b3..a5753f6c 100644 --- a/docs/examples/avatars/get-flag.md +++ b/docs/examples/avatars/get-flag.md @@ -1,4 +1,6 @@ +```dart import 'package:appwrite/appwrite.dart'; +import 'package:appwrite/enums.dart' as enums; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint @@ -31,3 +33,4 @@ FutureBuilder( : CircularProgressIndicator(); } ); +``` diff --git a/docs/examples/avatars/get-image.md b/docs/examples/avatars/get-image.md index bbfcc038..4e75bc7e 100644 --- a/docs/examples/avatars/get-image.md +++ b/docs/examples/avatars/get-image.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -29,3 +30,4 @@ FutureBuilder( : CircularProgressIndicator(); } ); +``` diff --git a/docs/examples/avatars/get-initials.md b/docs/examples/avatars/get-initials.md index 29940c17..3b5bb68e 100644 --- a/docs/examples/avatars/get-initials.md +++ b/docs/examples/avatars/get-initials.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -31,3 +32,4 @@ FutureBuilder( : CircularProgressIndicator(); } ); +``` diff --git a/docs/examples/avatars/get-qr.md b/docs/examples/avatars/get-qr.md index 0a75a668..8a6dc770 100644 --- a/docs/examples/avatars/get-qr.md +++ b/docs/examples/avatars/get-qr.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -31,3 +32,4 @@ FutureBuilder( : CircularProgressIndicator(); } ); +``` diff --git a/docs/examples/avatars/get-screenshot.md b/docs/examples/avatars/get-screenshot.md index 43c77ca2..6695d05a 100644 --- a/docs/examples/avatars/get-screenshot.md +++ b/docs/examples/avatars/get-screenshot.md @@ -1,4 +1,6 @@ +```dart import 'package:appwrite/appwrite.dart'; +import 'package:appwrite/enums.dart' as enums; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint @@ -69,3 +71,4 @@ FutureBuilder( : CircularProgressIndicator(); } ); +``` diff --git a/docs/examples/databases/create-document.md b/docs/examples/databases/create-document.md index 20a1c3c3..a4df848f 100644 --- a/docs/examples/databases/create-document.md +++ b/docs/examples/databases/create-document.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; import 'package:appwrite/permission.dart'; import 'package:appwrite/role.dart'; @@ -22,3 +23,4 @@ Document result = await databases.createDocument( permissions: [Permission.read(Role.any())], // optional transactionId: '', // optional ); +``` diff --git a/docs/examples/databases/create-operations.md b/docs/examples/databases/create-operations.md index 2dec7ff7..0551c28b 100644 --- a/docs/examples/databases/create-operations.md +++ b/docs/examples/databases/create-operations.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -20,3 +21,4 @@ Transaction result = await databases.createOperations( } ], // optional ); +``` diff --git a/docs/examples/databases/create-transaction.md b/docs/examples/databases/create-transaction.md index 3d7ddc3e..14ea5563 100644 --- a/docs/examples/databases/create-transaction.md +++ b/docs/examples/databases/create-transaction.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Databases databases = Databases(client); Transaction result = await databases.createTransaction( ttl: 60, // optional ); +``` diff --git a/docs/examples/databases/decrement-document-attribute.md b/docs/examples/databases/decrement-document-attribute.md index dad45bc8..83eaf379 100644 --- a/docs/examples/databases/decrement-document-attribute.md +++ b/docs/examples/databases/decrement-document-attribute.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -15,3 +16,4 @@ Document result = await databases.decrementDocumentAttribute( min: 0, // optional transactionId: '', // optional ); +``` diff --git a/docs/examples/databases/delete-document.md b/docs/examples/databases/delete-document.md index bd101370..92350ce2 100644 --- a/docs/examples/databases/delete-document.md +++ b/docs/examples/databases/delete-document.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -12,3 +13,4 @@ await databases.deleteDocument( documentId: '', transactionId: '', // optional ); +``` diff --git a/docs/examples/databases/delete-transaction.md b/docs/examples/databases/delete-transaction.md index 333dd1d3..3d6d5ed4 100644 --- a/docs/examples/databases/delete-transaction.md +++ b/docs/examples/databases/delete-transaction.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Databases databases = Databases(client); await databases.deleteTransaction( transactionId: '', ); +``` diff --git a/docs/examples/databases/get-document.md b/docs/examples/databases/get-document.md index 9dcf2cf1..1f384afd 100644 --- a/docs/examples/databases/get-document.md +++ b/docs/examples/databases/get-document.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -13,3 +14,4 @@ Document result = await databases.getDocument( queries: [], // optional transactionId: '', // optional ); +``` diff --git a/docs/examples/databases/get-transaction.md b/docs/examples/databases/get-transaction.md index 153b0f38..142b8bfa 100644 --- a/docs/examples/databases/get-transaction.md +++ b/docs/examples/databases/get-transaction.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Databases databases = Databases(client); Transaction result = await databases.getTransaction( transactionId: '', ); +``` diff --git a/docs/examples/databases/increment-document-attribute.md b/docs/examples/databases/increment-document-attribute.md index 855fd8f5..22ec3431 100644 --- a/docs/examples/databases/increment-document-attribute.md +++ b/docs/examples/databases/increment-document-attribute.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -15,3 +16,4 @@ Document result = await databases.incrementDocumentAttribute( max: 0, // optional transactionId: '', // optional ); +``` diff --git a/docs/examples/databases/list-documents.md b/docs/examples/databases/list-documents.md index 0527c752..ca690a55 100644 --- a/docs/examples/databases/list-documents.md +++ b/docs/examples/databases/list-documents.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -13,3 +14,4 @@ DocumentList result = await databases.listDocuments( transactionId: '', // optional total: false, // optional ); +``` diff --git a/docs/examples/databases/list-transactions.md b/docs/examples/databases/list-transactions.md index 467a1ced..ca9ff6fb 100644 --- a/docs/examples/databases/list-transactions.md +++ b/docs/examples/databases/list-transactions.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Databases databases = Databases(client); TransactionList result = await databases.listTransactions( queries: [], // optional ); +``` diff --git a/docs/examples/databases/update-document.md b/docs/examples/databases/update-document.md index 92407b14..52557334 100644 --- a/docs/examples/databases/update-document.md +++ b/docs/examples/databases/update-document.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; import 'package:appwrite/permission.dart'; import 'package:appwrite/role.dart'; @@ -22,3 +23,4 @@ Document result = await databases.updateDocument( permissions: [Permission.read(Role.any())], // optional transactionId: '', // optional ); +``` diff --git a/docs/examples/databases/update-transaction.md b/docs/examples/databases/update-transaction.md index a51f9d05..a882eb92 100644 --- a/docs/examples/databases/update-transaction.md +++ b/docs/examples/databases/update-transaction.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -11,3 +12,4 @@ Transaction result = await databases.updateTransaction( commit: false, // optional rollback: false, // optional ); +``` diff --git a/docs/examples/databases/upsert-document.md b/docs/examples/databases/upsert-document.md index 6ad76385..6678a0dc 100644 --- a/docs/examples/databases/upsert-document.md +++ b/docs/examples/databases/upsert-document.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; import 'package:appwrite/permission.dart'; import 'package:appwrite/role.dart'; @@ -22,3 +23,4 @@ Document result = await databases.upsertDocument( permissions: [Permission.read(Role.any())], // optional transactionId: '', // optional ); +``` diff --git a/docs/examples/functions/create-execution.md b/docs/examples/functions/create-execution.md index fa9780ff..0e219748 100644 --- a/docs/examples/functions/create-execution.md +++ b/docs/examples/functions/create-execution.md @@ -1,4 +1,6 @@ +```dart import 'package:appwrite/appwrite.dart'; +import 'package:appwrite/enums.dart' as enums; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint @@ -15,3 +17,4 @@ Execution result = await functions.createExecution( headers: {}, // optional scheduledAt: '', // optional ); +``` diff --git a/docs/examples/functions/get-execution.md b/docs/examples/functions/get-execution.md index 714933be..f17e10c1 100644 --- a/docs/examples/functions/get-execution.md +++ b/docs/examples/functions/get-execution.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ Execution result = await functions.getExecution( functionId: '', executionId: '', ); +``` diff --git a/docs/examples/functions/list-executions.md b/docs/examples/functions/list-executions.md index b4071bff..ae31ffcc 100644 --- a/docs/examples/functions/list-executions.md +++ b/docs/examples/functions/list-executions.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -11,3 +12,4 @@ ExecutionList result = await functions.listExecutions( queries: [], // optional total: false, // optional ); +``` diff --git a/docs/examples/graphql/mutation.md b/docs/examples/graphql/mutation.md index 60f0c297..7ec3ba75 100644 --- a/docs/examples/graphql/mutation.md +++ b/docs/examples/graphql/mutation.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Graphql graphql = Graphql(client); Any result = await graphql.mutation( query: {}, ); +``` diff --git a/docs/examples/graphql/query.md b/docs/examples/graphql/query.md index d90c3432..cac705e5 100644 --- a/docs/examples/graphql/query.md +++ b/docs/examples/graphql/query.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Graphql graphql = Graphql(client); Any result = await graphql.query( query: {}, ); +``` diff --git a/docs/examples/locale/get.md b/docs/examples/locale/get.md index b2846990..63021144 100644 --- a/docs/examples/locale/get.md +++ b/docs/examples/locale/get.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Locale locale = Locale(client); Locale result = await locale.get(); +``` diff --git a/docs/examples/locale/list-codes.md b/docs/examples/locale/list-codes.md index 02274715..23c375ba 100644 --- a/docs/examples/locale/list-codes.md +++ b/docs/examples/locale/list-codes.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Locale locale = Locale(client); LocaleCodeList result = await locale.listCodes(); +``` diff --git a/docs/examples/locale/list-continents.md b/docs/examples/locale/list-continents.md index 1098bd1d..349be795 100644 --- a/docs/examples/locale/list-continents.md +++ b/docs/examples/locale/list-continents.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Locale locale = Locale(client); ContinentList result = await locale.listContinents(); +``` diff --git a/docs/examples/locale/list-countries-eu.md b/docs/examples/locale/list-countries-eu.md index 7d6571f4..f775aa2e 100644 --- a/docs/examples/locale/list-countries-eu.md +++ b/docs/examples/locale/list-countries-eu.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Locale locale = Locale(client); CountryList result = await locale.listCountriesEU(); +``` diff --git a/docs/examples/locale/list-countries-phones.md b/docs/examples/locale/list-countries-phones.md index 395f240f..ee368e29 100644 --- a/docs/examples/locale/list-countries-phones.md +++ b/docs/examples/locale/list-countries-phones.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Locale locale = Locale(client); PhoneList result = await locale.listCountriesPhones(); +``` diff --git a/docs/examples/locale/list-countries.md b/docs/examples/locale/list-countries.md index a322eb20..17e0814f 100644 --- a/docs/examples/locale/list-countries.md +++ b/docs/examples/locale/list-countries.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Locale locale = Locale(client); CountryList result = await locale.listCountries(); +``` diff --git a/docs/examples/locale/list-currencies.md b/docs/examples/locale/list-currencies.md index 8884bf45..751de786 100644 --- a/docs/examples/locale/list-currencies.md +++ b/docs/examples/locale/list-currencies.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Locale locale = Locale(client); CurrencyList result = await locale.listCurrencies(); +``` diff --git a/docs/examples/locale/list-languages.md b/docs/examples/locale/list-languages.md index 0444d941..28b46a0a 100644 --- a/docs/examples/locale/list-languages.md +++ b/docs/examples/locale/list-languages.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -7,3 +8,4 @@ Client client = Client() Locale locale = Locale(client); LanguageList result = await locale.listLanguages(); +``` diff --git a/docs/examples/messaging/create-subscriber.md b/docs/examples/messaging/create-subscriber.md index 2a278a04..e28a1ab6 100644 --- a/docs/examples/messaging/create-subscriber.md +++ b/docs/examples/messaging/create-subscriber.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -11,3 +12,4 @@ Subscriber result = await messaging.createSubscriber( subscriberId: '', targetId: '', ); +``` diff --git a/docs/examples/messaging/delete-subscriber.md b/docs/examples/messaging/delete-subscriber.md index 02c1f615..4861ec90 100644 --- a/docs/examples/messaging/delete-subscriber.md +++ b/docs/examples/messaging/delete-subscriber.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ await messaging.deleteSubscriber( topicId: '', subscriberId: '', ); +``` diff --git a/docs/examples/storage/create-file.md b/docs/examples/storage/create-file.md index ed1021c9..8f904801 100644 --- a/docs/examples/storage/create-file.md +++ b/docs/examples/storage/create-file.md @@ -1,3 +1,4 @@ +```dart import 'dart:io'; import 'package:appwrite/appwrite.dart'; import 'package:appwrite/permission.dart'; @@ -15,3 +16,4 @@ File result = await storage.createFile( file: InputFile(path: './path-to-files/image.jpg', filename: 'image.jpg'), permissions: [Permission.read(Role.any())], // optional ); +``` diff --git a/docs/examples/storage/delete-file.md b/docs/examples/storage/delete-file.md index b2c6a78f..960e92f5 100644 --- a/docs/examples/storage/delete-file.md +++ b/docs/examples/storage/delete-file.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ await storage.deleteFile( bucketId: '', fileId: '', ); +``` diff --git a/docs/examples/storage/get-file-download.md b/docs/examples/storage/get-file-download.md index 2cdba9b1..8fc48d15 100644 --- a/docs/examples/storage/get-file-download.md +++ b/docs/examples/storage/get-file-download.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -29,3 +30,4 @@ FutureBuilder( : CircularProgressIndicator(); } ); +``` diff --git a/docs/examples/storage/get-file-preview.md b/docs/examples/storage/get-file-preview.md index 92bee14e..06e583a3 100644 --- a/docs/examples/storage/get-file-preview.md +++ b/docs/examples/storage/get-file-preview.md @@ -1,4 +1,6 @@ +```dart import 'package:appwrite/appwrite.dart'; +import 'package:appwrite/enums.dart' as enums; Client client = Client() .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint @@ -51,3 +53,4 @@ FutureBuilder( : CircularProgressIndicator(); } ); +``` diff --git a/docs/examples/storage/get-file-view.md b/docs/examples/storage/get-file-view.md index bcf5902c..56d2652d 100644 --- a/docs/examples/storage/get-file-view.md +++ b/docs/examples/storage/get-file-view.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -29,3 +30,4 @@ FutureBuilder( : CircularProgressIndicator(); } ); +``` diff --git a/docs/examples/storage/get-file.md b/docs/examples/storage/get-file.md index f4b541ff..9f1adb6e 100644 --- a/docs/examples/storage/get-file.md +++ b/docs/examples/storage/get-file.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ File result = await storage.getFile( bucketId: '', fileId: '', ); +``` diff --git a/docs/examples/storage/list-files.md b/docs/examples/storage/list-files.md index 8f7c3bd7..0decd695 100644 --- a/docs/examples/storage/list-files.md +++ b/docs/examples/storage/list-files.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -12,3 +13,4 @@ FileList result = await storage.listFiles( search: '', // optional total: false, // optional ); +``` diff --git a/docs/examples/storage/update-file.md b/docs/examples/storage/update-file.md index 8aa29234..90814329 100644 --- a/docs/examples/storage/update-file.md +++ b/docs/examples/storage/update-file.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; import 'package:appwrite/permission.dart'; import 'package:appwrite/role.dart'; @@ -14,3 +15,4 @@ File result = await storage.updateFile( name: '', // optional permissions: [Permission.read(Role.any())], // optional ); +``` diff --git a/docs/examples/tablesdb/create-operations.md b/docs/examples/tablesdb/create-operations.md index 631aefe6..bc779b6b 100644 --- a/docs/examples/tablesdb/create-operations.md +++ b/docs/examples/tablesdb/create-operations.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -20,3 +21,4 @@ Transaction result = await tablesDB.createOperations( } ], // optional ); +``` diff --git a/docs/examples/tablesdb/create-row.md b/docs/examples/tablesdb/create-row.md index ede8c404..cb5d8578 100644 --- a/docs/examples/tablesdb/create-row.md +++ b/docs/examples/tablesdb/create-row.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; import 'package:appwrite/permission.dart'; import 'package:appwrite/role.dart'; @@ -22,3 +23,4 @@ Row result = await tablesDB.createRow( permissions: [Permission.read(Role.any())], // optional transactionId: '', // optional ); +``` diff --git a/docs/examples/tablesdb/create-transaction.md b/docs/examples/tablesdb/create-transaction.md index 0ad0eb52..527dde39 100644 --- a/docs/examples/tablesdb/create-transaction.md +++ b/docs/examples/tablesdb/create-transaction.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ TablesDB tablesDB = TablesDB(client); Transaction result = await tablesDB.createTransaction( ttl: 60, // optional ); +``` diff --git a/docs/examples/tablesdb/decrement-row-column.md b/docs/examples/tablesdb/decrement-row-column.md index 65f67513..699badfc 100644 --- a/docs/examples/tablesdb/decrement-row-column.md +++ b/docs/examples/tablesdb/decrement-row-column.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -15,3 +16,4 @@ Row result = await tablesDB.decrementRowColumn( min: 0, // optional transactionId: '', // optional ); +``` diff --git a/docs/examples/tablesdb/delete-row.md b/docs/examples/tablesdb/delete-row.md index b8ea1d26..c4e66f58 100644 --- a/docs/examples/tablesdb/delete-row.md +++ b/docs/examples/tablesdb/delete-row.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -12,3 +13,4 @@ await tablesDB.deleteRow( rowId: '', transactionId: '', // optional ); +``` diff --git a/docs/examples/tablesdb/delete-transaction.md b/docs/examples/tablesdb/delete-transaction.md index 2d27c6af..ab178fb8 100644 --- a/docs/examples/tablesdb/delete-transaction.md +++ b/docs/examples/tablesdb/delete-transaction.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ TablesDB tablesDB = TablesDB(client); await tablesDB.deleteTransaction( transactionId: '', ); +``` diff --git a/docs/examples/tablesdb/get-row.md b/docs/examples/tablesdb/get-row.md index eb75da50..6e385a84 100644 --- a/docs/examples/tablesdb/get-row.md +++ b/docs/examples/tablesdb/get-row.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -13,3 +14,4 @@ Row result = await tablesDB.getRow( queries: [], // optional transactionId: '', // optional ); +``` diff --git a/docs/examples/tablesdb/get-transaction.md b/docs/examples/tablesdb/get-transaction.md index 000e2302..39b02a77 100644 --- a/docs/examples/tablesdb/get-transaction.md +++ b/docs/examples/tablesdb/get-transaction.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ TablesDB tablesDB = TablesDB(client); Transaction result = await tablesDB.getTransaction( transactionId: '', ); +``` diff --git a/docs/examples/tablesdb/increment-row-column.md b/docs/examples/tablesdb/increment-row-column.md index 91cd0ce3..1837125e 100644 --- a/docs/examples/tablesdb/increment-row-column.md +++ b/docs/examples/tablesdb/increment-row-column.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -15,3 +16,4 @@ Row result = await tablesDB.incrementRowColumn( max: 0, // optional transactionId: '', // optional ); +``` diff --git a/docs/examples/tablesdb/list-rows.md b/docs/examples/tablesdb/list-rows.md index 38305101..1d535f8a 100644 --- a/docs/examples/tablesdb/list-rows.md +++ b/docs/examples/tablesdb/list-rows.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -13,3 +14,4 @@ RowList result = await tablesDB.listRows( transactionId: '', // optional total: false, // optional ); +``` diff --git a/docs/examples/tablesdb/list-transactions.md b/docs/examples/tablesdb/list-transactions.md index 5e088ced..d95e5198 100644 --- a/docs/examples/tablesdb/list-transactions.md +++ b/docs/examples/tablesdb/list-transactions.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ TablesDB tablesDB = TablesDB(client); TransactionList result = await tablesDB.listTransactions( queries: [], // optional ); +``` diff --git a/docs/examples/tablesdb/update-row.md b/docs/examples/tablesdb/update-row.md index cf7dd773..3cf3c955 100644 --- a/docs/examples/tablesdb/update-row.md +++ b/docs/examples/tablesdb/update-row.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; import 'package:appwrite/permission.dart'; import 'package:appwrite/role.dart'; @@ -22,3 +23,4 @@ Row result = await tablesDB.updateRow( permissions: [Permission.read(Role.any())], // optional transactionId: '', // optional ); +``` diff --git a/docs/examples/tablesdb/update-transaction.md b/docs/examples/tablesdb/update-transaction.md index ef56443e..d5a8e082 100644 --- a/docs/examples/tablesdb/update-transaction.md +++ b/docs/examples/tablesdb/update-transaction.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -11,3 +12,4 @@ Transaction result = await tablesDB.updateTransaction( commit: false, // optional rollback: false, // optional ); +``` diff --git a/docs/examples/tablesdb/upsert-row.md b/docs/examples/tablesdb/upsert-row.md index 9d69ef6b..74c7d2c5 100644 --- a/docs/examples/tablesdb/upsert-row.md +++ b/docs/examples/tablesdb/upsert-row.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; import 'package:appwrite/permission.dart'; import 'package:appwrite/role.dart'; @@ -22,3 +23,4 @@ Row result = await tablesDB.upsertRow( permissions: [Permission.read(Role.any())], // optional transactionId: '', // optional ); +``` diff --git a/docs/examples/teams/create-membership.md b/docs/examples/teams/create-membership.md index 2491fba7..caab7926 100644 --- a/docs/examples/teams/create-membership.md +++ b/docs/examples/teams/create-membership.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -8,10 +9,11 @@ Teams teams = Teams(client); Membership result = await teams.createMembership( teamId: '', - roles: [enums.Roles.admin], + roles: [], email: 'email@example.com', // optional userId: '', // optional phone: '+12065550100', // optional url: 'https://example.com', // optional name: '', // optional ); +``` diff --git a/docs/examples/teams/create.md b/docs/examples/teams/create.md index 637e216a..7a4af366 100644 --- a/docs/examples/teams/create.md +++ b/docs/examples/teams/create.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -11,3 +12,4 @@ Team result = await teams.create( name: '', roles: [], // optional ); +``` diff --git a/docs/examples/teams/delete-membership.md b/docs/examples/teams/delete-membership.md index 0f1941d8..e42161fa 100644 --- a/docs/examples/teams/delete-membership.md +++ b/docs/examples/teams/delete-membership.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ await teams.deleteMembership( teamId: '', membershipId: '', ); +``` diff --git a/docs/examples/teams/delete.md b/docs/examples/teams/delete.md index 74c74c9c..d3f4d711 100644 --- a/docs/examples/teams/delete.md +++ b/docs/examples/teams/delete.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Teams teams = Teams(client); await teams.delete( teamId: '', ); +``` diff --git a/docs/examples/teams/get-membership.md b/docs/examples/teams/get-membership.md index 468e02cf..3a2906b9 100644 --- a/docs/examples/teams/get-membership.md +++ b/docs/examples/teams/get-membership.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ Membership result = await teams.getMembership( teamId: '', membershipId: '', ); +``` diff --git a/docs/examples/teams/get-prefs.md b/docs/examples/teams/get-prefs.md index a22c7886..e35006fa 100644 --- a/docs/examples/teams/get-prefs.md +++ b/docs/examples/teams/get-prefs.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Teams teams = Teams(client); Preferences result = await teams.getPrefs( teamId: '', ); +``` diff --git a/docs/examples/teams/get.md b/docs/examples/teams/get.md index 5e8c3463..2a71db42 100644 --- a/docs/examples/teams/get.md +++ b/docs/examples/teams/get.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,3 +10,4 @@ Teams teams = Teams(client); Team result = await teams.get( teamId: '', ); +``` diff --git a/docs/examples/teams/list-memberships.md b/docs/examples/teams/list-memberships.md index 86b5eed2..bf643511 100644 --- a/docs/examples/teams/list-memberships.md +++ b/docs/examples/teams/list-memberships.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -12,3 +13,4 @@ MembershipList result = await teams.listMemberships( search: '', // optional total: false, // optional ); +``` diff --git a/docs/examples/teams/list.md b/docs/examples/teams/list.md index fd8b60f2..2de4ebfe 100644 --- a/docs/examples/teams/list.md +++ b/docs/examples/teams/list.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -11,3 +12,4 @@ TeamList result = await teams.list( search: '', // optional total: false, // optional ); +``` diff --git a/docs/examples/teams/update-membership-status.md b/docs/examples/teams/update-membership-status.md index 1ce3eacb..ebb924b0 100644 --- a/docs/examples/teams/update-membership-status.md +++ b/docs/examples/teams/update-membership-status.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -12,3 +13,4 @@ Membership result = await teams.updateMembershipStatus( userId: '', secret: '', ); +``` diff --git a/docs/examples/teams/update-membership.md b/docs/examples/teams/update-membership.md index 2b9f9b3e..2d7c25c8 100644 --- a/docs/examples/teams/update-membership.md +++ b/docs/examples/teams/update-membership.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -9,5 +10,6 @@ Teams teams = Teams(client); Membership result = await teams.updateMembership( teamId: '', membershipId: '', - roles: [enums.Roles.admin], + roles: [], ); +``` diff --git a/docs/examples/teams/update-name.md b/docs/examples/teams/update-name.md index 8f179458..629e7608 100644 --- a/docs/examples/teams/update-name.md +++ b/docs/examples/teams/update-name.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ Team result = await teams.updateName( teamId: '', name: '', ); +``` diff --git a/docs/examples/teams/update-prefs.md b/docs/examples/teams/update-prefs.md index 7b33c8c3..1a53c498 100644 --- a/docs/examples/teams/update-prefs.md +++ b/docs/examples/teams/update-prefs.md @@ -1,3 +1,4 @@ +```dart import 'package:appwrite/appwrite.dart'; Client client = Client() @@ -10,3 +11,4 @@ Preferences result = await teams.updatePrefs( teamId: '', prefs: {}, ); +``` diff --git a/lib/channel.dart b/lib/channel.dart index b83614be..d6bbb898 100644 --- a/lib/channel.dart +++ b/lib/channel.dart @@ -38,9 +38,15 @@ class Channel { Channel._(this._segments); - /// Internal helper to transition to next state with segment and ID - Channel _next(String segment, [String id = '*']) { - return Channel._([..._segments, segment, _normalize(id)]); + /// Internal helper to transition to next state with segment and optional ID + Channel _next(String segment, [String? id]) { + final segments = [..._segments, segment]; + + if (id != null) { + segments.add(_normalize(id)); + } + + return Channel._(segments); } /// Internal helper for terminal actions (no ID segment) @@ -61,6 +67,9 @@ class Channel { static Channel<_Bucket> bucket([String id = '*']) => Channel<_Bucket>._(['buckets', _normalize(id)]); + static Channel<_Execution> execution([String id = '*']) => + Channel<_Execution>._(['executions', _normalize(id)]); + static Channel<_Func> function([String id = '*']) => Channel<_Func>._(['functions', _normalize(id)]); @@ -70,10 +79,7 @@ class Channel { static Channel<_Membership> membership([String id = '*']) => Channel<_Membership>._(['memberships', _normalize(id)]); - static String account([String userId = '']) { - final id = _normalize(userId); - return id == '*' ? 'account' : 'account.$id'; - } + static String account() => 'account'; // Global events static String documents() => 'documents'; @@ -88,13 +94,13 @@ class Channel { /// Only available on Channel<_Database> extension DatabaseChannel on Channel<_Database> { - Channel<_Collection> collection([String id = '*']) => - _next<_Collection>('collections', id); + Channel<_Collection> collection([String? id]) => + _next<_Collection>('collections', id ?? '*'); } /// Only available on Channel<_Collection> extension CollectionChannel on Channel<_Collection> { - Channel<_Document> document([String id = '*']) => + Channel<_Document> document([String? id]) => _next<_Document>('documents', id); } @@ -102,27 +108,19 @@ extension CollectionChannel on Channel<_Collection> { /// Only available on Channel<_TablesDB> extension TablesDBChannel on Channel<_TablesDB> { - Channel<_Table> table([String id = '*']) => _next<_Table>('tables', id); + Channel<_Table> table([String? id]) => _next<_Table>('tables', id ?? '*'); } /// Only available on Channel<_Table> extension TableChannel on Channel<_Table> { - Channel<_Row> row([String id = '*']) => _next<_Row>('rows', id); + Channel<_Row> row([String? id]) => _next<_Row>('rows', id); } // --- BUCKET ROUTE --- /// Only available on Channel<_Bucket> extension BucketChannel on Channel<_Bucket> { - Channel<_File> file([String id = '*']) => _next<_File>('files', id); -} - -// --- FUNCTION ROUTE --- - -/// Only available on Channel<_Func> -extension FuncChannel on Channel<_Func> { - Channel<_Execution> execution([String id = '*']) => - _next<_Execution>('executions', id); + Channel<_File> file([String? id]) => _next<_File>('files', id); } // --- TERMINAL ACTIONS --- @@ -149,13 +147,6 @@ extension FileChannel on Channel<_File> { Channel<_Resolved> delete() => _resolve('delete'); } -/// Only available on Channel<_Execution> -extension ExecutionChannel on Channel<_Execution> { - Channel<_Resolved> create() => _resolve('create'); - Channel<_Resolved> update() => _resolve('update'); - Channel<_Resolved> delete() => _resolve('delete'); -} - /// Only available on Channel<_Team> extension TeamChannel on Channel<_Team> { Channel<_Resolved> create() => _resolve('create'); diff --git a/lib/enums.dart b/lib/enums.dart index f2f5823f..f4b466f6 100644 --- a/lib/enums.dart +++ b/lib/enums.dart @@ -1,6 +1,7 @@ /// Appwrite Enums library appwrite.enums; +part 'src/enums/scopes.dart'; part 'src/enums/authenticator_type.dart'; part 'src/enums/authentication_factor.dart'; part 'src/enums/o_auth_provider.dart'; @@ -13,6 +14,5 @@ part 'src/enums/browser_permission.dart'; part 'src/enums/image_format.dart'; part 'src/enums/execution_method.dart'; part 'src/enums/image_gravity.dart'; -part 'src/enums/roles.dart'; part 'src/enums/execution_trigger.dart'; part 'src/enums/execution_status.dart'; diff --git a/lib/models.dart b/lib/models.dart index ca9bccc6..872d6d10 100644 --- a/lib/models.dart +++ b/lib/models.dart @@ -13,6 +13,7 @@ part 'src/models/file_list.dart'; part 'src/models/team_list.dart'; part 'src/models/membership_list.dart'; part 'src/models/execution_list.dart'; +part 'src/models/key_list.dart'; part 'src/models/country_list.dart'; part 'src/models/continent_list.dart'; part 'src/models/language_list.dart'; @@ -42,6 +43,7 @@ part 'src/models/file.dart'; part 'src/models/team.dart'; part 'src/models/membership.dart'; part 'src/models/execution.dart'; +part 'src/models/key.dart'; part 'src/models/country.dart'; part 'src/models/continent.dart'; part 'src/models/language.dart'; @@ -55,3 +57,5 @@ part 'src/models/mfa_factors.dart'; part 'src/models/transaction.dart'; part 'src/models/subscriber.dart'; part 'src/models/target.dart'; +part 'src/models/payment_method.dart'; +part 'src/models/payment_method_list.dart'; diff --git a/lib/services/account.dart b/lib/services/account.dart index f4dda775..28305140 100644 --- a/lib/services/account.dart +++ b/lib/services/account.dart @@ -134,6 +134,102 @@ class Account extends Service { return models.Jwt.fromMap(res.data); } + /// Get a list of all API keys from the current account. + Future listKeys({bool? total}) async { + const String apiPath = '/account/keys'; + + final Map apiParams = { + if (total != null) 'total': total, + }; + + final Map apiHeaders = {}; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.KeyList.fromMap(res.data); + } + + /// Create a new account API key. + Future createKey( + {required String name, + required List scopes, + String? expire}) async { + const String apiPath = '/account/keys'; + + final Map apiParams = { + 'name': name, + 'scopes': scopes.map((e) => e.value).toList(), + 'expire': expire, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Key.fromMap(res.data); + } + + /// Get a key by its unique ID. This endpoint returns details about a specific + /// API key in your account including it's scopes. + Future getKey({required String keyId}) async { + final String apiPath = '/account/keys/{keyId}'.replaceAll('{keyId}', keyId); + + final Map apiParams = {}; + + final Map apiHeaders = {}; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Key.fromMap(res.data); + } + + /// Update a key by its unique ID. Use this endpoint to update the name, + /// scopes, or expiration time of an API key. + Future updateKey( + {required String keyId, + required String name, + required List scopes, + String? expire}) async { + final String apiPath = '/account/keys/{keyId}'.replaceAll('{keyId}', keyId); + + final Map apiParams = { + 'name': name, + 'scopes': scopes.map((e) => e.value).toList(), + 'expire': expire, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Key.fromMap(res.data); + } + + /// Delete a key by its unique ID. Once deleted, the key can no longer be used + /// to authenticate API calls. + Future deleteKey({required String keyId}) async { + final String apiPath = '/account/keys/{keyId}'.replaceAll('{keyId}', keyId); + + 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 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, bool? total}) async { @@ -578,6 +674,140 @@ class Account extends Service { return models.User.fromMap(res.data); } + /// List payment methods for this account. + Future listPaymentMethods( + {List? queries}) async { + const String apiPath = '/account/payment-methods'; + + final Map apiParams = { + if (queries != null) 'queries': queries, + }; + + final Map apiHeaders = {}; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.PaymentMethodList.fromMap(res.data); + } + + /// Create a new payment method for the current user account. + Future createPaymentMethod() async { + const String apiPath = '/account/payment-methods'; + + 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.PaymentMethod.fromMap(res.data); + } + + /// Get a specific payment method for the user. + Future getPaymentMethod( + {required String paymentMethodId}) async { + final String apiPath = '/account/payment-methods/{paymentMethodId}' + .replaceAll('{paymentMethodId}', paymentMethodId); + + final Map apiParams = {}; + + final Map apiHeaders = {}; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.PaymentMethod.fromMap(res.data); + } + + /// Update a new payment method for the current user account. + Future updatePaymentMethod( + {required String paymentMethodId, + required int expiryMonth, + required int expiryYear, + String? state}) async { + final String apiPath = '/account/payment-methods/{paymentMethodId}' + .replaceAll('{paymentMethodId}', paymentMethodId); + + final Map apiParams = { + 'expiryMonth': expiryMonth, + 'expiryYear': expiryYear, + if (state != null) 'state': state, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.PaymentMethod.fromMap(res.data); + } + + /// Delete a specific payment method from a user's account. + Future deletePaymentMethod({required String paymentMethodId}) async { + final String apiPath = '/account/payment-methods/{paymentMethodId}' + .replaceAll('{paymentMethodId}', paymentMethodId); + + 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 payment method provider. + Future updatePaymentMethodProvider( + {required String paymentMethodId, + required String providerMethodId, + required String name, + String? state}) async { + final String apiPath = '/account/payment-methods/{paymentMethodId}/provider' + .replaceAll('{paymentMethodId}', paymentMethodId); + + final Map apiParams = { + 'providerMethodId': providerMethodId, + 'name': name, + 'state': state, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.PaymentMethod.fromMap(res.data); + } + + /// Update payment method mandate options. + Future updatePaymentMethodMandateOptions( + {required String paymentMethodId}) async { + final String apiPath = '/account/payment-methods/{paymentMethodId}/setup' + .replaceAll('{paymentMethodId}', paymentMethodId); + + 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.PaymentMethod.fromMap(res.data); + } + /// 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 diff --git a/lib/services/teams.dart b/lib/services/teams.dart index 988efd3e..6b4d5e39 100644 --- a/lib/services/teams.dart +++ b/lib/services/teams.dart @@ -149,7 +149,7 @@ class Teams extends Service { /// Future createMembership( {required String teamId, - required List roles, + required List roles, String? email, String? userId, String? phone, @@ -162,7 +162,7 @@ class Teams extends Service { if (email != null) 'email': email, if (userId != null) 'userId': userId, if (phone != null) 'phone': phone, - 'roles': roles.map((e) => e.value).toList(), + 'roles': roles, if (url != null) 'url': url, if (name != null) 'name': name, }; @@ -203,13 +203,13 @@ class Teams extends Service { Future updateMembership( {required String teamId, required String membershipId, - required List roles}) async { + required List roles}) async { final String apiPath = '/teams/{teamId}/memberships/{membershipId}' .replaceAll('{teamId}', teamId) .replaceAll('{membershipId}', membershipId); final Map apiParams = { - 'roles': roles.map((e) => e.value).toList(), + 'roles': roles, }; final Map apiHeaders = { diff --git a/lib/src/client_browser.dart b/lib/src/client_browser.dart index b5eea74f..d48b6c0e 100644 --- a/lib/src/client_browser.dart +++ b/lib/src/client_browser.dart @@ -40,7 +40,7 @@ class ClientBrowser extends ClientBase with ClientMixin { 'x-sdk-name': 'Flutter', 'x-sdk-platform': 'client', 'x-sdk-language': 'flutter', - 'x-sdk-version': '21.0.0', + 'x-sdk-version': '21.1.0', 'X-Appwrite-Response-Format': '1.8.0', }; diff --git a/lib/src/client_io.dart b/lib/src/client_io.dart index c06eb95d..7744a365 100644 --- a/lib/src/client_io.dart +++ b/lib/src/client_io.dart @@ -58,7 +58,7 @@ class ClientIO extends ClientBase with ClientMixin { 'x-sdk-name': 'Flutter', 'x-sdk-platform': 'client', 'x-sdk-language': 'flutter', - 'x-sdk-version': '21.0.0', + 'x-sdk-version': '21.1.0', 'X-Appwrite-Response-Format': '1.8.0', }; diff --git a/lib/src/enums/o_auth_provider.dart b/lib/src/enums/o_auth_provider.dart index fe3f1c74..539e3784 100644 --- a/lib/src/enums/o_auth_provider.dart +++ b/lib/src/enums/o_auth_provider.dart @@ -39,7 +39,9 @@ enum OAuthProvider { yammer(value: 'yammer'), yandex(value: 'yandex'), zoho(value: 'zoho'), - zoom(value: 'zoom'); + zoom(value: 'zoom'), + githubImagine(value: 'githubImagine'), + googleImagine(value: 'googleImagine'); const OAuthProvider({required this.value}); diff --git a/lib/src/enums/roles.dart b/lib/src/enums/roles.dart deleted file mode 100644 index af11fab2..00000000 --- a/lib/src/enums/roles.dart +++ /dev/null @@ -1,13 +0,0 @@ -part of '../../enums.dart'; - -enum Roles { - admin(value: 'admin'), - developer(value: 'developer'), - owner(value: 'owner'); - - const Roles({required this.value}); - - final String value; - - String toJson() => value; -} diff --git a/lib/src/enums/scopes.dart b/lib/src/enums/scopes.dart new file mode 100644 index 00000000..7d68f073 --- /dev/null +++ b/lib/src/enums/scopes.dart @@ -0,0 +1,13 @@ +part of '../../enums.dart'; + +enum Scopes { + account(value: 'account'), + teamsRead(value: 'teams.read'), + teamsWrite(value: 'teams.write'); + + const Scopes({required this.value}); + + final String value; + + String toJson() => value; +} diff --git a/lib/src/models/key.dart b/lib/src/models/key.dart new file mode 100644 index 00000000..15946090 --- /dev/null +++ b/lib/src/models/key.dart @@ -0,0 +1,72 @@ +part of '../../models.dart'; + +/// Key +class Key implements Model { + /// Key ID. + final String $id; + + /// Key creation date in ISO 8601 format. + final String $createdAt; + + /// Key update date in ISO 8601 format. + final String $updatedAt; + + /// Key name. + final String name; + + /// Key expiration date in ISO 8601 format. + final String expire; + + /// Allowed permission scopes. + final List scopes; + + /// Secret key. + final String secret; + + /// Most recent access date in ISO 8601 format. This attribute is only updated again after 24 hours. + final String accessedAt; + + /// List of SDK user agents that used this key. + final List sdks; + + Key({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.expire, + required this.scopes, + required this.secret, + required this.accessedAt, + required this.sdks, + }); + + factory Key.fromMap(Map map) { + return Key( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + expire: map['expire'].toString(), + scopes: List.from(map['scopes'] ?? []), + secret: map['secret'].toString(), + accessedAt: map['accessedAt'].toString(), + sdks: List.from(map['sdks'] ?? []), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "expire": expire, + "scopes": scopes, + "secret": secret, + "accessedAt": accessedAt, + "sdks": sdks, + }; + } +} diff --git a/lib/src/models/key_list.dart b/lib/src/models/key_list.dart new file mode 100644 index 00000000..127a6cd7 --- /dev/null +++ b/lib/src/models/key_list.dart @@ -0,0 +1,30 @@ +part of '../../models.dart'; + +/// API Keys List +class KeyList implements Model { + /// Total number of keys that matched your query. + final int total; + + /// List of keys. + final List keys; + + KeyList({ + required this.total, + required this.keys, + }); + + factory KeyList.fromMap(Map map) { + return KeyList( + total: map['total'], + keys: List.from(map['keys'].map((p) => Key.fromMap(p))), + ); + } + + @override + Map toMap() { + return { + "total": total, + "keys": keys.map((p) => p.toMap()).toList(), + }; + } +} diff --git a/lib/src/models/payment_method.dart b/lib/src/models/payment_method.dart new file mode 100644 index 00000000..0e18ac24 --- /dev/null +++ b/lib/src/models/payment_method.dart @@ -0,0 +1,138 @@ +part of '../../models.dart'; + +/// paymentMethod +class PaymentMethod implements Model { + /// Payment Method ID. + final String $id; + + /// Payment method creation time in ISO 8601 format. + final String $createdAt; + + /// Payment method update date in ISO 8601 format. + final String $updatedAt; + + /// Payment method permissions. [Learn more about permissions](/docs/permissions). + final List $permissions; + + /// Payment method ID from the payment provider + final String providerMethodId; + + /// Client secret hash for payment setup + final String clientSecret; + + /// User ID from the payment provider. + final String providerUserId; + + /// ID of the Team. + final String userId; + + /// Expiry month of the payment method. + final int expiryMonth; + + /// Expiry year of the payment method. + final int expiryYear; + + /// Last 4 digit of the payment method + final String last4; + + /// Payment method brand + final String brand; + + /// Name of the owner + final String name; + + /// Mandate ID of the payment method + final String mandateId; + + /// Country of the payment method + final String country; + + /// State of the payment method + final String state; + + /// Last payment error associated with the payment method. + final String lastError; + + /// True when it's the default payment method. + final bool xdefault; + + /// True when payment method has expired. + final bool expired; + + /// True when payment method has failed to process multiple times. + final bool failed; + + PaymentMethod({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.$permissions, + required this.providerMethodId, + required this.clientSecret, + required this.providerUserId, + required this.userId, + required this.expiryMonth, + required this.expiryYear, + required this.last4, + required this.brand, + required this.name, + required this.mandateId, + required this.country, + required this.state, + required this.lastError, + required this.xdefault, + required this.expired, + required this.failed, + }); + + factory PaymentMethod.fromMap(Map map) { + return PaymentMethod( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + $permissions: List.from(map['\$permissions'] ?? []), + providerMethodId: map['providerMethodId'].toString(), + clientSecret: map['clientSecret'].toString(), + providerUserId: map['providerUserId'].toString(), + userId: map['userId'].toString(), + expiryMonth: map['expiryMonth'], + expiryYear: map['expiryYear'], + last4: map['last4'].toString(), + brand: map['brand'].toString(), + name: map['name'].toString(), + mandateId: map['mandateId'].toString(), + country: map['country'].toString(), + state: map['state'].toString(), + lastError: map['lastError'].toString(), + xdefault: map['default'], + expired: map['expired'], + failed: map['failed'], + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "\$permissions": $permissions, + "providerMethodId": providerMethodId, + "clientSecret": clientSecret, + "providerUserId": providerUserId, + "userId": userId, + "expiryMonth": expiryMonth, + "expiryYear": expiryYear, + "last4": last4, + "brand": brand, + "name": name, + "mandateId": mandateId, + "country": country, + "state": state, + "lastError": lastError, + "default": xdefault, + "expired": expired, + "failed": failed, + }; + } +} diff --git a/lib/src/models/payment_method_list.dart b/lib/src/models/payment_method_list.dart new file mode 100644 index 00000000..830a81b8 --- /dev/null +++ b/lib/src/models/payment_method_list.dart @@ -0,0 +1,31 @@ +part of '../../models.dart'; + +/// Payment methods list +class PaymentMethodList implements Model { + /// Total number of paymentMethods that matched your query. + final int total; + + /// List of paymentMethods. + final List paymentMethods; + + PaymentMethodList({ + required this.total, + required this.paymentMethods, + }); + + factory PaymentMethodList.fromMap(Map map) { + return PaymentMethodList( + total: map['total'], + paymentMethods: List.from( + map['paymentMethods'].map((p) => PaymentMethod.fromMap(p))), + ); + } + + @override + Map toMap() { + return { + "total": total, + "paymentMethods": paymentMethods.map((p) => p.toMap()).toList(), + }; + } +} diff --git a/lib/src/realtime.dart b/lib/src/realtime.dart index 19114f08..18b9c573 100644 --- a/lib/src/realtime.dart +++ b/lib/src/realtime.dart @@ -51,7 +51,9 @@ abstract class Realtime extends Service { /// ]); /// ``` RealtimeSubscription subscribe( - List channels); // Object can be String or Channel + List channels, { + List queries = const [], + }); // Object can be String or Channel /// The [close code](https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.5) set when the WebSocket connection is closed. /// diff --git a/lib/src/realtime_base.dart b/lib/src/realtime_base.dart index e9dd5aa2..16e62d67 100644 --- a/lib/src/realtime_base.dart +++ b/lib/src/realtime_base.dart @@ -4,5 +4,7 @@ import 'realtime.dart'; abstract class RealtimeBase implements Realtime { @override RealtimeSubscription subscribe( - List channels); // Object can be String or Channel + List channels, { + List queries = const [], + }); // Object can be String or Channel } diff --git a/lib/src/realtime_browser.dart b/lib/src/realtime_browser.dart index 5d088906..8ae3c740 100644 --- a/lib/src/realtime_browser.dart +++ b/lib/src/realtime_browser.dart @@ -35,7 +35,10 @@ class RealtimeBrowser extends RealtimeBase with RealtimeMixin { } @override - RealtimeSubscription subscribe(List channels) { - return subscribeTo(channels); + RealtimeSubscription subscribe( + List channels, { + List queries = const [], + }) { + return subscribeTo(channels, queries); } } diff --git a/lib/src/realtime_io.dart b/lib/src/realtime_io.dart index 92de37f3..6040a5fc 100644 --- a/lib/src/realtime_io.dart +++ b/lib/src/realtime_io.dart @@ -43,8 +43,11 @@ class RealtimeIO extends RealtimeBase with RealtimeMixin { /// Use this method to subscribe to a channels and listen to /// realtime events on those channels @override - RealtimeSubscription subscribe(List channels) { - return subscribeTo(channels); + RealtimeSubscription subscribe( + List channels, { + List queries = const [], + }) { + return subscribeTo(channels, queries); } // https://github.com/jonataslaw/getsocket/blob/f25b3a264d8cc6f82458c949b86d286cd0343792/lib/src/io.dart#L104 @@ -57,7 +60,6 @@ class RealtimeIO extends RealtimeBase with RealtimeMixin { var client = HttpClient(context: SecurityContext()); client.badCertificateCallback = (X509Certificate cert, String host, int port) { - debugPrint('AppwriteRealtime: Allow self-signed certificate'); return true; }; diff --git a/lib/src/realtime_mixin.dart b/lib/src/realtime_mixin.dart index 7a5aa6b8..4fc4a564 100644 --- a/lib/src/realtime_mixin.dart +++ b/lib/src/realtime_mixin.dart @@ -15,13 +15,20 @@ typedef GetFallbackCookie = String? Function(); mixin RealtimeMixin { late Client client; - final Set _channels = {}; + // Slot-centric state: Map + // Each subscription stores its own channels and queries + final Map _subscriptions = {}; + // Map slot index -> subscriptionId (from backend) + final Map _slotToSubscriptionId = {}; + // Inverse map: subscriptionId -> slot index (for O(1) lookup) + final Map _subscriptionIdToSlot = {}; + int _subscriptionsCounter = 0; WebSocketChannel? _websok; String? _lastUrl; late WebSocketFactory getWebSocket; GetFallbackCookie? getFallbackCookie; + bool _pendingSocketRebuild = false; int? get closeCode => _websok?.closeCode; - final Map _subscriptions = {}; bool _reconnect = true; int _retries = 0; StreamSubscription? _websocketSubscription; @@ -52,7 +59,17 @@ mixin RealtimeMixin { } Future _createSocket() async { - if (_creatingSocket || _channels.isEmpty) return; + // Rebuild channels from all slots + final allChannels = {}; + for (var subscription in _subscriptions.values) { + allChannels.addAll(subscription.channels); + } + + if (_creatingSocket) { + _pendingSocketRebuild = true; + return; + } + if (allChannels.isEmpty) return; _creatingSocket = true; final uri = _prepareUri(); try { @@ -68,7 +85,6 @@ mixin RealtimeMixin { _lastUrl = uri.toString(); _websok = await getWebSocket(uri); } - debugPrint('subscription: $_lastUrl'); _retries = 0; _websocketSubscription = _websok?.stream.listen((response) { final data = RealtimeResponse.fromJson(response); @@ -77,8 +93,25 @@ mixin RealtimeMixin { handleError(data); break; case 'connected': - // channels, user? + // channels, user, subscriptions? final message = RealtimeResponseConnected.fromMap(data.data); + + // Store subscription ID mappings from backend + // Format: { "0": "sub_a1f9", "1": "sub_b83c", ... } + _slotToSubscriptionId.clear(); + _subscriptionIdToSlot.clear(); + if (data.data['subscriptions'] != null) { + final subscriptions = + data.data['subscriptions'] as Map; + subscriptions.forEach((slotStr, subscriptionId) { + final slot = int.tryParse(slotStr); + if (slot != null) { + _slotToSubscriptionId[slot] = subscriptionId.toString(); + _subscriptionIdToSlot[subscriptionId.toString()] = slot; + } + }); + } + if (message.user.isEmpty) { // send fallback cookie if exists final cookie = getFallbackCookie?.call(); @@ -97,10 +130,25 @@ mixin RealtimeMixin { debugPrint('Received heartbeat response from realtime server'); break; case 'event': - final message = RealtimeMessage.fromMap(data.data); - for (var subscription in _subscriptions.values) { - for (var channel in message.channels) { - if (subscription.channels.contains(channel)) { + final messageData = data.data as Map; + final message = RealtimeMessage.fromMap(messageData); + final subscriptions = + (messageData['subscriptions'] as List?) + ?.map((x) => x.toString()) + .toList() ?? + []; + + if (subscriptions.isEmpty) { + break; + } + + // Iterate over all matching subscriptionIds and call callback for each + for (var subscriptionId in subscriptions) { + // O(1) lookup using subscriptionId + final slot = _subscriptionIdToSlot[subscriptionId]; + if (slot != null) { + final subscription = _subscriptions[slot]; + if (subscription != null) { subscription.controller.add(message); } } @@ -125,6 +173,10 @@ mixin RealtimeMixin { _retry(); } finally { _creatingSocket = false; + if (_pendingSocketRebuild) { + _pendingSocketRebuild = false; + Future.microtask(_createSocket); + } } } @@ -154,16 +206,54 @@ mixin RealtimeMixin { "Please set endPointRealtime to connect to realtime server"); } var uri = Uri.parse(client.endPointRealtime!); - return Uri( - host: uri.host, - scheme: uri.scheme, - port: uri.port, - queryParameters: { - "project": client.config['project'], - "channels[]": _channels.toList(), - }, - path: "${uri.path}/realtime", - ); + + // Collect all unique channels from all slots + final allChannels = {}; + for (var subscription in _subscriptions.values) { + allChannels.addAll(subscription.channels); + } + + // Build query string from slots → channels → queries + // Format: channel[slot][]=query (each query sent as separate parameter) + // For each slot, repeat its queries under each channel it subscribes to + // Example: slot 1 → channels [tests, prod], queries [q1, q2] + // Produces: tests[1][]=q1&tests[1][]=q2&prod[1][]=q1&prod[1][]=q2 + var queryParams = + "project=${Uri.encodeComponent(client.config['project']!)}"; + + for (var channel in allChannels) { + final encodedChannel = Uri.encodeComponent(channel); + queryParams += "&channels[]=$encodedChannel"; + } + + // Hardcode the select query string since Query is not accessible in this mixin + // This is equivalent to Query.select(["*"]) which returns: {"method":"select","values":["*"]} + final selectAllQuery = '{"method":"select","values":["*"]}'; + for (var entry in _subscriptions.entries) { + final slot = entry.key; + final subscription = entry.value; + + // Get queries array - each query is a separate string + final queries = subscription.queries.isEmpty + ? [selectAllQuery] + : subscription.queries; + + // Repeat this slot's queries under each channel it subscribes to + // Each query is sent as a separate parameter: channel[slot][]=q1&channel[slot][]=q2 + for (var channel in subscription.channels) { + final encodedChannel = Uri.encodeComponent(channel); + for (var query in queries) { + final encodedQuery = Uri.encodeComponent(query); + queryParams += "&$encodedChannel[$slot][]=$encodedQuery"; + } + } + } + + final portPart = (uri.hasPort && uri.port != 80 && uri.port != 443) + ? ':${uri.port}' + : ''; + return Uri.parse( + "${uri.scheme}://${uri.host}$portPart${uri.path}/realtime?$queryParams"); } /// Convert channel value to string @@ -172,40 +262,53 @@ mixin RealtimeMixin { return channel is String ? channel : channel.toString(); } - RealtimeSubscription subscribeTo(List channels) { + RealtimeSubscription subscribeTo(List channels, + [List queries = const []]) { StreamController controller = StreamController.broadcast(); final channelStrings = channels.map((ch) => _channelToString(ch)).toList().cast(); - _channels.addAll(channelStrings); - Future.delayed(Duration.zero, () => _createSocket()); - int id = DateTime.now().microsecondsSinceEpoch; + final queryStrings = List.from(queries); + + // Allocate a new slot index + _subscriptionsCounter++; + final slot = _subscriptionsCounter; + + // Store slot-centric data: channels, queries, and callback belong to the slot + // queries is stored as List (array of query strings) + // No channel mutation occurs here - channels are derived from slots in _createSocket() RealtimeSubscription subscription = RealtimeSubscription( controller: controller, channels: channelStrings, + queries: queryStrings, close: () async { - _subscriptions.remove(id); + final subscriptionId = _slotToSubscriptionId[slot]; + _subscriptions.remove(slot); + _slotToSubscriptionId.remove(slot); + if (subscriptionId != null) { + _subscriptionIdToSlot.remove(subscriptionId); + } controller.close(); - _cleanup(channelStrings); - if (_channels.isNotEmpty) { + // Rebuild channels from remaining slots + final remainingChannels = {}; + for (var sub in _subscriptions.values) { + remainingChannels.addAll(sub.channels); + } + + if (remainingChannels.isNotEmpty) { await Future.delayed(Duration.zero, () => _createSocket()); } else { await _closeConnection(); } }); - _subscriptions[id] = subscription; + _subscriptions[slot] = subscription; + + Future.delayed(Duration.zero, () => _createSocket()); return subscription; } - void _cleanup(List channels) { - for (var channel in channels) { - bool found = _subscriptions.values - .any((subscription) => subscription.channels.contains(channel)); - if (!found) { - _channels.remove(channel); - } - } - } + // _cleanup is no longer needed - slots are removed directly in subscribeTo().close() + // Channels are automatically rebuilt from remaining slots in _createSocket() void handleError(RealtimeResponse response) { if (response.data['code'] == status.policyViolation) { diff --git a/lib/src/realtime_subscription.dart b/lib/src/realtime_subscription.dart index aaecd799..fa78dc42 100644 --- a/lib/src/realtime_subscription.dart +++ b/lib/src/realtime_subscription.dart @@ -12,6 +12,9 @@ class RealtimeSubscription { /// List of channels List channels; + /// List of query strings + List queries; + /// Closes the subscription final Future Function() close; @@ -19,6 +22,7 @@ class RealtimeSubscription { RealtimeSubscription({ required this.close, required this.channels, + required this.queries, required this.controller, }) : stream = controller.stream; } diff --git a/pubspec.yaml b/pubspec.yaml index 0da16c31..1cea5955 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: appwrite -version: 21.0.0 +version: 21.1.0 description: Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API homepage: https://appwrite.io repository: https://github.com/appwrite/sdk-for-flutter diff --git a/test/channel_test.dart b/test/channel_test.dart index 0a012f67..d4c0e1a7 100644 --- a/test/channel_test.dart +++ b/test/channel_test.dart @@ -5,7 +5,7 @@ void main() { group('database()', () { test('returns database channel with defaults', () { expect(Channel.database().collection().document().toString(), - 'databases.*.collections.*.documents.*'); + 'databases.*.collections.*.documents'); }); test('returns database channel with specific IDs', () { @@ -31,7 +31,7 @@ void main() { group('tablesdb()', () { test('returns tablesdb channel with defaults', () { expect(Channel.tablesdb().table().row().toString(), - 'tablesdb.*.tables.*.rows.*'); + 'tablesdb.*.tables.*.rows'); }); test('returns tablesdb channel with specific IDs', () { @@ -51,18 +51,14 @@ void main() { }); group('account()', () { - test('returns account channel with default', () { - expect(Channel.account(), 'account.*'); - }); - - test('returns account channel with specific user ID', () { - expect(Channel.account('user123'), 'account.user123'); + test('returns account channel', () { + expect(Channel.account(), 'account'); }); }); group('bucket()', () { test('returns buckets channel with defaults', () { - expect(Channel.bucket().file().toString(), 'buckets.*.files.*'); + expect(Channel.bucket().file().toString(), 'buckets.*.files'); }); test('returns buckets channel with specific IDs', () { @@ -78,18 +74,21 @@ void main() { group('functions()', () { test('returns functions channel with defaults', () { - expect(Channel.function().execution().toString(), - 'functions.*.executions.*'); + expect(Channel.function().toString(), 'functions.*'); }); test('returns functions channel with specific IDs', () { - expect(Channel.function('func1').execution('exec1').toString(), - 'functions.func1.executions.exec1'); + expect(Channel.function('func1').toString(), 'functions.func1'); + }); + }); + + group('executions()', () { + test('returns executions channel with defaults', () { + expect(Channel.execution().toString(), 'executions.*'); }); - test('returns functions channel with action', () { - expect(Channel.function('func1').execution('exec1').create().toString(), - 'functions.func1.executions.exec1.create'); + test('returns executions channel with specific IDs', () { + expect(Channel.execution('exec1').toString(), 'executions.exec1'); }); }); diff --git a/test/services/account_test.dart b/test/services/account_test.dart index c91bab89..1937a386 100644 --- a/test/services/account_test.dart +++ b/test/services/account_test.dart @@ -188,6 +188,104 @@ void main() { expect(response, isA()); }); + test('test method listKeys()', () async { + final Map data = { + 'total': 5, + 'keys': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.listKeys(); + expect(response, isA()); + }); + + test('test method createKey()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'My API Key', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'scopes': [], + 'secret': '919c2d18fb5d4...a2ae413da83346ad2', + 'accessedAt': '2020-10-15T06:38:00.000+00:00', + 'sdks': [], + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.createKey( + name: '', + scopes: [enums.Scopes.account], + ); + expect(response, isA()); + }); + + test('test method getKey()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'My API Key', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'scopes': [], + 'secret': '919c2d18fb5d4...a2ae413da83346ad2', + 'accessedAt': '2020-10-15T06:38:00.000+00:00', + 'sdks': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.getKey( + keyId: '', + ); + expect(response, isA()); + }); + + test('test method updateKey()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'My API Key', + 'expire': '2020-10-15T06:38:00.000+00:00', + 'scopes': [], + 'secret': '919c2d18fb5d4...a2ae413da83346ad2', + 'accessedAt': '2020-10-15T06:38:00.000+00:00', + 'sdks': [], + }; + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.updateKey( + keyId: '', + name: '', + scopes: [enums.Scopes.account], + ); + expect(response, isA()); + }); + + test('test method deleteKey()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.deleteKey( + keyId: '', + ); + }); + test('test method listLogs()', () async { final Map data = { 'total': 5, @@ -644,6 +742,204 @@ void main() { expect(response, isA()); }); + test('test method listPaymentMethods()', () async { + final Map data = { + 'total': 5, + 'paymentMethods': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.listPaymentMethods(); + expect(response, isA()); + }); + + test('test method createPaymentMethod()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'providerMethodId': 'abdk3ed3sdkfj', + 'clientSecret': 'seti_ddfe', + 'providerUserId': 'abdk3ed3sdkfj', + 'userId': '5e5ea5c16897e', + 'expiryMonth': 2, + 'expiryYear': 2024, + 'last4': '4242', + 'brand': 'visa', + 'name': 'John Doe', + 'mandateId': 'yxc', + 'country': 'de', + 'state': '', + 'lastError': 'Your card has insufficient funds.', + 'default': true, + 'expired': true, + 'failed': true, + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.createPaymentMethod(); + expect(response, isA()); + }); + + test('test method getPaymentMethod()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'providerMethodId': 'abdk3ed3sdkfj', + 'clientSecret': 'seti_ddfe', + 'providerUserId': 'abdk3ed3sdkfj', + 'userId': '5e5ea5c16897e', + 'expiryMonth': 2, + 'expiryYear': 2024, + 'last4': '4242', + 'brand': 'visa', + 'name': 'John Doe', + 'mandateId': 'yxc', + 'country': 'de', + 'state': '', + 'lastError': 'Your card has insufficient funds.', + 'default': true, + 'expired': true, + 'failed': true, + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.getPaymentMethod( + paymentMethodId: '', + ); + expect(response, isA()); + }); + + test('test method updatePaymentMethod()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'providerMethodId': 'abdk3ed3sdkfj', + 'clientSecret': 'seti_ddfe', + 'providerUserId': 'abdk3ed3sdkfj', + 'userId': '5e5ea5c16897e', + 'expiryMonth': 2, + 'expiryYear': 2024, + 'last4': '4242', + 'brand': 'visa', + 'name': 'John Doe', + 'mandateId': 'yxc', + 'country': 'de', + 'state': '', + 'lastError': 'Your card has insufficient funds.', + 'default': true, + 'expired': true, + 'failed': true, + }; + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.updatePaymentMethod( + paymentMethodId: '', + expiryMonth: 1, + expiryYear: 1, + ); + expect(response, isA()); + }); + + test('test method deletePaymentMethod()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.deletePaymentMethod( + paymentMethodId: '', + ); + }); + + test('test method updatePaymentMethodProvider()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'providerMethodId': 'abdk3ed3sdkfj', + 'clientSecret': 'seti_ddfe', + 'providerUserId': 'abdk3ed3sdkfj', + 'userId': '5e5ea5c16897e', + 'expiryMonth': 2, + 'expiryYear': 2024, + 'last4': '4242', + 'brand': 'visa', + 'name': 'John Doe', + 'mandateId': 'yxc', + 'country': 'de', + 'state': '', + 'lastError': 'Your card has insufficient funds.', + 'default': true, + 'expired': true, + 'failed': true, + }; + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.updatePaymentMethodProvider( + paymentMethodId: '', + providerMethodId: '', + name: '', + ); + expect(response, isA()); + }); + + test('test method updatePaymentMethodMandateOptions()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + '\$permissions': [], + 'providerMethodId': 'abdk3ed3sdkfj', + 'clientSecret': 'seti_ddfe', + 'providerUserId': 'abdk3ed3sdkfj', + 'userId': '5e5ea5c16897e', + 'expiryMonth': 2, + 'expiryYear': 2024, + 'last4': '4242', + 'brand': 'visa', + 'name': 'John Doe', + 'mandateId': 'yxc', + 'country': 'de', + 'state': '', + 'lastError': 'Your card has insufficient funds.', + 'default': true, + 'expired': true, + 'failed': true, + }; + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + final response = await account.updatePaymentMethodMandateOptions( + paymentMethodId: '', + ); + expect(response, isA()); + }); + test('test method updatePhone()', () async { final Map data = { '\$id': '5e5ea5c16897e', diff --git a/test/services/teams_test.dart b/test/services/teams_test.dart index 0b934243..9a2eb930 100644 --- a/test/services/teams_test.dart +++ b/test/services/teams_test.dart @@ -184,7 +184,7 @@ void main() { final response = await teams.createMembership( teamId: '', - roles: [enums.Roles.admin], + roles: [], ); expect(response, isA()); }); @@ -241,7 +241,7 @@ void main() { final response = await teams.updateMembership( teamId: '', membershipId: '', - roles: [enums.Roles.admin], + roles: [], ); expect(response, isA()); }); diff --git a/test/src/models/key_list_test.dart b/test/src/models/key_list_test.dart new file mode 100644 index 00000000..ab109f83 --- /dev/null +++ b/test/src/models/key_list_test.dart @@ -0,0 +1,19 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('KeyList', () { + test('model', () { + final model = KeyList( + total: 5, + keys: [], + ); + + final map = model.toMap(); + final result = KeyList.fromMap(map); + + expect(result.total, 5); + expect(result.keys, []); + }); + }); +} diff --git a/test/src/models/key_test.dart b/test/src/models/key_test.dart new file mode 100644 index 00000000..6afa084d --- /dev/null +++ b/test/src/models/key_test.dart @@ -0,0 +1,33 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('Key', () { + test('model', () { + final model = Key( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + name: 'My API Key', + expire: '2020-10-15T06:38:00.000+00:00', + scopes: [], + secret: '919c2d18fb5d4...a2ae413da83346ad2', + accessedAt: '2020-10-15T06:38:00.000+00:00', + sdks: [], + ); + + final map = model.toMap(); + final result = Key.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.name, 'My API Key'); + expect(result.expire, '2020-10-15T06:38:00.000+00:00'); + expect(result.scopes, []); + expect(result.secret, '919c2d18fb5d4...a2ae413da83346ad2'); + expect(result.accessedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.sdks, []); + }); + }); +} diff --git a/test/src/models/payment_method_list_test.dart b/test/src/models/payment_method_list_test.dart new file mode 100644 index 00000000..ed42e022 --- /dev/null +++ b/test/src/models/payment_method_list_test.dart @@ -0,0 +1,19 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('PaymentMethodList', () { + test('model', () { + final model = PaymentMethodList( + total: 5, + paymentMethods: [], + ); + + final map = model.toMap(); + final result = PaymentMethodList.fromMap(map); + + expect(result.total, 5); + expect(result.paymentMethods, []); + }); + }); +} diff --git a/test/src/models/payment_method_test.dart b/test/src/models/payment_method_test.dart new file mode 100644 index 00000000..7e52d8f5 --- /dev/null +++ b/test/src/models/payment_method_test.dart @@ -0,0 +1,55 @@ +import 'package:appwrite/models.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('PaymentMethod', () { + test('model', () { + final model = PaymentMethod( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + $permissions: [], + providerMethodId: 'abdk3ed3sdkfj', + clientSecret: 'seti_ddfe', + providerUserId: 'abdk3ed3sdkfj', + userId: '5e5ea5c16897e', + expiryMonth: 2, + expiryYear: 2024, + last4: '4242', + brand: 'visa', + name: 'John Doe', + mandateId: 'yxc', + country: 'de', + state: '', + lastError: 'Your card has insufficient funds.', + xdefault: true, + expired: true, + failed: true, + ); + + final map = model.toMap(); + final result = PaymentMethod.fromMap(map); + + expect(result.$id, '5e5ea5c16897e'); + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$updatedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.$permissions, []); + expect(result.providerMethodId, 'abdk3ed3sdkfj'); + expect(result.clientSecret, 'seti_ddfe'); + expect(result.providerUserId, 'abdk3ed3sdkfj'); + expect(result.userId, '5e5ea5c16897e'); + expect(result.expiryMonth, 2); + expect(result.expiryYear, 2024); + expect(result.last4, '4242'); + expect(result.brand, 'visa'); + expect(result.name, 'John Doe'); + expect(result.mandateId, 'yxc'); + expect(result.country, 'de'); + expect(result.state, ''); + expect(result.lastError, 'Your card has insufficient funds.'); + expect(result.xdefault, true); + expect(result.expired, true); + expect(result.failed, true); + }); + }); +} diff --git a/test/src/realtime_subscription_test.dart b/test/src/realtime_subscription_test.dart index f74ff253..421cdf78 100644 --- a/test/src/realtime_subscription_test.dart +++ b/test/src/realtime_subscription_test.dart @@ -10,7 +10,8 @@ void main() { final subscription = RealtimeSubscription( controller: mockStream, close: mockCloseFunction, - channels: ['documents']); + channels: ['documents'], + queries: const []); test('should have the correct stream and close function', () { expect(subscription.controller, equals(mockStream));