diff --git a/CHANGELOG.md b/CHANGELOG.md index 50e6f4eb..2837ae0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # Change Log +## 23.0.0 + +* [BREAKING] Renamed Webhook model fields: `security` → `tls`, `httpUser` → `authUsername`, `httpPass` → `authPassword`, `signatureKey` → `secret` +* [BREAKING] Renamed Webhook service parameters to match: `security` → `tls`, `httpUser` → `authUsername`, `httpPass` → `authPassword` +* [BREAKING] Renamed `Webhooks.updateSignature()` to `Webhooks.updateSecret()` with new optional `secret` parameter +* Added `Client.getHeaders()` method to retrieve request headers +* Added `secret` parameter to Webhook create and update methods +* Added `x` OAuth provider to `OAuthProvider` enum +* Added `userType` field to `Log` model +* Added `purge` parameter to `updateCollection` and `updateTable` for cache invalidation +* Added Project service: platform CRUD, key CRUD, protocol/service status management +* Added new models: `Key`, `KeyList`, `Project`, `DevKey`, `MockNumber`, `AuthProvider`, `PlatformAndroid`, `PlatformApple`, `PlatformLinux`, `PlatformList`, `PlatformWeb`, `PlatformWindows`, `BillingLimits`, `Block` +* Added new enums: `PlatformType`, `ProtocolId`, `ServiceId` +* Updated `BuildRuntime`, `Runtime` enums with `dart-3.11` and `flutter-3.41` +* Updated `Scopes` enum with `keysRead`, `keysWrite`, `platformsRead`, `platformsWrite` +* Updated `X-Appwrite-Response-Format` header to `1.9.1` +* Updated TTL description for list caching in Databases and TablesDB + ## 22.0.0 * [BREAKING] Changed `$sequence` type from `int` to `String` for `Row` and `Document` models diff --git a/README.md b/README.md index a4c65148..1af96c04 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Add this to your package's `pubspec.yaml` file: ```yml dependencies: - dart_appwrite: ^22.0.0 + dart_appwrite: ^23.0.0 ``` You can install packages from the command line: diff --git a/docs/examples/databases/create-datetime-attribute.md b/docs/examples/databases/create-datetime-attribute.md index f722c7ea..b3932277 100644 --- a/docs/examples/databases/create-datetime-attribute.md +++ b/docs/examples/databases/create-datetime-attribute.md @@ -13,7 +13,7 @@ AttributeDatetime result = await databases.createDatetimeAttribute( collectionId: '', key: '', xrequired: false, - xdefault: '', // (optional) + xdefault: '2020-10-15T06:38:00.000+00:00', // (optional) array: false, // (optional) ); ``` diff --git a/docs/examples/databases/get-attribute.md b/docs/examples/databases/get-attribute.md index 2159d188..49545146 100644 --- a/docs/examples/databases/get-attribute.md +++ b/docs/examples/databases/get-attribute.md @@ -8,7 +8,7 @@ Client client = Client() Databases databases = Databases(client); -AttributeBoolean result = await databases.getAttribute( +dynamic result = await databases.getAttribute( databaseId: '', collectionId: '', key: '', diff --git a/docs/examples/databases/update-collection.md b/docs/examples/databases/update-collection.md index b9ce24fa..b724e7b9 100644 --- a/docs/examples/databases/update-collection.md +++ b/docs/examples/databases/update-collection.md @@ -17,5 +17,6 @@ Collection result = await databases.updateCollection( permissions: [Permission.read(Role.any())], // (optional) documentSecurity: false, // (optional) enabled: false, // (optional) + purge: false, // (optional) ); ``` diff --git a/docs/examples/databases/update-datetime-attribute.md b/docs/examples/databases/update-datetime-attribute.md index dee3b520..4548b2b4 100644 --- a/docs/examples/databases/update-datetime-attribute.md +++ b/docs/examples/databases/update-datetime-attribute.md @@ -13,7 +13,7 @@ AttributeDatetime result = await databases.updateDatetimeAttribute( collectionId: '', key: '', xrequired: false, - xdefault: '', + xdefault: '2020-10-15T06:38:00.000+00:00', newKey: '', // (optional) ); ``` diff --git a/docs/examples/messaging/create-email.md b/docs/examples/messaging/create-email.md index fd9f1eab..f31414eb 100644 --- a/docs/examples/messaging/create-email.md +++ b/docs/examples/messaging/create-email.md @@ -20,6 +20,6 @@ Message result = await messaging.createEmail( attachments: [], // (optional) draft: false, // (optional) html: false, // (optional) - scheduledAt: '', // (optional) + scheduledAt: '2020-10-15T06:38:00.000+00:00', // (optional) ); ``` diff --git a/docs/examples/messaging/create-push.md b/docs/examples/messaging/create-push.md index 9908cdd3..e8bf76a9 100644 --- a/docs/examples/messaging/create-push.md +++ b/docs/examples/messaging/create-push.md @@ -25,7 +25,7 @@ Message result = await messaging.createPush( tag: '', // (optional) badge: 0, // (optional) draft: false, // (optional) - scheduledAt: '', // (optional) + scheduledAt: '2020-10-15T06:38:00.000+00:00', // (optional) contentAvailable: false, // (optional) critical: false, // (optional) priority: enums.MessagePriority.normal, // (optional) diff --git a/docs/examples/messaging/create-sms.md b/docs/examples/messaging/create-sms.md index 19968893..01591f57 100644 --- a/docs/examples/messaging/create-sms.md +++ b/docs/examples/messaging/create-sms.md @@ -15,6 +15,6 @@ Message result = await messaging.createSMS( users: [], // (optional) targets: [], // (optional) draft: false, // (optional) - scheduledAt: '', // (optional) + scheduledAt: '2020-10-15T06:38:00.000+00:00', // (optional) ); ``` diff --git a/docs/examples/messaging/update-email.md b/docs/examples/messaging/update-email.md index fa31f10b..c78a42fd 100644 --- a/docs/examples/messaging/update-email.md +++ b/docs/examples/messaging/update-email.md @@ -19,7 +19,7 @@ Message result = await messaging.updateEmail( html: false, // (optional) cc: [], // (optional) bcc: [], // (optional) - scheduledAt: '', // (optional) + scheduledAt: '2020-10-15T06:38:00.000+00:00', // (optional) attachments: [], // (optional) ); ``` diff --git a/docs/examples/messaging/update-push.md b/docs/examples/messaging/update-push.md index d367dca5..0d2145a9 100644 --- a/docs/examples/messaging/update-push.md +++ b/docs/examples/messaging/update-push.md @@ -25,7 +25,7 @@ Message result = await messaging.updatePush( tag: '', // (optional) badge: 0, // (optional) draft: false, // (optional) - scheduledAt: '', // (optional) + scheduledAt: '2020-10-15T06:38:00.000+00:00', // (optional) contentAvailable: false, // (optional) critical: false, // (optional) priority: enums.MessagePriority.normal, // (optional) diff --git a/docs/examples/messaging/update-sms.md b/docs/examples/messaging/update-sms.md index b33c1460..b8197294 100644 --- a/docs/examples/messaging/update-sms.md +++ b/docs/examples/messaging/update-sms.md @@ -15,6 +15,6 @@ Message result = await messaging.updateSMS( targets: [], // (optional) content: '', // (optional) draft: false, // (optional) - scheduledAt: '', // (optional) + scheduledAt: '2020-10-15T06:38:00.000+00:00', // (optional) ); ``` diff --git a/docs/examples/project/create-android-platform.md b/docs/examples/project/create-android-platform.md new file mode 100644 index 00000000..47a5c14b --- /dev/null +++ b/docs/examples/project/create-android-platform.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +PlatformAndroid result = await project.createAndroidPlatform( + platformId: '', + name: '', + applicationId: '', +); +``` diff --git a/docs/examples/project/create-apple-platform.md b/docs/examples/project/create-apple-platform.md new file mode 100644 index 00000000..8de12084 --- /dev/null +++ b/docs/examples/project/create-apple-platform.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +PlatformApple result = await project.createApplePlatform( + platformId: '', + name: '', + bundleIdentifier: '', +); +``` diff --git a/docs/examples/project/create-key.md b/docs/examples/project/create-key.md new file mode 100644 index 00000000..9c63e3bf --- /dev/null +++ b/docs/examples/project/create-key.md @@ -0,0 +1,18 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; +import 'package:dart_appwrite/enums.dart' as enums; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +Key result = await project.createKey( + keyId: '', + name: '', + scopes: [enums.Scopes.sessionsWrite], + expire: '2020-10-15T06:38:00.000+00:00', // (optional) +); +``` diff --git a/docs/examples/project/create-linux-platform.md b/docs/examples/project/create-linux-platform.md new file mode 100644 index 00000000..a7842305 --- /dev/null +++ b/docs/examples/project/create-linux-platform.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +PlatformLinux result = await project.createLinuxPlatform( + platformId: '', + name: '', + packageName: '', +); +``` diff --git a/docs/examples/project/create-web-platform.md b/docs/examples/project/create-web-platform.md new file mode 100644 index 00000000..12b157ee --- /dev/null +++ b/docs/examples/project/create-web-platform.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +PlatformWeb result = await project.createWebPlatform( + platformId: '', + name: '', + hostname: 'app.example.com', +); +``` diff --git a/docs/examples/project/create-windows-platform.md b/docs/examples/project/create-windows-platform.md new file mode 100644 index 00000000..f2b47ca0 --- /dev/null +++ b/docs/examples/project/create-windows-platform.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +PlatformWindows result = await project.createWindowsPlatform( + platformId: '', + name: '', + packageIdentifierName: '', +); +``` diff --git a/docs/examples/project/delete-key.md b/docs/examples/project/delete-key.md new file mode 100644 index 00000000..6617fa4d --- /dev/null +++ b/docs/examples/project/delete-key.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +await project.deleteKey( + keyId: '', +); +``` diff --git a/docs/examples/project/delete-platform.md b/docs/examples/project/delete-platform.md new file mode 100644 index 00000000..2a1a5985 --- /dev/null +++ b/docs/examples/project/delete-platform.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +await project.deletePlatform( + platformId: '', +); +``` diff --git a/docs/examples/project/get-key.md b/docs/examples/project/get-key.md new file mode 100644 index 00000000..77ee7bd3 --- /dev/null +++ b/docs/examples/project/get-key.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +Key result = await project.getKey( + keyId: '', +); +``` diff --git a/docs/examples/project/get-platform.md b/docs/examples/project/get-platform.md new file mode 100644 index 00000000..3874f13a --- /dev/null +++ b/docs/examples/project/get-platform.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +dynamic result = await project.getPlatform( + platformId: '', +); +``` diff --git a/docs/examples/project/list-keys.md b/docs/examples/project/list-keys.md new file mode 100644 index 00000000..6002f728 --- /dev/null +++ b/docs/examples/project/list-keys.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +KeyList result = await project.listKeys( + queries: [], // (optional) + total: false, // (optional) +); +``` diff --git a/docs/examples/project/list-platforms.md b/docs/examples/project/list-platforms.md new file mode 100644 index 00000000..9333ae36 --- /dev/null +++ b/docs/examples/project/list-platforms.md @@ -0,0 +1,15 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +PlatformList result = await project.listPlatforms( + queries: [], // (optional) + total: false, // (optional) +); +``` diff --git a/docs/examples/project/update-android-platform.md b/docs/examples/project/update-android-platform.md new file mode 100644 index 00000000..ee6eccf6 --- /dev/null +++ b/docs/examples/project/update-android-platform.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +PlatformAndroid result = await project.updateAndroidPlatform( + platformId: '', + name: '', + applicationId: '', +); +``` diff --git a/docs/examples/project/update-apple-platform.md b/docs/examples/project/update-apple-platform.md new file mode 100644 index 00000000..8feb3093 --- /dev/null +++ b/docs/examples/project/update-apple-platform.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +PlatformApple result = await project.updateApplePlatform( + platformId: '', + name: '', + bundleIdentifier: '', +); +``` diff --git a/docs/examples/project/update-key.md b/docs/examples/project/update-key.md new file mode 100644 index 00000000..83f4139c --- /dev/null +++ b/docs/examples/project/update-key.md @@ -0,0 +1,18 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; +import 'package:dart_appwrite/enums.dart' as enums; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +Key result = await project.updateKey( + keyId: '', + name: '', + scopes: [enums.Scopes.sessionsWrite], + expire: '2020-10-15T06:38:00.000+00:00', // (optional) +); +``` diff --git a/docs/examples/project/update-labels.md b/docs/examples/project/update-labels.md new file mode 100644 index 00000000..ec1b51ce --- /dev/null +++ b/docs/examples/project/update-labels.md @@ -0,0 +1,14 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +Project result = await project.updateLabels( + labels: [], +); +``` diff --git a/docs/examples/project/update-linux-platform.md b/docs/examples/project/update-linux-platform.md new file mode 100644 index 00000000..c93fe7a6 --- /dev/null +++ b/docs/examples/project/update-linux-platform.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +PlatformLinux result = await project.updateLinuxPlatform( + platformId: '', + name: '', + packageName: '', +); +``` diff --git a/docs/examples/project/update-protocol-status.md b/docs/examples/project/update-protocol-status.md new file mode 100644 index 00000000..721651af --- /dev/null +++ b/docs/examples/project/update-protocol-status.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; +import 'package:dart_appwrite/enums.dart' as enums; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +Project result = await project.updateProtocolStatus( + protocolId: enums.ProtocolId.rest, + enabled: false, +); +``` diff --git a/docs/examples/project/update-service-status.md b/docs/examples/project/update-service-status.md new file mode 100644 index 00000000..59487ddd --- /dev/null +++ b/docs/examples/project/update-service-status.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; +import 'package:dart_appwrite/enums.dart' as enums; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +Project result = await project.updateServiceStatus( + serviceId: enums.ServiceId.account, + enabled: false, +); +``` diff --git a/docs/examples/project/update-web-platform.md b/docs/examples/project/update-web-platform.md new file mode 100644 index 00000000..5de1cdc9 --- /dev/null +++ b/docs/examples/project/update-web-platform.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +PlatformWeb result = await project.updateWebPlatform( + platformId: '', + name: '', + hostname: 'app.example.com', +); +``` diff --git a/docs/examples/project/update-windows-platform.md b/docs/examples/project/update-windows-platform.md new file mode 100644 index 00000000..306d0024 --- /dev/null +++ b/docs/examples/project/update-windows-platform.md @@ -0,0 +1,16 @@ +```dart +import 'package:dart_appwrite/dart_appwrite.dart'; + +Client client = Client() + .setEndpoint('https://.cloud.appwrite.io/v1') // Your API Endpoint + .setProject('') // Your project ID + .setKey(''); // Your secret API key + +Project project = Project(client); + +PlatformWindows result = await project.updateWindowsPlatform( + platformId: '', + name: '', + packageIdentifierName: '', +); +``` diff --git a/docs/examples/tablesdb/create-datetime-column.md b/docs/examples/tablesdb/create-datetime-column.md index c30ee7a9..37d7b058 100644 --- a/docs/examples/tablesdb/create-datetime-column.md +++ b/docs/examples/tablesdb/create-datetime-column.md @@ -13,7 +13,7 @@ ColumnDatetime result = await tablesDB.createDatetimeColumn( tableId: '', key: '', xrequired: false, - xdefault: '', // (optional) + xdefault: '2020-10-15T06:38:00.000+00:00', // (optional) array: false, // (optional) ); ``` diff --git a/docs/examples/tablesdb/get-column.md b/docs/examples/tablesdb/get-column.md index 5c8e6875..fe45005c 100644 --- a/docs/examples/tablesdb/get-column.md +++ b/docs/examples/tablesdb/get-column.md @@ -8,7 +8,7 @@ Client client = Client() TablesDB tablesDB = TablesDB(client); -ColumnBoolean result = await tablesDB.getColumn( +dynamic result = await tablesDB.getColumn( databaseId: '', tableId: '', key: '', diff --git a/docs/examples/tablesdb/update-datetime-column.md b/docs/examples/tablesdb/update-datetime-column.md index 04a5f89a..9f4915da 100644 --- a/docs/examples/tablesdb/update-datetime-column.md +++ b/docs/examples/tablesdb/update-datetime-column.md @@ -13,7 +13,7 @@ ColumnDatetime result = await tablesDB.updateDatetimeColumn( tableId: '', key: '', xrequired: false, - xdefault: '', + xdefault: '2020-10-15T06:38:00.000+00:00', newKey: '', // (optional) ); ``` diff --git a/docs/examples/tablesdb/update-table.md b/docs/examples/tablesdb/update-table.md index 9cf9c05c..217da3f4 100644 --- a/docs/examples/tablesdb/update-table.md +++ b/docs/examples/tablesdb/update-table.md @@ -17,5 +17,6 @@ Table result = await tablesDB.updateTable( permissions: [Permission.read(Role.any())], // (optional) rowSecurity: false, // (optional) enabled: false, // (optional) + purge: false, // (optional) ); ``` diff --git a/docs/examples/tokens/create-file-token.md b/docs/examples/tokens/create-file-token.md index 8e08bf2c..5348736a 100644 --- a/docs/examples/tokens/create-file-token.md +++ b/docs/examples/tokens/create-file-token.md @@ -11,6 +11,6 @@ Tokens tokens = Tokens(client); ResourceToken result = await tokens.createFileToken( bucketId: '', fileId: '', - expire: '', // (optional) + expire: '2020-10-15T06:38:00.000+00:00', // (optional) ); ``` diff --git a/docs/examples/tokens/update.md b/docs/examples/tokens/update.md index 678d904b..6c0eb572 100644 --- a/docs/examples/tokens/update.md +++ b/docs/examples/tokens/update.md @@ -10,6 +10,6 @@ Tokens tokens = Tokens(client); ResourceToken result = await tokens.update( tokenId: '', - expire: '', // (optional) + expire: '2020-10-15T06:38:00.000+00:00', // (optional) ); ``` diff --git a/docs/examples/webhooks/create.md b/docs/examples/webhooks/create.md index 6e0ba71f..a401dffd 100644 --- a/docs/examples/webhooks/create.md +++ b/docs/examples/webhooks/create.md @@ -14,8 +14,9 @@ Webhook result = await webhooks.create( name: '', events: [], enabled: false, // (optional) - security: false, // (optional) - httpUser: '', // (optional) - httpPass: '', // (optional) + tls: false, // (optional) + authUsername: '', // (optional) + authPassword: '', // (optional) + secret: '', // (optional) ); ``` diff --git a/docs/examples/webhooks/update-signature.md b/docs/examples/webhooks/update-secret.md similarity index 80% rename from docs/examples/webhooks/update-signature.md rename to docs/examples/webhooks/update-secret.md index a73a1645..9aab19bf 100644 --- a/docs/examples/webhooks/update-signature.md +++ b/docs/examples/webhooks/update-secret.md @@ -8,7 +8,8 @@ Client client = Client() Webhooks webhooks = Webhooks(client); -Webhook result = await webhooks.updateSignature( +Webhook result = await webhooks.updateSecret( webhookId: '', + secret: '', // (optional) ); ``` diff --git a/docs/examples/webhooks/update.md b/docs/examples/webhooks/update.md index 2bd23106..7185c65a 100644 --- a/docs/examples/webhooks/update.md +++ b/docs/examples/webhooks/update.md @@ -14,8 +14,8 @@ Webhook result = await webhooks.update( url: '', events: [], enabled: false, // (optional) - security: false, // (optional) - httpUser: '', // (optional) - httpPass: '', // (optional) + tls: false, // (optional) + authUsername: '', // (optional) + authPassword: '', // (optional) ); ``` diff --git a/lib/enums.dart b/lib/enums.dart index 8c7bbec4..ac0ee55a 100644 --- a/lib/enums.dart +++ b/lib/enums.dart @@ -25,6 +25,8 @@ part 'src/enums/execution_method.dart'; part 'src/enums/name.dart'; part 'src/enums/message_priority.dart'; part 'src/enums/smtp_encryption.dart'; +part 'src/enums/protocol_id.dart'; +part 'src/enums/service_id.dart'; part 'src/enums/framework.dart'; part 'src/enums/build_runtime.dart'; part 'src/enums/adapter.dart'; @@ -40,6 +42,7 @@ part 'src/enums/index_status.dart'; part 'src/enums/deployment_status.dart'; part 'src/enums/execution_trigger.dart'; part 'src/enums/execution_status.dart'; +part 'src/enums/platform_type.dart'; part 'src/enums/health_antivirus_status.dart'; part 'src/enums/health_check_status.dart'; part 'src/enums/message_status.dart'; diff --git a/lib/models.dart b/lib/models.dart index d95ab223..5af3de6c 100644 --- a/lib/models.dart +++ b/lib/models.dart @@ -27,6 +27,7 @@ part 'src/models/runtime_list.dart'; part 'src/models/deployment_list.dart'; part 'src/models/execution_list.dart'; part 'src/models/webhook_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'; @@ -113,7 +114,18 @@ part 'src/models/framework.dart'; part 'src/models/framework_adapter.dart'; part 'src/models/deployment.dart'; part 'src/models/execution.dart'; +part 'src/models/project.dart'; part 'src/models/webhook.dart'; +part 'src/models/key.dart'; +part 'src/models/dev_key.dart'; +part 'src/models/mock_number.dart'; +part 'src/models/auth_provider.dart'; +part 'src/models/platform_web.dart'; +part 'src/models/platform_apple.dart'; +part 'src/models/platform_android.dart'; +part 'src/models/platform_windows.dart'; +part 'src/models/platform_linux.dart'; +part 'src/models/platform_list.dart'; part 'src/models/variable.dart'; part 'src/models/country.dart'; part 'src/models/continent.dart'; @@ -139,6 +151,8 @@ part 'src/models/subscriber.dart'; part 'src/models/target.dart'; part 'src/models/activity_event.dart'; part 'src/models/backup_archive.dart'; +part 'src/models/billing_limits.dart'; +part 'src/models/block.dart'; part 'src/models/backup_policy.dart'; part 'src/models/backup_restoration.dart'; part 'src/models/activity_event_list.dart'; diff --git a/lib/services/databases.dart b/lib/services/databases.dart index e0b8f289..76d6aa73 100644 --- a/lib/services/databases.dart +++ b/lib/services/databases.dart @@ -314,7 +314,8 @@ class Databases extends Service { String? name, List? permissions, bool? documentSecurity, - bool? enabled}) async { + bool? enabled, + bool? purge}) async { final String apiPath = '/databases/{databaseId}/collections/{collectionId}' .replaceAll('{databaseId}', databaseId) .replaceAll('{collectionId}', collectionId); @@ -324,6 +325,7 @@ class Databases extends Service { 'permissions': permissions, if (documentSecurity != null) 'documentSecurity': documentSecurity, if (enabled != null) 'enabled': enabled, + if (purge != null) 'purge': purge, }; final Map apiHeaders = { @@ -1539,7 +1541,7 @@ class Databases extends Service { /// Get attribute by ID. @Deprecated( 'This API has been deprecated since 1.8.0. Please use `TablesDB.getColumn` instead.') - Future getAttribute( + Future getAttribute( {required String databaseId, required String collectionId, required String key}) async { @@ -1556,7 +1558,47 @@ class Databases extends Service { final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - return res.data; + return () { + if (res.data is! Map) { + throw StateError( + 'Unable to match response to any expected response model.'); + } + + final response = res.data as Map; + if (response['type'] == 'string' && response['format'] == 'email') { + return models.AttributeEmail.fromMap(response); + } + if (response['type'] == 'string' && response['format'] == 'enum') { + return models.AttributeEnum.fromMap(response); + } + if (response['type'] == 'string' && response['format'] == 'url') { + return models.AttributeUrl.fromMap(response); + } + if (response['type'] == 'string' && response['format'] == 'ip') { + return models.AttributeIp.fromMap(response); + } + if (response['type'] == 'boolean') { + return models.AttributeBoolean.fromMap(response); + } + if (response['type'] == 'integer') { + return models.AttributeInteger.fromMap(response); + } + if (response['type'] == 'double') { + return models.AttributeFloat.fromMap(response); + } + if (response['type'] == 'datetime') { + return models.AttributeDatetime.fromMap(response); + } + if (response['type'] == 'relationship') { + return models.AttributeRelationship.fromMap(response); + } + if (response['type'] == 'string') { + return models.AttributeString.fromMap(response); + } + + throw StateError( + 'Unable to match response to any expected response model.'); + }(); } /// Deletes an attribute. diff --git a/lib/services/health.dart b/lib/services/health.dart index 097a7c36..7e83036f 100644 --- a/lib/services/health.dart +++ b/lib/services/health.dart @@ -114,6 +114,7 @@ class Health extends Service { /// Get the number of audit logs that are waiting to be processed in the /// Appwrite internal queue server. + /// Future getQueueAudits({int? threshold}) async { final String apiPath = '/health/queue/audits'; diff --git a/lib/services/project.dart b/lib/services/project.dart index c4912660..d47bb82d 100644 --- a/lib/services/project.dart +++ b/lib/services/project.dart @@ -5,6 +5,489 @@ part of '../dart_appwrite.dart'; class Project extends Service { Project(super.client); + /// Get a list of all API keys from the current project. + Future listKeys({List? queries, bool? total}) async { + final String apiPath = '/project/keys'; + + final Map apiParams = { + if (queries != null) 'queries': queries, + 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 API key. It's recommended to have multiple API keys with + /// strict scopes for separate functions within your project. + Future createKey( + {required String keyId, + required String name, + required List scopes, + String? expire}) async { + final String apiPath = '/project/keys'; + + final Map apiParams = { + 'keyId': keyId, + '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. + Future getKey({required String keyId}) async { + final String apiPath = '/project/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 = '/project/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 = '/project/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; + } + + /// Update the project labels. Labels can be used to easily filter projects in + /// an organization. + Future updateLabels({required List labels}) async { + final String apiPath = '/project/labels'; + + final Map apiParams = { + 'labels': labels, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Project.fromMap(res.data); + } + + /// Get a list of all platforms in the project. This endpoint returns an array + /// of all platforms and their configurations. + Future listPlatforms( + {List? queries, bool? total}) async { + final String apiPath = '/project/platforms'; + + final Map apiParams = { + if (queries != null) 'queries': queries, + if (total != null) 'total': total, + }; + + final Map apiHeaders = {}; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.PlatformList.fromMap(res.data); + } + + /// Create a new Android platform for your project. Use this endpoint to + /// register a new Android platform where your users will run your application + /// which will interact with the Appwrite API. + Future createAndroidPlatform( + {required String platformId, + required String name, + required String applicationId}) async { + final String apiPath = '/project/platforms/android'; + + final Map apiParams = { + 'platformId': platformId, + 'name': name, + 'applicationId': applicationId, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.PlatformAndroid.fromMap(res.data); + } + + /// Update an Android platform by its unique ID. Use this endpoint to update + /// the platform's name or application ID. + Future updateAndroidPlatform( + {required String platformId, + required String name, + required String applicationId}) async { + final String apiPath = '/project/platforms/android/{platformId}' + .replaceAll('{platformId}', platformId); + + final Map apiParams = { + 'name': name, + 'applicationId': applicationId, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.PlatformAndroid.fromMap(res.data); + } + + /// Create a new Apple platform for your project. Use this endpoint to register + /// a new Apple platform where your users will run your application which will + /// interact with the Appwrite API. + Future createApplePlatform( + {required String platformId, + required String name, + required String bundleIdentifier}) async { + final String apiPath = '/project/platforms/apple'; + + final Map apiParams = { + 'platformId': platformId, + 'name': name, + 'bundleIdentifier': bundleIdentifier, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.PlatformApple.fromMap(res.data); + } + + /// Update an Apple platform by its unique ID. Use this endpoint to update the + /// platform's name or bundle identifier. + Future updateApplePlatform( + {required String platformId, + required String name, + required String bundleIdentifier}) async { + final String apiPath = '/project/platforms/apple/{platformId}' + .replaceAll('{platformId}', platformId); + + final Map apiParams = { + 'name': name, + 'bundleIdentifier': bundleIdentifier, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.PlatformApple.fromMap(res.data); + } + + /// Create a new Linux platform for your project. Use this endpoint to register + /// a new Linux platform where your users will run your application which will + /// interact with the Appwrite API. + Future createLinuxPlatform( + {required String platformId, + required String name, + required String packageName}) async { + final String apiPath = '/project/platforms/linux'; + + final Map apiParams = { + 'platformId': platformId, + 'name': name, + 'packageName': packageName, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.PlatformLinux.fromMap(res.data); + } + + /// Update a Linux platform by its unique ID. Use this endpoint to update the + /// platform's name or package name. + Future updateLinuxPlatform( + {required String platformId, + required String name, + required String packageName}) async { + final String apiPath = '/project/platforms/linux/{platformId}' + .replaceAll('{platformId}', platformId); + + final Map apiParams = { + 'name': name, + 'packageName': packageName, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.PlatformLinux.fromMap(res.data); + } + + /// Create a new web platform for your project. Use this endpoint to register a + /// new platform where your users will run your application which will interact + /// with the Appwrite API. + Future createWebPlatform( + {required String platformId, + required String name, + required String hostname}) async { + final String apiPath = '/project/platforms/web'; + + final Map apiParams = { + 'platformId': platformId, + 'name': name, + 'hostname': hostname, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.PlatformWeb.fromMap(res.data); + } + + /// Update a web platform by its unique ID. Use this endpoint to update the + /// platform's name or hostname. + Future updateWebPlatform( + {required String platformId, + required String name, + required String hostname}) async { + final String apiPath = '/project/platforms/web/{platformId}' + .replaceAll('{platformId}', platformId); + + final Map apiParams = { + 'name': name, + 'hostname': hostname, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.PlatformWeb.fromMap(res.data); + } + + /// Create a new Windows platform for your project. Use this endpoint to + /// register a new Windows platform where your users will run your application + /// which will interact with the Appwrite API. + Future createWindowsPlatform( + {required String platformId, + required String name, + required String packageIdentifierName}) async { + final String apiPath = '/project/platforms/windows'; + + final Map apiParams = { + 'platformId': platformId, + 'name': name, + 'packageIdentifierName': packageIdentifierName, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.post, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.PlatformWindows.fromMap(res.data); + } + + /// Update a Windows platform by its unique ID. Use this endpoint to update the + /// platform's name or package identifier name. + Future updateWindowsPlatform( + {required String platformId, + required String name, + required String packageIdentifierName}) async { + final String apiPath = '/project/platforms/windows/{platformId}' + .replaceAll('{platformId}', platformId); + + final Map apiParams = { + 'name': name, + 'packageIdentifierName': packageIdentifierName, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.put, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.PlatformWindows.fromMap(res.data); + } + + /// Get a platform by its unique ID. This endpoint returns the platform's + /// details, including its name, type, and key configurations. + Future getPlatform({required String platformId}) async { + final String apiPath = '/project/platforms/{platformId}' + .replaceAll('{platformId}', platformId); + + final Map apiParams = {}; + + final Map apiHeaders = {}; + + final res = await client.call(HttpMethod.get, + path: apiPath, params: apiParams, headers: apiHeaders); + + return () { + if (res.data is! Map) { + throw StateError( + 'Unable to match response to any expected response model.'); + } + + final response = res.data as Map; + if (response['type'] == 'web') { + return models.PlatformWeb.fromMap(response); + } + if (response['type'] == 'apple') { + return models.PlatformApple.fromMap(response); + } + if (response['type'] == 'android') { + return models.PlatformAndroid.fromMap(response); + } + if (response['type'] == 'windows') { + return models.PlatformWindows.fromMap(response); + } + if (response['type'] == 'linux') { + return models.PlatformLinux.fromMap(response); + } + + throw StateError( + 'Unable to match response to any expected response model.'); + }(); + } + + /// Delete a platform by its unique ID. This endpoint removes the platform and + /// all its configurations from the project. + Future deletePlatform({required String platformId}) async { + final String apiPath = '/project/platforms/{platformId}' + .replaceAll('{platformId}', platformId); + + 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 the status of a specific protocol. Use this endpoint to enable or + /// disable a protocol in your project. + Future updateProtocolStatus( + {required enums.ProtocolId protocolId, required bool enabled}) async { + final String apiPath = '/project/protocols/{protocolId}/status' + .replaceAll('{protocolId}', protocolId.value); + + final Map apiParams = { + 'enabled': enabled, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Project.fromMap(res.data); + } + + /// Update the status of a specific service. Use this endpoint to enable or + /// disable a service in your project. + Future updateServiceStatus( + {required enums.ServiceId serviceId, required bool enabled}) async { + final String apiPath = '/project/services/{serviceId}/status' + .replaceAll('{serviceId}', serviceId.value); + + final Map apiParams = { + 'enabled': enabled, + }; + + final Map apiHeaders = { + 'content-type': 'application/json', + }; + + final res = await client.call(HttpMethod.patch, + path: apiPath, params: apiParams, headers: apiHeaders); + + return models.Project.fromMap(res.data); + } + /// Get a list of all project environment variables. Future listVariables( {List? queries, bool? total}) async { diff --git a/lib/services/tables_db.dart b/lib/services/tables_db.dart index 9c6ebddb..384b3804 100644 --- a/lib/services/tables_db.dart +++ b/lib/services/tables_db.dart @@ -294,7 +294,8 @@ class TablesDB extends Service { String? name, List? permissions, bool? rowSecurity, - bool? enabled}) async { + bool? enabled, + bool? purge}) async { final String apiPath = '/tablesdb/{databaseId}/tables/{tableId}' .replaceAll('{databaseId}', databaseId) .replaceAll('{tableId}', tableId); @@ -304,6 +305,7 @@ class TablesDB extends Service { 'permissions': permissions, if (rowSecurity != null) 'rowSecurity': rowSecurity, if (enabled != null) 'enabled': enabled, + if (purge != null) 'purge': purge, }; final Map apiHeaders = { @@ -1431,7 +1433,7 @@ class TablesDB extends Service { } /// Get column by ID. - Future getColumn( + Future getColumn( {required String databaseId, required String tableId, required String key}) async { @@ -1448,7 +1450,47 @@ class TablesDB extends Service { final res = await client.call(HttpMethod.get, path: apiPath, params: apiParams, headers: apiHeaders); - return res.data; + return () { + if (res.data is! Map) { + throw StateError( + 'Unable to match response to any expected response model.'); + } + + final response = res.data as Map; + if (response['type'] == 'string' && response['format'] == 'email') { + return models.ColumnEmail.fromMap(response); + } + if (response['type'] == 'string' && response['format'] == 'enum') { + return models.ColumnEnum.fromMap(response); + } + if (response['type'] == 'string' && response['format'] == 'url') { + return models.ColumnUrl.fromMap(response); + } + if (response['type'] == 'string' && response['format'] == 'ip') { + return models.ColumnIp.fromMap(response); + } + if (response['type'] == 'boolean') { + return models.ColumnBoolean.fromMap(response); + } + if (response['type'] == 'integer') { + return models.ColumnInteger.fromMap(response); + } + if (response['type'] == 'double') { + return models.ColumnFloat.fromMap(response); + } + if (response['type'] == 'datetime') { + return models.ColumnDatetime.fromMap(response); + } + if (response['type'] == 'relationship') { + return models.ColumnRelationship.fromMap(response); + } + if (response['type'] == 'string') { + return models.ColumnString.fromMap(response); + } + + throw StateError( + 'Unable to match response to any expected response model.'); + }(); } /// Deletes a column. diff --git a/lib/services/webhooks.dart b/lib/services/webhooks.dart index a5ea340b..ae5dd16f 100644 --- a/lib/services/webhooks.dart +++ b/lib/services/webhooks.dart @@ -29,9 +29,10 @@ class Webhooks extends Service { required String name, required List events, bool? enabled, - bool? security, - String? httpUser, - String? httpPass}) async { + bool? tls, + String? authUsername, + String? authPassword, + String? secret}) async { final String apiPath = '/webhooks'; final Map apiParams = { @@ -40,9 +41,10 @@ class Webhooks extends Service { 'name': name, 'events': events, if (enabled != null) 'enabled': enabled, - if (security != null) 'security': security, - if (httpUser != null) 'httpUser': httpUser, - if (httpPass != null) 'httpPass': httpPass, + if (tls != null) 'tls': tls, + if (authUsername != null) 'authUsername': authUsername, + if (authPassword != null) 'authPassword': authPassword, + 'secret': secret, }; final Map apiHeaders = { @@ -79,9 +81,9 @@ class Webhooks extends Service { required String url, required List events, bool? enabled, - bool? security, - String? httpUser, - String? httpPass}) async { + bool? tls, + String? authUsername, + String? authPassword}) async { final String apiPath = '/webhooks/{webhookId}'.replaceAll('{webhookId}', webhookId); @@ -90,9 +92,9 @@ class Webhooks extends Service { 'url': url, 'events': events, if (enabled != null) 'enabled': enabled, - if (security != null) 'security': security, - if (httpUser != null) 'httpUser': httpUser, - if (httpPass != null) 'httpPass': httpPass, + if (tls != null) 'tls': tls, + if (authUsername != null) 'authUsername': authUsername, + if (authPassword != null) 'authPassword': authPassword, }; final Map apiHeaders = { @@ -123,14 +125,17 @@ class Webhooks extends Service { return res.data; } - /// Update the webhook signature key. This endpoint can be used to regenerate - /// the signature key used to sign and validate payload deliveries for a - /// specific webhook. - Future updateSignature({required String webhookId}) async { + /// Update the webhook signing key. This endpoint can be used to regenerate the + /// signing key used to sign and validate payload deliveries for a specific + /// webhook. + Future updateSecret( + {required String webhookId, String? secret}) async { final String apiPath = - '/webhooks/{webhookId}/signature'.replaceAll('{webhookId}', webhookId); + '/webhooks/{webhookId}/secret'.replaceAll('{webhookId}', webhookId); - final Map apiParams = {}; + final Map apiParams = { + 'secret': secret, + }; final Map apiHeaders = { 'content-type': 'application/json', diff --git a/lib/src/client.dart b/lib/src/client.dart index ea877a5d..98cffb92 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -83,6 +83,9 @@ abstract class Client { /// Add headers that should be sent with all API calls. Client addHeader(String key, String value); + /// Get the current request headers. + Map getHeaders(); + /// Sends a "ping" request to Appwrite to verify connectivity. Future ping(); diff --git a/lib/src/client_base.dart b/lib/src/client_base.dart index 337a893b..772f1e40 100644 --- a/lib/src/client_base.dart +++ b/lib/src/client_base.dart @@ -46,6 +46,9 @@ abstract class ClientBase implements Client { @override ClientBase addHeader(String key, String value); + @override + Map getHeaders(); + @override Future ping() async { final String apiPath = '/ping'; diff --git a/lib/src/client_browser.dart b/lib/src/client_browser.dart index d289c7c3..d1a34e1c 100644 --- a/lib/src/client_browser.dart +++ b/lib/src/client_browser.dart @@ -33,8 +33,8 @@ class ClientBrowser extends ClientBase with ClientMixin { 'x-sdk-name': 'Dart', 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', - 'x-sdk-version': '22.0.0', - 'X-Appwrite-Response-Format': '1.9.0', + 'x-sdk-version': '23.0.0', + 'X-Appwrite-Response-Format': '1.9.1', }; config = {}; @@ -138,6 +138,11 @@ class ClientBrowser extends ClientBase with ClientMixin { return this; } + @override + Map getHeaders() { + return Map.from(_headers!); + } + @override Future webAuth(Uri url) async { final request = http.Request('GET', url); diff --git a/lib/src/client_io.dart b/lib/src/client_io.dart index d1de9871..4f23d9c2 100644 --- a/lib/src/client_io.dart +++ b/lib/src/client_io.dart @@ -42,10 +42,10 @@ class ClientIO extends ClientBase with ClientMixin { 'x-sdk-name': 'Dart', 'x-sdk-platform': 'server', 'x-sdk-language': 'dart', - 'x-sdk-version': '22.0.0', + 'x-sdk-version': '23.0.0', 'user-agent': - 'AppwriteDartSDK/22.0.0 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', - 'X-Appwrite-Response-Format': '1.9.0', + 'AppwriteDartSDK/23.0.0 (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})', + 'X-Appwrite-Response-Format': '1.9.1', }; config = {}; @@ -151,6 +151,11 @@ class ClientIO extends ClientBase with ClientMixin { return this; } + @override + Map getHeaders() { + return Map.from(_headers!); + } + @override Future chunkedUpload({ required String path, diff --git a/lib/src/enums/build_runtime.dart b/lib/src/enums/build_runtime.dart index edb1089b..df242bdf 100644 --- a/lib/src/enums/build_runtime.dart +++ b/lib/src/enums/build_runtime.dart @@ -49,6 +49,7 @@ enum BuildRuntime { dart38(value: 'dart-3.8'), dart39(value: 'dart-3.9'), dart310(value: 'dart-3.10'), + dart311(value: 'dart-3.11'), dotnet60(value: 'dotnet-6.0'), dotnet70(value: 'dotnet-7.0'), dotnet80(value: 'dotnet-8.0'), @@ -86,7 +87,8 @@ enum BuildRuntime { flutter329(value: 'flutter-3.29'), flutter332(value: 'flutter-3.32'), flutter335(value: 'flutter-3.35'), - flutter338(value: 'flutter-3.38'); + flutter338(value: 'flutter-3.38'), + flutter341(value: 'flutter-3.41'); const BuildRuntime({required this.value}); diff --git a/lib/src/enums/o_auth_provider.dart b/lib/src/enums/o_auth_provider.dart index fe3f1c74..dc08c932 100644 --- a/lib/src/enums/o_auth_provider.dart +++ b/lib/src/enums/o_auth_provider.dart @@ -35,6 +35,7 @@ enum OAuthProvider { tradeshiftBox(value: 'tradeshiftBox'), twitch(value: 'twitch'), wordpress(value: 'wordpress'), + x(value: 'x'), yahoo(value: 'yahoo'), yammer(value: 'yammer'), yandex(value: 'yandex'), diff --git a/lib/src/enums/platform_type.dart b/lib/src/enums/platform_type.dart new file mode 100644 index 00000000..8b3c8f08 --- /dev/null +++ b/lib/src/enums/platform_type.dart @@ -0,0 +1,15 @@ +part of '../../enums.dart'; + +enum PlatformType { + windows(value: 'windows'), + apple(value: 'apple'), + android(value: 'android'), + linux(value: 'linux'), + web(value: 'web'); + + const PlatformType({required this.value}); + + final String value; + + String toJson() => value; +} diff --git a/lib/src/enums/protocol_id.dart b/lib/src/enums/protocol_id.dart new file mode 100644 index 00000000..a9dea8c9 --- /dev/null +++ b/lib/src/enums/protocol_id.dart @@ -0,0 +1,13 @@ +part of '../../enums.dart'; + +enum ProtocolId { + rest(value: 'rest'), + graphql(value: 'graphql'), + websocket(value: 'websocket'); + + const ProtocolId({required this.value}); + + final String value; + + String toJson() => value; +} diff --git a/lib/src/enums/runtime.dart b/lib/src/enums/runtime.dart index eb0c578d..232aca0a 100644 --- a/lib/src/enums/runtime.dart +++ b/lib/src/enums/runtime.dart @@ -49,6 +49,7 @@ enum Runtime { dart38(value: 'dart-3.8'), dart39(value: 'dart-3.9'), dart310(value: 'dart-3.10'), + dart311(value: 'dart-3.11'), dotnet60(value: 'dotnet-6.0'), dotnet70(value: 'dotnet-7.0'), dotnet80(value: 'dotnet-8.0'), @@ -86,7 +87,8 @@ enum Runtime { flutter329(value: 'flutter-3.29'), flutter332(value: 'flutter-3.32'), flutter335(value: 'flutter-3.35'), - flutter338(value: 'flutter-3.38'); + flutter338(value: 'flutter-3.38'), + flutter341(value: 'flutter-3.41'); const Runtime({required this.value}); diff --git a/lib/src/enums/scopes.dart b/lib/src/enums/scopes.dart index adf56959..64a925ec 100644 --- a/lib/src/enums/scopes.dart +++ b/lib/src/enums/scopes.dart @@ -62,6 +62,10 @@ enum Scopes { webhooksWrite(value: 'webhooks.write'), projectRead(value: 'project.read'), projectWrite(value: 'project.write'), + keysRead(value: 'keys.read'), + keysWrite(value: 'keys.write'), + platformsRead(value: 'platforms.read'), + platformsWrite(value: 'platforms.write'), policiesWrite(value: 'policies.write'), policiesRead(value: 'policies.read'), archivesRead(value: 'archives.read'), diff --git a/lib/src/enums/service_id.dart b/lib/src/enums/service_id.dart new file mode 100644 index 00000000..35c37fe8 --- /dev/null +++ b/lib/src/enums/service_id.dart @@ -0,0 +1,27 @@ +part of '../../enums.dart'; + +enum ServiceId { + account(value: 'account'), + avatars(value: 'avatars'), + databases(value: 'databases'), + tablesdb(value: 'tablesdb'), + locale(value: 'locale'), + health(value: 'health'), + project(value: 'project'), + storage(value: 'storage'), + teams(value: 'teams'), + users(value: 'users'), + vcs(value: 'vcs'), + sites(value: 'sites'), + functions(value: 'functions'), + proxy(value: 'proxy'), + graphql(value: 'graphql'), + migrations(value: 'migrations'), + messaging(value: 'messaging'); + + const ServiceId({required this.value}); + + final String value; + + String toJson() => value; +} diff --git a/lib/src/models/auth_provider.dart b/lib/src/models/auth_provider.dart new file mode 100644 index 00000000..5ef17597 --- /dev/null +++ b/lib/src/models/auth_provider.dart @@ -0,0 +1,48 @@ +part of '../../models.dart'; + +/// AuthProvider +class AuthProvider implements Model { + /// Auth Provider. + final String key; + + /// Auth Provider name. + final String name; + + /// OAuth 2.0 application ID. + final String appId; + + /// OAuth 2.0 application secret. Might be JSON string if provider requires extra configuration. + final String secret; + + /// Auth Provider is active and can be used to create session. + final bool enabled; + + AuthProvider({ + required this.key, + required this.name, + required this.appId, + required this.secret, + required this.enabled, + }); + + factory AuthProvider.fromMap(Map map) { + return AuthProvider( + key: map['key'].toString(), + name: map['name'].toString(), + appId: map['appId'].toString(), + secret: map['secret'].toString(), + enabled: map['enabled'], + ); + } + + @override + Map toMap() { + return { + "key": key, + "name": name, + "appId": appId, + "secret": secret, + "enabled": enabled, + }; + } +} diff --git a/lib/src/models/billing_limits.dart b/lib/src/models/billing_limits.dart new file mode 100644 index 00000000..e775c07e --- /dev/null +++ b/lib/src/models/billing_limits.dart @@ -0,0 +1,66 @@ +part of '../../models.dart'; + +/// BillingLimits +class BillingLimits implements Model { + /// Bandwidth limit + final int bandwidth; + + /// Storage limit + final int storage; + + /// Users limit + final int users; + + /// Executions limit + final int executions; + + /// GBHours limit + final int GBHours; + + /// Image transformations limit + final int imageTransformations; + + /// Auth phone limit + final int authPhone; + + /// Budget limit percentage + final int budgetLimit; + + BillingLimits({ + required this.bandwidth, + required this.storage, + required this.users, + required this.executions, + required this.GBHours, + required this.imageTransformations, + required this.authPhone, + required this.budgetLimit, + }); + + factory BillingLimits.fromMap(Map map) { + return BillingLimits( + bandwidth: map['bandwidth'], + storage: map['storage'], + users: map['users'], + executions: map['executions'], + GBHours: map['GBHours'], + imageTransformations: map['imageTransformations'], + authPhone: map['authPhone'], + budgetLimit: map['budgetLimit'], + ); + } + + @override + Map toMap() { + return { + "bandwidth": bandwidth, + "storage": storage, + "users": users, + "executions": executions, + "GBHours": GBHours, + "imageTransformations": imageTransformations, + "authPhone": authPhone, + "budgetLimit": budgetLimit, + }; + } +} diff --git a/lib/src/models/block.dart b/lib/src/models/block.dart new file mode 100644 index 00000000..448021a1 --- /dev/null +++ b/lib/src/models/block.dart @@ -0,0 +1,48 @@ +part of '../../models.dart'; + +/// Block +class Block implements Model { + /// Block creation date in ISO 8601 format. + final String $createdAt; + + /// Resource type that is blocked + final String resourceType; + + /// Resource identifier that is blocked + final String resourceId; + + /// Reason for the block. Can be null if no reason was provided. + final String? reason; + + /// Block expiration date in ISO 8601 format. Can be null if the block does not expire. + final String? expiredAt; + + Block({ + required this.$createdAt, + required this.resourceType, + required this.resourceId, + this.reason, + this.expiredAt, + }); + + factory Block.fromMap(Map map) { + return Block( + $createdAt: map['\$createdAt'].toString(), + resourceType: map['resourceType'].toString(), + resourceId: map['resourceId'].toString(), + reason: map['reason']?.toString(), + expiredAt: map['expiredAt']?.toString(), + ); + } + + @override + Map toMap() { + return { + "\$createdAt": $createdAt, + "resourceType": resourceType, + "resourceId": resourceId, + "reason": reason, + "expiredAt": expiredAt, + }; + } +} diff --git a/lib/src/models/dev_key.dart b/lib/src/models/dev_key.dart new file mode 100644 index 00000000..06f90c5b --- /dev/null +++ b/lib/src/models/dev_key.dart @@ -0,0 +1,66 @@ +part of '../../models.dart'; + +/// DevKey +class DevKey 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; + + /// 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; + + DevKey({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.expire, + required this.secret, + required this.accessedAt, + required this.sdks, + }); + + factory DevKey.fromMap(Map map) { + return DevKey( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + expire: map['expire'].toString(), + 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, + "secret": secret, + "accessedAt": accessedAt, + "sdks": sdks, + }; + } +} 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/log.dart b/lib/src/models/log.dart index ff67b75b..572cce50 100644 --- a/lib/src/models/log.dart +++ b/lib/src/models/log.dart @@ -17,6 +17,9 @@ class Log implements Model { /// API mode when event triggered. final String mode; + /// User type who triggered the audit log. Possible values: user, admin, guest, keyProject, keyAccount, keyOrganization. + final String userType; + /// IP session in use when the session was created. final String ip; @@ -71,6 +74,7 @@ class Log implements Model { required this.userEmail, required this.userName, required this.mode, + required this.userType, required this.ip, required this.time, required this.osCode, @@ -96,6 +100,7 @@ class Log implements Model { userEmail: map['userEmail'].toString(), userName: map['userName'].toString(), mode: map['mode'].toString(), + userType: map['userType'].toString(), ip: map['ip'].toString(), time: map['time'].toString(), osCode: map['osCode'].toString(), @@ -123,6 +128,7 @@ class Log implements Model { "userEmail": userEmail, "userName": userName, "mode": mode, + "userType": userType, "ip": ip, "time": time, "osCode": osCode, diff --git a/lib/src/models/mock_number.dart b/lib/src/models/mock_number.dart new file mode 100644 index 00000000..a87a8281 --- /dev/null +++ b/lib/src/models/mock_number.dart @@ -0,0 +1,30 @@ +part of '../../models.dart'; + +/// Mock Number +class MockNumber implements Model { + /// Mock phone number for testing phone authentication. Useful for testing phone authentication without sending an SMS. + final String phone; + + /// Mock OTP for the number. + final String otp; + + MockNumber({ + required this.phone, + required this.otp, + }); + + factory MockNumber.fromMap(Map map) { + return MockNumber( + phone: map['phone'].toString(), + otp: map['otp'].toString(), + ); + } + + @override + Map toMap() { + return { + "phone": phone, + "otp": otp, + }; + } +} diff --git a/lib/src/models/platform_android.dart b/lib/src/models/platform_android.dart new file mode 100644 index 00000000..0f8d940d --- /dev/null +++ b/lib/src/models/platform_android.dart @@ -0,0 +1,54 @@ +part of '../../models.dart'; + +/// Platform Android +class PlatformAndroid implements Model { + /// Platform ID. + final String $id; + + /// Platform creation date in ISO 8601 format. + final String $createdAt; + + /// Platform update date in ISO 8601 format. + final String $updatedAt; + + /// Platform name. + final String name; + + /// Platform type. Possible values are: windows, apple, android, linux, web. + final enums.PlatformType type; + + /// Android application ID. + final String applicationId; + + PlatformAndroid({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.type, + required this.applicationId, + }); + + factory PlatformAndroid.fromMap(Map map) { + return PlatformAndroid( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + type: enums.PlatformType.values.firstWhere((e) => e.value == map['type']), + applicationId: map['applicationId'].toString(), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "type": type.value, + "applicationId": applicationId, + }; + } +} diff --git a/lib/src/models/platform_apple.dart b/lib/src/models/platform_apple.dart new file mode 100644 index 00000000..b421c15d --- /dev/null +++ b/lib/src/models/platform_apple.dart @@ -0,0 +1,54 @@ +part of '../../models.dart'; + +/// Platform Apple +class PlatformApple implements Model { + /// Platform ID. + final String $id; + + /// Platform creation date in ISO 8601 format. + final String $createdAt; + + /// Platform update date in ISO 8601 format. + final String $updatedAt; + + /// Platform name. + final String name; + + /// Platform type. Possible values are: windows, apple, android, linux, web. + final enums.PlatformType type; + + /// Apple bundle identifier. + final String bundleIdentifier; + + PlatformApple({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.type, + required this.bundleIdentifier, + }); + + factory PlatformApple.fromMap(Map map) { + return PlatformApple( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + type: enums.PlatformType.values.firstWhere((e) => e.value == map['type']), + bundleIdentifier: map['bundleIdentifier'].toString(), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "type": type.value, + "bundleIdentifier": bundleIdentifier, + }; + } +} diff --git a/lib/src/models/platform_linux.dart b/lib/src/models/platform_linux.dart new file mode 100644 index 00000000..45131dde --- /dev/null +++ b/lib/src/models/platform_linux.dart @@ -0,0 +1,54 @@ +part of '../../models.dart'; + +/// Platform Linux +class PlatformLinux implements Model { + /// Platform ID. + final String $id; + + /// Platform creation date in ISO 8601 format. + final String $createdAt; + + /// Platform update date in ISO 8601 format. + final String $updatedAt; + + /// Platform name. + final String name; + + /// Platform type. Possible values are: windows, apple, android, linux, web. + final enums.PlatformType type; + + /// Linux package name. + final String packageName; + + PlatformLinux({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.type, + required this.packageName, + }); + + factory PlatformLinux.fromMap(Map map) { + return PlatformLinux( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + type: enums.PlatformType.values.firstWhere((e) => e.value == map['type']), + packageName: map['packageName'].toString(), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "type": type.value, + "packageName": packageName, + }; + } +} diff --git a/lib/src/models/platform_list.dart b/lib/src/models/platform_list.dart new file mode 100644 index 00000000..1c5f8b02 --- /dev/null +++ b/lib/src/models/platform_list.dart @@ -0,0 +1,30 @@ +part of '../../models.dart'; + +/// Platforms List +class PlatformList implements Model { + /// Total number of platforms in the given project. + final int total; + + /// List of platforms. + final List platforms; + + PlatformList({ + required this.total, + required this.platforms, + }); + + factory PlatformList.fromMap(Map map) { + return PlatformList( + total: map['total'], + platforms: List.from(map['platforms'] ?? []), + ); + } + + @override + Map toMap() { + return { + "total": total, + "platforms": platforms, + }; + } +} diff --git a/lib/src/models/platform_web.dart b/lib/src/models/platform_web.dart new file mode 100644 index 00000000..630225df --- /dev/null +++ b/lib/src/models/platform_web.dart @@ -0,0 +1,54 @@ +part of '../../models.dart'; + +/// Platform Web +class PlatformWeb implements Model { + /// Platform ID. + final String $id; + + /// Platform creation date in ISO 8601 format. + final String $createdAt; + + /// Platform update date in ISO 8601 format. + final String $updatedAt; + + /// Platform name. + final String name; + + /// Platform type. Possible values are: windows, apple, android, linux, web. + final enums.PlatformType type; + + /// Web app hostname. Empty string for other platforms. + final String hostname; + + PlatformWeb({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.type, + required this.hostname, + }); + + factory PlatformWeb.fromMap(Map map) { + return PlatformWeb( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + type: enums.PlatformType.values.firstWhere((e) => e.value == map['type']), + hostname: map['hostname'].toString(), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "type": type.value, + "hostname": hostname, + }; + } +} diff --git a/lib/src/models/platform_windows.dart b/lib/src/models/platform_windows.dart new file mode 100644 index 00000000..957533a4 --- /dev/null +++ b/lib/src/models/platform_windows.dart @@ -0,0 +1,54 @@ +part of '../../models.dart'; + +/// Platform Windows +class PlatformWindows implements Model { + /// Platform ID. + final String $id; + + /// Platform creation date in ISO 8601 format. + final String $createdAt; + + /// Platform update date in ISO 8601 format. + final String $updatedAt; + + /// Platform name. + final String name; + + /// Platform type. Possible values are: windows, apple, android, linux, web. + final enums.PlatformType type; + + /// Windows package identifier name. + final String packageIdentifierName; + + PlatformWindows({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.type, + required this.packageIdentifierName, + }); + + factory PlatformWindows.fromMap(Map map) { + return PlatformWindows( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + type: enums.PlatformType.values.firstWhere((e) => e.value == map['type']), + packageIdentifierName: map['packageIdentifierName'].toString(), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "type": type.value, + "packageIdentifierName": packageIdentifierName, + }; + } +} diff --git a/lib/src/models/project.dart b/lib/src/models/project.dart new file mode 100644 index 00000000..10f84064 --- /dev/null +++ b/lib/src/models/project.dart @@ -0,0 +1,489 @@ +part of '../../models.dart'; + +/// Project +class Project implements Model { + /// Project ID. + final String $id; + + /// Project creation date in ISO 8601 format. + final String $createdAt; + + /// Project update date in ISO 8601 format. + final String $updatedAt; + + /// Project name. + final String name; + + /// Project description. + final String description; + + /// Project team ID. + final String teamId; + + /// Project logo file ID. + final String logo; + + /// Project website URL. + final String url; + + /// Company legal name. + final String legalName; + + /// Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format. + final String legalCountry; + + /// State name. + final String legalState; + + /// City name. + final String legalCity; + + /// Company Address. + final String legalAddress; + + /// Company Tax ID. + final String legalTaxId; + + /// Session duration in seconds. + final int authDuration; + + /// Max users allowed. 0 is unlimited. + final int authLimit; + + /// Max sessions allowed per user. 100 maximum. + final int authSessionsLimit; + + /// Max allowed passwords in the history list per user. Max passwords limit allowed in history is 20. Use 0 for disabling password history. + final int authPasswordHistory; + + /// Whether or not to check user's password against most commonly used passwords. + final bool authPasswordDictionary; + + /// Whether or not to check the user password for similarity with their personal data. + final bool authPersonalDataCheck; + + /// Whether or not to disallow disposable email addresses during signup and email updates. + final bool authDisposableEmails; + + /// Whether or not to require canonical email addresses during signup and email updates. + final bool authCanonicalEmails; + + /// Whether or not to disallow free email addresses during signup and email updates. + final bool authFreeEmails; + + /// An array of mock numbers and their corresponding verification codes (OTPs). + final List authMockNumbers; + + /// Whether or not to send session alert emails to users. + final bool authSessionAlerts; + + /// Whether or not to show user names in the teams membership response. + final bool authMembershipsUserName; + + /// Whether or not to show user emails in the teams membership response. + final bool authMembershipsUserEmail; + + /// Whether or not to show user MFA status in the teams membership response. + final bool authMembershipsMfa; + + /// Whether or not all existing sessions should be invalidated on password change + final bool authInvalidateSessions; + + /// List of Auth Providers. + final List oAuthProviders; + + /// List of Platforms. + final List platforms; + + /// List of Webhooks. + final List webhooks; + + /// List of API Keys. + final List keys; + + /// List of dev keys. + final List devKeys; + + /// Status for custom SMTP + final bool smtpEnabled; + + /// SMTP sender name + final String smtpSenderName; + + /// SMTP sender email + final String smtpSenderEmail; + + /// SMTP reply to email + final String smtpReplyTo; + + /// SMTP server host name + final String smtpHost; + + /// SMTP server port + final int smtpPort; + + /// SMTP server username + final String smtpUsername; + + /// SMTP server password + final String smtpPassword; + + /// SMTP server secure protocol + final String smtpSecure; + + /// Number of times the ping was received for this project. + final int pingCount; + + /// Last ping datetime in ISO 8601 format. + final String pingedAt; + + /// Labels for the project. + final List labels; + + /// Project status + final String status; + + /// Email/Password auth method status + final bool authEmailPassword; + + /// Magic URL auth method status + final bool authUsersAuthMagicURL; + + /// Email (OTP) auth method status + final bool authEmailOtp; + + /// Anonymous auth method status + final bool authAnonymous; + + /// Invites auth method status + final bool authInvites; + + /// JWT auth method status + final bool authJWT; + + /// Phone auth method status + final bool authPhone; + + /// Account service status + final bool serviceStatusForAccount; + + /// Avatars service status + final bool serviceStatusForAvatars; + + /// Databases (legacy) service status + final bool serviceStatusForDatabases; + + /// TablesDB service status + final bool serviceStatusForTablesdb; + + /// Locale service status + final bool serviceStatusForLocale; + + /// Health service status + final bool serviceStatusForHealth; + + /// Project service status + final bool serviceStatusForProject; + + /// Storage service status + final bool serviceStatusForStorage; + + /// Teams service status + final bool serviceStatusForTeams; + + /// Users service status + final bool serviceStatusForUsers; + + /// VCS service status + final bool serviceStatusForVcs; + + /// Sites service status + final bool serviceStatusForSites; + + /// Functions service status + final bool serviceStatusForFunctions; + + /// Proxy service status + final bool serviceStatusForProxy; + + /// GraphQL service status + final bool serviceStatusForGraphql; + + /// Migrations service status + final bool serviceStatusForMigrations; + + /// Messaging service status + final bool serviceStatusForMessaging; + + /// REST protocol status + final bool protocolStatusForRest; + + /// GraphQL protocol status + final bool protocolStatusForGraphql; + + /// Websocket protocol status + final bool protocolStatusForWebsocket; + + /// Project region + final String region; + + /// Billing limits reached + final BillingLimits billingLimits; + + /// Project blocks information + final List blocks; + + /// Last time the project was accessed via console. Used with plan's projectInactivityDays to determine if project is paused. + final String consoleAccessedAt; + + Project({ + required this.$id, + required this.$createdAt, + required this.$updatedAt, + required this.name, + required this.description, + required this.teamId, + required this.logo, + required this.url, + required this.legalName, + required this.legalCountry, + required this.legalState, + required this.legalCity, + required this.legalAddress, + required this.legalTaxId, + required this.authDuration, + required this.authLimit, + required this.authSessionsLimit, + required this.authPasswordHistory, + required this.authPasswordDictionary, + required this.authPersonalDataCheck, + required this.authDisposableEmails, + required this.authCanonicalEmails, + required this.authFreeEmails, + required this.authMockNumbers, + required this.authSessionAlerts, + required this.authMembershipsUserName, + required this.authMembershipsUserEmail, + required this.authMembershipsMfa, + required this.authInvalidateSessions, + required this.oAuthProviders, + required this.platforms, + required this.webhooks, + required this.keys, + required this.devKeys, + required this.smtpEnabled, + required this.smtpSenderName, + required this.smtpSenderEmail, + required this.smtpReplyTo, + required this.smtpHost, + required this.smtpPort, + required this.smtpUsername, + required this.smtpPassword, + required this.smtpSecure, + required this.pingCount, + required this.pingedAt, + required this.labels, + required this.status, + required this.authEmailPassword, + required this.authUsersAuthMagicURL, + required this.authEmailOtp, + required this.authAnonymous, + required this.authInvites, + required this.authJWT, + required this.authPhone, + required this.serviceStatusForAccount, + required this.serviceStatusForAvatars, + required this.serviceStatusForDatabases, + required this.serviceStatusForTablesdb, + required this.serviceStatusForLocale, + required this.serviceStatusForHealth, + required this.serviceStatusForProject, + required this.serviceStatusForStorage, + required this.serviceStatusForTeams, + required this.serviceStatusForUsers, + required this.serviceStatusForVcs, + required this.serviceStatusForSites, + required this.serviceStatusForFunctions, + required this.serviceStatusForProxy, + required this.serviceStatusForGraphql, + required this.serviceStatusForMigrations, + required this.serviceStatusForMessaging, + required this.protocolStatusForRest, + required this.protocolStatusForGraphql, + required this.protocolStatusForWebsocket, + required this.region, + required this.billingLimits, + required this.blocks, + required this.consoleAccessedAt, + }); + + factory Project.fromMap(Map map) { + return Project( + $id: map['\$id'].toString(), + $createdAt: map['\$createdAt'].toString(), + $updatedAt: map['\$updatedAt'].toString(), + name: map['name'].toString(), + description: map['description'].toString(), + teamId: map['teamId'].toString(), + logo: map['logo'].toString(), + url: map['url'].toString(), + legalName: map['legalName'].toString(), + legalCountry: map['legalCountry'].toString(), + legalState: map['legalState'].toString(), + legalCity: map['legalCity'].toString(), + legalAddress: map['legalAddress'].toString(), + legalTaxId: map['legalTaxId'].toString(), + authDuration: map['authDuration'], + authLimit: map['authLimit'], + authSessionsLimit: map['authSessionsLimit'], + authPasswordHistory: map['authPasswordHistory'], + authPasswordDictionary: map['authPasswordDictionary'], + authPersonalDataCheck: map['authPersonalDataCheck'], + authDisposableEmails: map['authDisposableEmails'], + authCanonicalEmails: map['authCanonicalEmails'], + authFreeEmails: map['authFreeEmails'], + authMockNumbers: List.from( + map['authMockNumbers'].map((p) => MockNumber.fromMap(p))), + authSessionAlerts: map['authSessionAlerts'], + authMembershipsUserName: map['authMembershipsUserName'], + authMembershipsUserEmail: map['authMembershipsUserEmail'], + authMembershipsMfa: map['authMembershipsMfa'], + authInvalidateSessions: map['authInvalidateSessions'], + oAuthProviders: List.from( + map['oAuthProviders'].map((p) => AuthProvider.fromMap(p))), + platforms: List.from(map['platforms'] ?? []), + webhooks: + List.from(map['webhooks'].map((p) => Webhook.fromMap(p))), + keys: List.from(map['keys'].map((p) => Key.fromMap(p))), + devKeys: List.from(map['devKeys'].map((p) => DevKey.fromMap(p))), + smtpEnabled: map['smtpEnabled'], + smtpSenderName: map['smtpSenderName'].toString(), + smtpSenderEmail: map['smtpSenderEmail'].toString(), + smtpReplyTo: map['smtpReplyTo'].toString(), + smtpHost: map['smtpHost'].toString(), + smtpPort: map['smtpPort'], + smtpUsername: map['smtpUsername'].toString(), + smtpPassword: map['smtpPassword'].toString(), + smtpSecure: map['smtpSecure'].toString(), + pingCount: map['pingCount'], + pingedAt: map['pingedAt'].toString(), + labels: List.from(map['labels'] ?? []), + status: map['status'].toString(), + authEmailPassword: map['authEmailPassword'], + authUsersAuthMagicURL: map['authUsersAuthMagicURL'], + authEmailOtp: map['authEmailOtp'], + authAnonymous: map['authAnonymous'], + authInvites: map['authInvites'], + authJWT: map['authJWT'], + authPhone: map['authPhone'], + serviceStatusForAccount: map['serviceStatusForAccount'], + serviceStatusForAvatars: map['serviceStatusForAvatars'], + serviceStatusForDatabases: map['serviceStatusForDatabases'], + serviceStatusForTablesdb: map['serviceStatusForTablesdb'], + serviceStatusForLocale: map['serviceStatusForLocale'], + serviceStatusForHealth: map['serviceStatusForHealth'], + serviceStatusForProject: map['serviceStatusForProject'], + serviceStatusForStorage: map['serviceStatusForStorage'], + serviceStatusForTeams: map['serviceStatusForTeams'], + serviceStatusForUsers: map['serviceStatusForUsers'], + serviceStatusForVcs: map['serviceStatusForVcs'], + serviceStatusForSites: map['serviceStatusForSites'], + serviceStatusForFunctions: map['serviceStatusForFunctions'], + serviceStatusForProxy: map['serviceStatusForProxy'], + serviceStatusForGraphql: map['serviceStatusForGraphql'], + serviceStatusForMigrations: map['serviceStatusForMigrations'], + serviceStatusForMessaging: map['serviceStatusForMessaging'], + protocolStatusForRest: map['protocolStatusForRest'], + protocolStatusForGraphql: map['protocolStatusForGraphql'], + protocolStatusForWebsocket: map['protocolStatusForWebsocket'], + region: map['region'].toString(), + billingLimits: BillingLimits.fromMap(map['billingLimits']), + blocks: List.from(map['blocks'].map((p) => Block.fromMap(p))), + consoleAccessedAt: map['consoleAccessedAt'].toString(), + ); + } + + @override + Map toMap() { + return { + "\$id": $id, + "\$createdAt": $createdAt, + "\$updatedAt": $updatedAt, + "name": name, + "description": description, + "teamId": teamId, + "logo": logo, + "url": url, + "legalName": legalName, + "legalCountry": legalCountry, + "legalState": legalState, + "legalCity": legalCity, + "legalAddress": legalAddress, + "legalTaxId": legalTaxId, + "authDuration": authDuration, + "authLimit": authLimit, + "authSessionsLimit": authSessionsLimit, + "authPasswordHistory": authPasswordHistory, + "authPasswordDictionary": authPasswordDictionary, + "authPersonalDataCheck": authPersonalDataCheck, + "authDisposableEmails": authDisposableEmails, + "authCanonicalEmails": authCanonicalEmails, + "authFreeEmails": authFreeEmails, + "authMockNumbers": authMockNumbers.map((p) => p.toMap()).toList(), + "authSessionAlerts": authSessionAlerts, + "authMembershipsUserName": authMembershipsUserName, + "authMembershipsUserEmail": authMembershipsUserEmail, + "authMembershipsMfa": authMembershipsMfa, + "authInvalidateSessions": authInvalidateSessions, + "oAuthProviders": oAuthProviders.map((p) => p.toMap()).toList(), + "platforms": platforms, + "webhooks": webhooks.map((p) => p.toMap()).toList(), + "keys": keys.map((p) => p.toMap()).toList(), + "devKeys": devKeys.map((p) => p.toMap()).toList(), + "smtpEnabled": smtpEnabled, + "smtpSenderName": smtpSenderName, + "smtpSenderEmail": smtpSenderEmail, + "smtpReplyTo": smtpReplyTo, + "smtpHost": smtpHost, + "smtpPort": smtpPort, + "smtpUsername": smtpUsername, + "smtpPassword": smtpPassword, + "smtpSecure": smtpSecure, + "pingCount": pingCount, + "pingedAt": pingedAt, + "labels": labels, + "status": status, + "authEmailPassword": authEmailPassword, + "authUsersAuthMagicURL": authUsersAuthMagicURL, + "authEmailOtp": authEmailOtp, + "authAnonymous": authAnonymous, + "authInvites": authInvites, + "authJWT": authJWT, + "authPhone": authPhone, + "serviceStatusForAccount": serviceStatusForAccount, + "serviceStatusForAvatars": serviceStatusForAvatars, + "serviceStatusForDatabases": serviceStatusForDatabases, + "serviceStatusForTablesdb": serviceStatusForTablesdb, + "serviceStatusForLocale": serviceStatusForLocale, + "serviceStatusForHealth": serviceStatusForHealth, + "serviceStatusForProject": serviceStatusForProject, + "serviceStatusForStorage": serviceStatusForStorage, + "serviceStatusForTeams": serviceStatusForTeams, + "serviceStatusForUsers": serviceStatusForUsers, + "serviceStatusForVcs": serviceStatusForVcs, + "serviceStatusForSites": serviceStatusForSites, + "serviceStatusForFunctions": serviceStatusForFunctions, + "serviceStatusForProxy": serviceStatusForProxy, + "serviceStatusForGraphql": serviceStatusForGraphql, + "serviceStatusForMigrations": serviceStatusForMigrations, + "serviceStatusForMessaging": serviceStatusForMessaging, + "protocolStatusForRest": protocolStatusForRest, + "protocolStatusForGraphql": protocolStatusForGraphql, + "protocolStatusForWebsocket": protocolStatusForWebsocket, + "region": region, + "billingLimits": billingLimits.toMap(), + "blocks": blocks.map((p) => p.toMap()).toList(), + "consoleAccessedAt": consoleAccessedAt, + }; + } +} diff --git a/lib/src/models/webhook.dart b/lib/src/models/webhook.dart index 13e7c2b5..39f28f43 100644 --- a/lib/src/models/webhook.dart +++ b/lib/src/models/webhook.dart @@ -20,17 +20,17 @@ class Webhook implements Model { /// Webhook trigger events. final List events; - /// Indicated if SSL / TLS Certificate verification is enabled. - final bool security; + /// Indicates if SSL / TLS certificate verification is enabled. + final bool tls; /// HTTP basic authentication username. - final String httpUser; + final String authUsername; /// HTTP basic authentication password. - final String httpPass; + final String authPassword; - /// Signature key which can be used to validated incoming - final String signatureKey; + /// Signature key which can be used to validate incoming webhook payloads. Only returned on creation and secret rotation. + final String secret; /// Indicates if this webhook is enabled. final bool enabled; @@ -48,10 +48,10 @@ class Webhook implements Model { required this.name, required this.url, required this.events, - required this.security, - required this.httpUser, - required this.httpPass, - required this.signatureKey, + required this.tls, + required this.authUsername, + required this.authPassword, + required this.secret, required this.enabled, required this.logs, required this.attempts, @@ -65,10 +65,10 @@ class Webhook implements Model { name: map['name'].toString(), url: map['url'].toString(), events: List.from(map['events'] ?? []), - security: map['security'], - httpUser: map['httpUser'].toString(), - httpPass: map['httpPass'].toString(), - signatureKey: map['signatureKey'].toString(), + tls: map['tls'], + authUsername: map['authUsername'].toString(), + authPassword: map['authPassword'].toString(), + secret: map['secret'].toString(), enabled: map['enabled'], logs: map['logs'].toString(), attempts: map['attempts'], @@ -84,10 +84,10 @@ class Webhook implements Model { "name": name, "url": url, "events": events, - "security": security, - "httpUser": httpUser, - "httpPass": httpPass, - "signatureKey": signatureKey, + "tls": tls, + "authUsername": authUsername, + "authPassword": authPassword, + "secret": secret, "enabled": enabled, "logs": logs, "attempts": attempts, diff --git a/lib/src/service.dart b/lib/src/service.dart index 1ae319b7..d73e37e6 100644 --- a/lib/src/service.dart +++ b/lib/src/service.dart @@ -1,3 +1,4 @@ +import '../models.dart' as models; import 'client.dart'; class Service { diff --git a/pubspec.yaml b/pubspec.yaml index 9887edc5..3a0aa782 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: dart_appwrite -version: 22.0.0 +version: 23.0.0 description: Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API homepage: https://appwrite.io repository: https://github.com/appwrite/sdk-for-dart diff --git a/test/services/account_test.dart b/test/services/account_test.dart index 7f6409b8..727e20bb 100644 --- a/test/services/account_test.dart +++ b/test/services/account_test.dart @@ -231,8 +231,9 @@ void main() { test('test method createMfaAuthenticator()', () async { final Map data = { - 'secret': '1', - 'uri': '1', + 'secret': '[SHARED_SECRET]', + 'uri': + 'otpauth://totp/appwrite:user@example.com?secret=[SHARED_SECRET]&issuer=appwrite', }; when(client.call( @@ -247,8 +248,9 @@ void main() { test('test method createMFAAuthenticator()', () async { final Map data = { - 'secret': '1', - 'uri': '1', + 'secret': '[SHARED_SECRET]', + 'uri': + 'otpauth://totp/appwrite:user@example.com?secret=[SHARED_SECRET]&issuer=appwrite', }; when(client.call( @@ -1173,6 +1175,7 @@ void main() { final response = await account.createOAuth2Token( provider: enums.OAuthProvider.amazon, ); + expect(response, isA()); }); test('test method createPhoneToken()', () async { diff --git a/test/services/databases_test.dart b/test/services/databases_test.dart index f85e4c1a..07d3f9f4 100644 --- a/test/services/databases_test.dart +++ b/test/services/databases_test.dart @@ -474,7 +474,7 @@ void main() { collectionId: '', key: '', xrequired: true, - xdefault: '', + xdefault: '2020-10-15T06:38:00.000+00:00', ); expect(response, isA()); }); @@ -1241,13 +1241,14 @@ void main() { test('test method getAttribute()', () async { final Map data = { - 'key': 'isEnabled', - 'type': 'boolean', + 'key': 'fullName', + 'type': 'string', 'status': 'available', 'error': 'string', 'required': true, '\$createdAt': '2020-10-15T06:38:00.000+00:00', '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'size': 128, }; when(client.call( @@ -1259,7 +1260,7 @@ void main() { collectionId: '', key: '', ); - expect(response, isA()); + expect(response, isA()); }); test('test method deleteAttribute()', () async { diff --git a/test/services/project_test.dart b/test/services/project_test.dart index 3083b50d..259d864c 100644 --- a/test/services/project_test.dart +++ b/test/services/project_test.dart @@ -54,6 +54,676 @@ void main() { project = Project(client); }); + test('test method listKeys()', () async { + final Map data = { + 'total': 5, + 'keys': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.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 project.createKey( + keyId: '', + name: '', + scopes: [enums.Scopes.sessionsWrite], + ); + 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 project.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 project.updateKey( + keyId: '', + name: '', + scopes: [enums.Scopes.sessionsWrite], + ); + expect(response, isA()); + }); + + test('test method deleteKey()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.deleteKey( + keyId: '', + ); + }); + + test('test method updateLabels()', () async { + final Map data = { + '\$id': '5e5ea5c16897e', + '\$createdAt': '2020-10-15T06:38:00.000+00:00', + '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'name': 'New Project', + 'description': 'This is a new project.', + 'teamId': '1592981250', + 'logo': '5f5c451b403cb', + 'url': '5f5c451b403cb', + 'legalName': 'Company LTD.', + 'legalCountry': 'US', + 'legalState': 'New York', + 'legalCity': 'New York City.', + 'legalAddress': '620 Eighth Avenue, New York, NY 10018', + 'legalTaxId': '131102020', + 'authDuration': 60, + 'authLimit': 100, + 'authSessionsLimit': 10, + 'authPasswordHistory': 5, + 'authPasswordDictionary': true, + 'authPersonalDataCheck': true, + 'authDisposableEmails': true, + 'authCanonicalEmails': true, + 'authFreeEmails': true, + 'authMockNumbers': [], + 'authSessionAlerts': true, + 'authMembershipsUserName': true, + 'authMembershipsUserEmail': true, + 'authMembershipsMfa': true, + 'authInvalidateSessions': true, + 'oAuthProviders': [], + 'platforms': [], + 'webhooks': [], + 'keys': [], + 'devKeys': [], + 'smtpEnabled': true, + 'smtpSenderName': 'John Appwrite', + 'smtpSenderEmail': 'john@appwrite.io', + 'smtpReplyTo': 'support@appwrite.io', + 'smtpHost': 'mail.appwrite.io', + 'smtpPort': 25, + 'smtpUsername': 'emailuser', + 'smtpPassword': 'securepassword', + 'smtpSecure': 'tls', + 'pingCount': 1, + 'pingedAt': '2020-10-15T06:38:00.000+00:00', + 'labels': [], + 'status': 'active', + 'authEmailPassword': true, + 'authUsersAuthMagicURL': true, + 'authEmailOtp': true, + 'authAnonymous': true, + 'authInvites': true, + 'authJWT': true, + 'authPhone': true, + 'serviceStatusForAccount': true, + 'serviceStatusForAvatars': true, + 'serviceStatusForDatabases': true, + 'serviceStatusForTablesdb': true, + 'serviceStatusForLocale': true, + 'serviceStatusForHealth': true, + 'serviceStatusForProject': true, + 'serviceStatusForStorage': true, + 'serviceStatusForTeams': true, + 'serviceStatusForUsers': true, + 'serviceStatusForVcs': true, + 'serviceStatusForSites': true, + 'serviceStatusForFunctions': true, + 'serviceStatusForProxy': true, + 'serviceStatusForGraphql': true, + 'serviceStatusForMigrations': true, + 'serviceStatusForMessaging': true, + 'protocolStatusForRest': true, + 'protocolStatusForGraphql': true, + 'protocolStatusForWebsocket': true, + 'region': 'fra', + 'billingLimits': { + 'bandwidth': 5, + 'storage': 150, + 'users': 200000, + 'executions': 750000, + 'GBHours': 100, + 'imageTransformations': 100, + 'authPhone': 10, + 'budgetLimit': 100, + }, + 'blocks': [], + 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + }; + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.updateLabels( + labels: [], + ); + expect(response, isA()); + }); + + test('test method listPlatforms()', () async { + final Map data = { + 'total': 5, + 'platforms': [], + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.listPlatforms(); + expect(response, isA()); + }); + + test('test method createAndroidPlatform()', () 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 Web App', + 'type': 'web', + 'applicationId': 'com.company.appname', + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.createAndroidPlatform( + platformId: '', + name: '', + applicationId: '', + ); + expect(response, isA()); + }); + + test('test method updateAndroidPlatform()', () 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 Web App', + 'type': 'web', + 'applicationId': 'com.company.appname', + }; + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.updateAndroidPlatform( + platformId: '', + name: '', + applicationId: '', + ); + expect(response, isA()); + }); + + test('test method createApplePlatform()', () 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 Web App', + 'type': 'web', + 'bundleIdentifier': 'com.company.appname', + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.createApplePlatform( + platformId: '', + name: '', + bundleIdentifier: '', + ); + expect(response, isA()); + }); + + test('test method updateApplePlatform()', () 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 Web App', + 'type': 'web', + 'bundleIdentifier': 'com.company.appname', + }; + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.updateApplePlatform( + platformId: '', + name: '', + bundleIdentifier: '', + ); + expect(response, isA()); + }); + + test('test method createLinuxPlatform()', () 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 Web App', + 'type': 'web', + 'packageName': 'com.company.appname', + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.createLinuxPlatform( + platformId: '', + name: '', + packageName: '', + ); + expect(response, isA()); + }); + + test('test method updateLinuxPlatform()', () 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 Web App', + 'type': 'web', + 'packageName': 'com.company.appname', + }; + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.updateLinuxPlatform( + platformId: '', + name: '', + packageName: '', + ); + expect(response, isA()); + }); + + test('test method createWebPlatform()', () 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 Web App', + 'type': 'web', + 'hostname': 'app.example.com', + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.createWebPlatform( + platformId: '', + name: '', + hostname: 'app.example.com', + ); + expect(response, isA()); + }); + + test('test method updateWebPlatform()', () 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 Web App', + 'type': 'web', + 'hostname': 'app.example.com', + }; + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.updateWebPlatform( + platformId: '', + name: '', + hostname: 'app.example.com', + ); + expect(response, isA()); + }); + + test('test method createWindowsPlatform()', () 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 Web App', + 'type': 'web', + 'packageIdentifierName': 'com.company.appname', + }; + + when(client.call( + HttpMethod.post, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.createWindowsPlatform( + platformId: '', + name: '', + packageIdentifierName: '', + ); + expect(response, isA()); + }); + + test('test method updateWindowsPlatform()', () 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 Web App', + 'type': 'web', + 'packageIdentifierName': 'com.company.appname', + }; + + when(client.call( + HttpMethod.put, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.updateWindowsPlatform( + platformId: '', + name: '', + packageIdentifierName: '', + ); + expect(response, isA()); + }); + + test('test method getPlatform()', () 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 Web App', + 'type': 'web', + 'packageName': 'com.company.appname', + }; + + when(client.call( + HttpMethod.get, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.getPlatform( + platformId: '', + ); + expect(response, isA()); + }); + + test('test method deletePlatform()', () async { + final data = ''; + + when(client.call( + HttpMethod.delete, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.deletePlatform( + platformId: '', + ); + }); + + test('test method updateProtocolStatus()', () 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': 'New Project', + 'description': 'This is a new project.', + 'teamId': '1592981250', + 'logo': '5f5c451b403cb', + 'url': '5f5c451b403cb', + 'legalName': 'Company LTD.', + 'legalCountry': 'US', + 'legalState': 'New York', + 'legalCity': 'New York City.', + 'legalAddress': '620 Eighth Avenue, New York, NY 10018', + 'legalTaxId': '131102020', + 'authDuration': 60, + 'authLimit': 100, + 'authSessionsLimit': 10, + 'authPasswordHistory': 5, + 'authPasswordDictionary': true, + 'authPersonalDataCheck': true, + 'authDisposableEmails': true, + 'authCanonicalEmails': true, + 'authFreeEmails': true, + 'authMockNumbers': [], + 'authSessionAlerts': true, + 'authMembershipsUserName': true, + 'authMembershipsUserEmail': true, + 'authMembershipsMfa': true, + 'authInvalidateSessions': true, + 'oAuthProviders': [], + 'platforms': [], + 'webhooks': [], + 'keys': [], + 'devKeys': [], + 'smtpEnabled': true, + 'smtpSenderName': 'John Appwrite', + 'smtpSenderEmail': 'john@appwrite.io', + 'smtpReplyTo': 'support@appwrite.io', + 'smtpHost': 'mail.appwrite.io', + 'smtpPort': 25, + 'smtpUsername': 'emailuser', + 'smtpPassword': 'securepassword', + 'smtpSecure': 'tls', + 'pingCount': 1, + 'pingedAt': '2020-10-15T06:38:00.000+00:00', + 'labels': [], + 'status': 'active', + 'authEmailPassword': true, + 'authUsersAuthMagicURL': true, + 'authEmailOtp': true, + 'authAnonymous': true, + 'authInvites': true, + 'authJWT': true, + 'authPhone': true, + 'serviceStatusForAccount': true, + 'serviceStatusForAvatars': true, + 'serviceStatusForDatabases': true, + 'serviceStatusForTablesdb': true, + 'serviceStatusForLocale': true, + 'serviceStatusForHealth': true, + 'serviceStatusForProject': true, + 'serviceStatusForStorage': true, + 'serviceStatusForTeams': true, + 'serviceStatusForUsers': true, + 'serviceStatusForVcs': true, + 'serviceStatusForSites': true, + 'serviceStatusForFunctions': true, + 'serviceStatusForProxy': true, + 'serviceStatusForGraphql': true, + 'serviceStatusForMigrations': true, + 'serviceStatusForMessaging': true, + 'protocolStatusForRest': true, + 'protocolStatusForGraphql': true, + 'protocolStatusForWebsocket': true, + 'region': 'fra', + 'billingLimits': { + 'bandwidth': 5, + 'storage': 150, + 'users': 200000, + 'executions': 750000, + 'GBHours': 100, + 'imageTransformations': 100, + 'authPhone': 10, + 'budgetLimit': 100, + }, + 'blocks': [], + 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + }; + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.updateProtocolStatus( + protocolId: enums.ProtocolId.rest, + enabled: true, + ); + expect(response, isA()); + }); + + test('test method updateServiceStatus()', () 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': 'New Project', + 'description': 'This is a new project.', + 'teamId': '1592981250', + 'logo': '5f5c451b403cb', + 'url': '5f5c451b403cb', + 'legalName': 'Company LTD.', + 'legalCountry': 'US', + 'legalState': 'New York', + 'legalCity': 'New York City.', + 'legalAddress': '620 Eighth Avenue, New York, NY 10018', + 'legalTaxId': '131102020', + 'authDuration': 60, + 'authLimit': 100, + 'authSessionsLimit': 10, + 'authPasswordHistory': 5, + 'authPasswordDictionary': true, + 'authPersonalDataCheck': true, + 'authDisposableEmails': true, + 'authCanonicalEmails': true, + 'authFreeEmails': true, + 'authMockNumbers': [], + 'authSessionAlerts': true, + 'authMembershipsUserName': true, + 'authMembershipsUserEmail': true, + 'authMembershipsMfa': true, + 'authInvalidateSessions': true, + 'oAuthProviders': [], + 'platforms': [], + 'webhooks': [], + 'keys': [], + 'devKeys': [], + 'smtpEnabled': true, + 'smtpSenderName': 'John Appwrite', + 'smtpSenderEmail': 'john@appwrite.io', + 'smtpReplyTo': 'support@appwrite.io', + 'smtpHost': 'mail.appwrite.io', + 'smtpPort': 25, + 'smtpUsername': 'emailuser', + 'smtpPassword': 'securepassword', + 'smtpSecure': 'tls', + 'pingCount': 1, + 'pingedAt': '2020-10-15T06:38:00.000+00:00', + 'labels': [], + 'status': 'active', + 'authEmailPassword': true, + 'authUsersAuthMagicURL': true, + 'authEmailOtp': true, + 'authAnonymous': true, + 'authInvites': true, + 'authJWT': true, + 'authPhone': true, + 'serviceStatusForAccount': true, + 'serviceStatusForAvatars': true, + 'serviceStatusForDatabases': true, + 'serviceStatusForTablesdb': true, + 'serviceStatusForLocale': true, + 'serviceStatusForHealth': true, + 'serviceStatusForProject': true, + 'serviceStatusForStorage': true, + 'serviceStatusForTeams': true, + 'serviceStatusForUsers': true, + 'serviceStatusForVcs': true, + 'serviceStatusForSites': true, + 'serviceStatusForFunctions': true, + 'serviceStatusForProxy': true, + 'serviceStatusForGraphql': true, + 'serviceStatusForMigrations': true, + 'serviceStatusForMessaging': true, + 'protocolStatusForRest': true, + 'protocolStatusForGraphql': true, + 'protocolStatusForWebsocket': true, + 'region': 'fra', + 'billingLimits': { + 'bandwidth': 5, + 'storage': 150, + 'users': 200000, + 'executions': 750000, + 'GBHours': 100, + 'imageTransformations': 100, + 'authPhone': 10, + 'budgetLimit': 100, + }, + 'blocks': [], + 'consoleAccessedAt': '2020-10-15T06:38:00.000+00:00', + }; + + when(client.call( + HttpMethod.patch, + )).thenAnswer((_) async => Response(data: data)); + + final response = await project.updateServiceStatus( + serviceId: enums.ServiceId.account, + enabled: true, + ); + expect(response, isA()); + }); + test('test method listVariables()', () async { final Map data = { 'total': 5, diff --git a/test/services/tables_db_test.dart b/test/services/tables_db_test.dart index 2711abd8..c434c3b4 100644 --- a/test/services/tables_db_test.dart +++ b/test/services/tables_db_test.dart @@ -474,7 +474,7 @@ void main() { tableId: '', key: '', xrequired: true, - xdefault: '', + xdefault: '2020-10-15T06:38:00.000+00:00', ); expect(response, isA()); }); @@ -1212,13 +1212,14 @@ void main() { test('test method getColumn()', () async { final Map data = { - 'key': 'isEnabled', - 'type': 'boolean', + 'key': 'fullName', + 'type': 'string', 'status': 'available', 'error': 'string', 'required': true, '\$createdAt': '2020-10-15T06:38:00.000+00:00', '\$updatedAt': '2020-10-15T06:38:00.000+00:00', + 'size': 128, }; when(client.call( @@ -1230,7 +1231,7 @@ void main() { tableId: '', key: '', ); - expect(response, isA()); + expect(response, isA()); }); test('test method deleteColumn()', () async { diff --git a/test/services/webhooks_test.dart b/test/services/webhooks_test.dart index e2018b9c..58a633e0 100644 --- a/test/services/webhooks_test.dart +++ b/test/services/webhooks_test.dart @@ -76,10 +76,10 @@ void main() { 'name': 'My Webhook', 'url': 'https://example.com/webhook', 'events': [], - 'security': true, - 'httpUser': 'username', - 'httpPass': 'password', - 'signatureKey': 'ad3d581ca230e2b7059c545e5a', + 'tls': true, + 'authUsername': 'username', + 'authPassword': 'password', + 'secret': 'ad3d581ca230e2b7059c545e5a', 'enabled': true, 'logs': 'Failed to connect to remote server.', 'attempts': 10, @@ -106,10 +106,10 @@ void main() { 'name': 'My Webhook', 'url': 'https://example.com/webhook', 'events': [], - 'security': true, - 'httpUser': 'username', - 'httpPass': 'password', - 'signatureKey': 'ad3d581ca230e2b7059c545e5a', + 'tls': true, + 'authUsername': 'username', + 'authPassword': 'password', + 'secret': 'ad3d581ca230e2b7059c545e5a', 'enabled': true, 'logs': 'Failed to connect to remote server.', 'attempts': 10, @@ -133,10 +133,10 @@ void main() { 'name': 'My Webhook', 'url': 'https://example.com/webhook', 'events': [], - 'security': true, - 'httpUser': 'username', - 'httpPass': 'password', - 'signatureKey': 'ad3d581ca230e2b7059c545e5a', + 'tls': true, + 'authUsername': 'username', + 'authPassword': 'password', + 'secret': 'ad3d581ca230e2b7059c545e5a', 'enabled': true, 'logs': 'Failed to connect to remote server.', 'attempts': 10, @@ -167,7 +167,7 @@ void main() { ); }); - test('test method updateSignature()', () async { + test('test method updateSecret()', () async { final Map data = { '\$id': '5e5ea5c16897e', '\$createdAt': '2020-10-15T06:38:00.000+00:00', @@ -175,10 +175,10 @@ void main() { 'name': 'My Webhook', 'url': 'https://example.com/webhook', 'events': [], - 'security': true, - 'httpUser': 'username', - 'httpPass': 'password', - 'signatureKey': 'ad3d581ca230e2b7059c545e5a', + 'tls': true, + 'authUsername': 'username', + 'authPassword': 'password', + 'secret': 'ad3d581ca230e2b7059c545e5a', 'enabled': true, 'logs': 'Failed to connect to remote server.', 'attempts': 10, @@ -188,7 +188,7 @@ void main() { HttpMethod.patch, )).thenAnswer((_) async => Response(data: data)); - final response = await webhooks.updateSignature( + final response = await webhooks.updateSecret( webhookId: '', ); expect(response, isA()); diff --git a/test/src/models/auth_provider_test.dart b/test/src/models/auth_provider_test.dart new file mode 100644 index 00000000..90191db8 --- /dev/null +++ b/test/src/models/auth_provider_test.dart @@ -0,0 +1,25 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('AuthProvider', () { + test('model', () { + final model = AuthProvider( + key: 'github', + name: 'GitHub', + appId: '259125845563242502', + secret: 'Bpw_g9c2TGXxfgLshDbSaL8tsCcqgczQ', + enabled: true, + ); + + final map = model.toMap(); + final result = AuthProvider.fromMap(map); + + expect(result.key, 'github'); + expect(result.name, 'GitHub'); + expect(result.appId, '259125845563242502'); + expect(result.secret, 'Bpw_g9c2TGXxfgLshDbSaL8tsCcqgczQ'); + expect(result.enabled, true); + }); + }); +} diff --git a/test/src/models/billing_limits_test.dart b/test/src/models/billing_limits_test.dart new file mode 100644 index 00000000..3ca637d1 --- /dev/null +++ b/test/src/models/billing_limits_test.dart @@ -0,0 +1,31 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('BillingLimits', () { + test('model', () { + final model = BillingLimits( + bandwidth: 5, + storage: 150, + users: 200000, + executions: 750000, + GBHours: 100, + imageTransformations: 100, + authPhone: 10, + budgetLimit: 100, + ); + + final map = model.toMap(); + final result = BillingLimits.fromMap(map); + + expect(result.bandwidth, 5); + expect(result.storage, 150); + expect(result.users, 200000); + expect(result.executions, 750000); + expect(result.GBHours, 100); + expect(result.imageTransformations, 100); + expect(result.authPhone, 10); + expect(result.budgetLimit, 100); + }); + }); +} diff --git a/test/src/models/block_test.dart b/test/src/models/block_test.dart new file mode 100644 index 00000000..e407398a --- /dev/null +++ b/test/src/models/block_test.dart @@ -0,0 +1,21 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('Block', () { + test('model', () { + final model = Block( + $createdAt: '2020-10-15T06:38:00.000+00:00', + resourceType: 'project', + resourceId: '5e5ea5c16897e', + ); + + final map = model.toMap(); + final result = Block.fromMap(map); + + expect(result.$createdAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.resourceType, 'project'); + expect(result.resourceId, '5e5ea5c16897e'); + }); + }); +} diff --git a/test/src/models/dev_key_test.dart b/test/src/models/dev_key_test.dart new file mode 100644 index 00000000..3a318814 --- /dev/null +++ b/test/src/models/dev_key_test.dart @@ -0,0 +1,31 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('DevKey', () { + test('model', () { + final model = DevKey( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + name: 'Dev API Key', + expire: '2020-10-15T06:38:00.000+00:00', + secret: '919c2d18fb5d4...a2ae413da83346ad2', + accessedAt: '2020-10-15T06:38:00.000+00:00', + sdks: [], + ); + + final map = model.toMap(); + final result = DevKey.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, 'Dev API Key'); + expect(result.expire, '2020-10-15T06:38:00.000+00:00'); + 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/key_list_test.dart b/test/src/models/key_list_test.dart new file mode 100644 index 00000000..97747078 --- /dev/null +++ b/test/src/models/key_list_test.dart @@ -0,0 +1,19 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/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..2050b172 --- /dev/null +++ b/test/src/models/key_test.dart @@ -0,0 +1,33 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/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/log_test.dart b/test/src/models/log_test.dart index c4e740c9..24273a11 100644 --- a/test/src/models/log_test.dart +++ b/test/src/models/log_test.dart @@ -10,6 +10,7 @@ void main() { userEmail: 'john@appwrite.io', userName: 'John Doe', mode: 'admin', + userType: 'user', ip: '127.0.0.1', time: '2020-10-15T06:38:00.000+00:00', osCode: 'Mac', @@ -36,6 +37,7 @@ void main() { expect(result.userEmail, 'john@appwrite.io'); expect(result.userName, 'John Doe'); expect(result.mode, 'admin'); + expect(result.userType, 'user'); expect(result.ip, '127.0.0.1'); expect(result.time, '2020-10-15T06:38:00.000+00:00'); expect(result.osCode, 'Mac'); diff --git a/test/src/models/mfa_type_test.dart b/test/src/models/mfa_type_test.dart index fd71f87d..e391105b 100644 --- a/test/src/models/mfa_type_test.dart +++ b/test/src/models/mfa_type_test.dart @@ -5,15 +5,17 @@ void main() { group('MfaType', () { test('model', () { final model = MfaType( - secret: '1', - uri: '1', + secret: '[SHARED_SECRET]', + uri: + 'otpauth://totp/appwrite:user@example.com?secret=[SHARED_SECRET]&issuer=appwrite', ); final map = model.toMap(); final result = MfaType.fromMap(map); - expect(result.secret, '1'); - expect(result.uri, '1'); + expect(result.secret, '[SHARED_SECRET]'); + expect(result.uri, + 'otpauth://totp/appwrite:user@example.com?secret=[SHARED_SECRET]&issuer=appwrite'); }); }); } diff --git a/test/src/models/mock_number_test.dart b/test/src/models/mock_number_test.dart new file mode 100644 index 00000000..9180847f --- /dev/null +++ b/test/src/models/mock_number_test.dart @@ -0,0 +1,19 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('MockNumber', () { + test('model', () { + final model = MockNumber( + phone: '+1612842323', + otp: '123456', + ); + + final map = model.toMap(); + final result = MockNumber.fromMap(map); + + expect(result.phone, '+1612842323'); + expect(result.otp, '123456'); + }); + }); +} diff --git a/test/src/models/platform_android_test.dart b/test/src/models/platform_android_test.dart new file mode 100644 index 00000000..67f712fc --- /dev/null +++ b/test/src/models/platform_android_test.dart @@ -0,0 +1,28 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:dart_appwrite/enums.dart'; +import 'package:test/test.dart'; + +void main() { + group('PlatformAndroid', () { + test('model', () { + final model = PlatformAndroid( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + name: 'My Web App', + type: PlatformType.windows, + applicationId: 'com.company.appname', + ); + + final map = model.toMap(); + final result = PlatformAndroid.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 Web App'); + expect(result.type, PlatformType.windows); + expect(result.applicationId, 'com.company.appname'); + }); + }); +} diff --git a/test/src/models/platform_apple_test.dart b/test/src/models/platform_apple_test.dart new file mode 100644 index 00000000..0c238f4e --- /dev/null +++ b/test/src/models/platform_apple_test.dart @@ -0,0 +1,28 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:dart_appwrite/enums.dart'; +import 'package:test/test.dart'; + +void main() { + group('PlatformApple', () { + test('model', () { + final model = PlatformApple( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + name: 'My Web App', + type: PlatformType.windows, + bundleIdentifier: 'com.company.appname', + ); + + final map = model.toMap(); + final result = PlatformApple.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 Web App'); + expect(result.type, PlatformType.windows); + expect(result.bundleIdentifier, 'com.company.appname'); + }); + }); +} diff --git a/test/src/models/platform_linux_test.dart b/test/src/models/platform_linux_test.dart new file mode 100644 index 00000000..a28a0658 --- /dev/null +++ b/test/src/models/platform_linux_test.dart @@ -0,0 +1,28 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:dart_appwrite/enums.dart'; +import 'package:test/test.dart'; + +void main() { + group('PlatformLinux', () { + test('model', () { + final model = PlatformLinux( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + name: 'My Web App', + type: PlatformType.windows, + packageName: 'com.company.appname', + ); + + final map = model.toMap(); + final result = PlatformLinux.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 Web App'); + expect(result.type, PlatformType.windows); + expect(result.packageName, 'com.company.appname'); + }); + }); +} diff --git a/test/src/models/platform_list_test.dart b/test/src/models/platform_list_test.dart new file mode 100644 index 00000000..6661761d --- /dev/null +++ b/test/src/models/platform_list_test.dart @@ -0,0 +1,19 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('PlatformList', () { + test('model', () { + final model = PlatformList( + total: 5, + platforms: [], + ); + + final map = model.toMap(); + final result = PlatformList.fromMap(map); + + expect(result.total, 5); + expect(result.platforms, []); + }); + }); +} diff --git a/test/src/models/platform_web_test.dart b/test/src/models/platform_web_test.dart new file mode 100644 index 00000000..29dc32e8 --- /dev/null +++ b/test/src/models/platform_web_test.dart @@ -0,0 +1,28 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:dart_appwrite/enums.dart'; +import 'package:test/test.dart'; + +void main() { + group('PlatformWeb', () { + test('model', () { + final model = PlatformWeb( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + name: 'My Web App', + type: PlatformType.windows, + hostname: 'app.example.com', + ); + + final map = model.toMap(); + final result = PlatformWeb.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 Web App'); + expect(result.type, PlatformType.windows); + expect(result.hostname, 'app.example.com'); + }); + }); +} diff --git a/test/src/models/platform_windows_test.dart b/test/src/models/platform_windows_test.dart new file mode 100644 index 00000000..57c708f9 --- /dev/null +++ b/test/src/models/platform_windows_test.dart @@ -0,0 +1,28 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:dart_appwrite/enums.dart'; +import 'package:test/test.dart'; + +void main() { + group('PlatformWindows', () { + test('model', () { + final model = PlatformWindows( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + name: 'My Web App', + type: PlatformType.windows, + packageIdentifierName: 'com.company.appname', + ); + + final map = model.toMap(); + final result = PlatformWindows.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 Web App'); + expect(result.type, PlatformType.windows); + expect(result.packageIdentifierName, 'com.company.appname'); + }); + }); +} diff --git a/test/src/models/project_test.dart b/test/src/models/project_test.dart new file mode 100644 index 00000000..adf8ccbe --- /dev/null +++ b/test/src/models/project_test.dart @@ -0,0 +1,179 @@ +import 'package:dart_appwrite/models.dart'; +import 'package:test/test.dart'; + +void main() { + group('Project', () { + test('model', () { + final model = Project( + $id: '5e5ea5c16897e', + $createdAt: '2020-10-15T06:38:00.000+00:00', + $updatedAt: '2020-10-15T06:38:00.000+00:00', + name: 'New Project', + description: 'This is a new project.', + teamId: '1592981250', + logo: '5f5c451b403cb', + url: '5f5c451b403cb', + legalName: 'Company LTD.', + legalCountry: 'US', + legalState: 'New York', + legalCity: 'New York City.', + legalAddress: '620 Eighth Avenue, New York, NY 10018', + legalTaxId: '131102020', + authDuration: 60, + authLimit: 100, + authSessionsLimit: 10, + authPasswordHistory: 5, + authPasswordDictionary: true, + authPersonalDataCheck: true, + authDisposableEmails: true, + authCanonicalEmails: true, + authFreeEmails: true, + authMockNumbers: [], + authSessionAlerts: true, + authMembershipsUserName: true, + authMembershipsUserEmail: true, + authMembershipsMfa: true, + authInvalidateSessions: true, + oAuthProviders: [], + platforms: [], + webhooks: [], + keys: [], + devKeys: [], + smtpEnabled: true, + smtpSenderName: 'John Appwrite', + smtpSenderEmail: 'john@appwrite.io', + smtpReplyTo: 'support@appwrite.io', + smtpHost: 'mail.appwrite.io', + smtpPort: 25, + smtpUsername: 'emailuser', + smtpPassword: 'securepassword', + smtpSecure: 'tls', + pingCount: 1, + pingedAt: '2020-10-15T06:38:00.000+00:00', + labels: [], + status: 'active', + authEmailPassword: true, + authUsersAuthMagicURL: true, + authEmailOtp: true, + authAnonymous: true, + authInvites: true, + authJWT: true, + authPhone: true, + serviceStatusForAccount: true, + serviceStatusForAvatars: true, + serviceStatusForDatabases: true, + serviceStatusForTablesdb: true, + serviceStatusForLocale: true, + serviceStatusForHealth: true, + serviceStatusForProject: true, + serviceStatusForStorage: true, + serviceStatusForTeams: true, + serviceStatusForUsers: true, + serviceStatusForVcs: true, + serviceStatusForSites: true, + serviceStatusForFunctions: true, + serviceStatusForProxy: true, + serviceStatusForGraphql: true, + serviceStatusForMigrations: true, + serviceStatusForMessaging: true, + protocolStatusForRest: true, + protocolStatusForGraphql: true, + protocolStatusForWebsocket: true, + region: 'fra', + billingLimits: BillingLimits( + bandwidth: 5, + storage: 150, + users: 200000, + executions: 750000, + GBHours: 100, + imageTransformations: 100, + authPhone: 10, + budgetLimit: 100, + ), + blocks: [], + consoleAccessedAt: '2020-10-15T06:38:00.000+00:00', + ); + + final map = model.toMap(); + final result = Project.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, 'New Project'); + expect(result.description, 'This is a new project.'); + expect(result.teamId, '1592981250'); + expect(result.logo, '5f5c451b403cb'); + expect(result.url, '5f5c451b403cb'); + expect(result.legalName, 'Company LTD.'); + expect(result.legalCountry, 'US'); + expect(result.legalState, 'New York'); + expect(result.legalCity, 'New York City.'); + expect(result.legalAddress, '620 Eighth Avenue, New York, NY 10018'); + expect(result.legalTaxId, '131102020'); + expect(result.authDuration, 60); + expect(result.authLimit, 100); + expect(result.authSessionsLimit, 10); + expect(result.authPasswordHistory, 5); + expect(result.authPasswordDictionary, true); + expect(result.authPersonalDataCheck, true); + expect(result.authDisposableEmails, true); + expect(result.authCanonicalEmails, true); + expect(result.authFreeEmails, true); + expect(result.authMockNumbers, []); + expect(result.authSessionAlerts, true); + expect(result.authMembershipsUserName, true); + expect(result.authMembershipsUserEmail, true); + expect(result.authMembershipsMfa, true); + expect(result.authInvalidateSessions, true); + expect(result.oAuthProviders, []); + expect(result.platforms, []); + expect(result.webhooks, []); + expect(result.keys, []); + expect(result.devKeys, []); + expect(result.smtpEnabled, true); + expect(result.smtpSenderName, 'John Appwrite'); + expect(result.smtpSenderEmail, 'john@appwrite.io'); + expect(result.smtpReplyTo, 'support@appwrite.io'); + expect(result.smtpHost, 'mail.appwrite.io'); + expect(result.smtpPort, 25); + expect(result.smtpUsername, 'emailuser'); + expect(result.smtpPassword, 'securepassword'); + expect(result.smtpSecure, 'tls'); + expect(result.pingCount, 1); + expect(result.pingedAt, '2020-10-15T06:38:00.000+00:00'); + expect(result.labels, []); + expect(result.status, 'active'); + expect(result.authEmailPassword, true); + expect(result.authUsersAuthMagicURL, true); + expect(result.authEmailOtp, true); + expect(result.authAnonymous, true); + expect(result.authInvites, true); + expect(result.authJWT, true); + expect(result.authPhone, true); + expect(result.serviceStatusForAccount, true); + expect(result.serviceStatusForAvatars, true); + expect(result.serviceStatusForDatabases, true); + expect(result.serviceStatusForTablesdb, true); + expect(result.serviceStatusForLocale, true); + expect(result.serviceStatusForHealth, true); + expect(result.serviceStatusForProject, true); + expect(result.serviceStatusForStorage, true); + expect(result.serviceStatusForTeams, true); + expect(result.serviceStatusForUsers, true); + expect(result.serviceStatusForVcs, true); + expect(result.serviceStatusForSites, true); + expect(result.serviceStatusForFunctions, true); + expect(result.serviceStatusForProxy, true); + expect(result.serviceStatusForGraphql, true); + expect(result.serviceStatusForMigrations, true); + expect(result.serviceStatusForMessaging, true); + expect(result.protocolStatusForRest, true); + expect(result.protocolStatusForGraphql, true); + expect(result.protocolStatusForWebsocket, true); + expect(result.region, 'fra'); + expect(result.blocks, []); + expect(result.consoleAccessedAt, '2020-10-15T06:38:00.000+00:00'); + }); + }); +} diff --git a/test/src/models/webhook_test.dart b/test/src/models/webhook_test.dart index 639e9d39..fd64e1db 100644 --- a/test/src/models/webhook_test.dart +++ b/test/src/models/webhook_test.dart @@ -11,10 +11,10 @@ void main() { name: 'My Webhook', url: 'https://example.com/webhook', events: [], - security: true, - httpUser: 'username', - httpPass: 'password', - signatureKey: 'ad3d581ca230e2b7059c545e5a', + tls: true, + authUsername: 'username', + authPassword: 'password', + secret: 'ad3d581ca230e2b7059c545e5a', enabled: true, logs: 'Failed to connect to remote server.', attempts: 10, @@ -29,10 +29,10 @@ void main() { expect(result.name, 'My Webhook'); expect(result.url, 'https://example.com/webhook'); expect(result.events, []); - expect(result.security, true); - expect(result.httpUser, 'username'); - expect(result.httpPass, 'password'); - expect(result.signatureKey, 'ad3d581ca230e2b7059c545e5a'); + expect(result.tls, true); + expect(result.authUsername, 'username'); + expect(result.authPassword, 'password'); + expect(result.secret, 'ad3d581ca230e2b7059c545e5a'); expect(result.enabled, true); expect(result.logs, 'Failed to connect to remote server.'); expect(result.attempts, 10);