From 27e0b16c636db9ae9f24756064dcc54729dcd320 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 11 Apr 2023 23:57:49 +0000 Subject: [PATCH] update to appwrite 1.3.0 --- README.md | 6 +- build.gradle | 2 +- docs/examples/java/account/create.md | 2 +- docs/examples/java/account/update-password.md | 2 +- docs/examples/java/databases/get-document.md | 2 +- docs/examples/java/teams/create-membership.md | 1 - docs/examples/java/teams/get-prefs.md | 21 ++ .../java/teams/{update.md => update-name.md} | 2 +- docs/examples/java/teams/update-prefs.md | 22 ++ docs/examples/kotlin/account/create.md | 2 +- .../kotlin/account/update-password.md | 2 +- .../examples/kotlin/databases/get-document.md | 2 +- .../kotlin/teams/create-membership.md | 1 - docs/examples/kotlin/teams/get-prefs.md | 12 + .../teams/{update.md => update-name.md} | 2 +- docs/examples/kotlin/teams/update-prefs.md | 13 + example-java/build.gradle | 16 +- example/build.gradle | 34 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- library/build.gradle | 14 +- library/src/main/java/io/appwrite/Client.kt | 2 +- library/src/main/java/io/appwrite/Query.kt | 16 ++ .../java/io/appwrite/models/AlgoArgon2.kt | 54 ++++ .../java/io/appwrite/models/AlgoBcrypt.kt | 30 +++ .../main/java/io/appwrite/models/AlgoMd5.kt | 30 +++ .../java/io/appwrite/models/AlgoPhpass.kt | 30 +++ .../java/io/appwrite/models/AlgoScrypt.kt | 62 +++++ .../io/appwrite/models/AlgoScryptModified.kt | 54 ++++ .../main/java/io/appwrite/models/AlgoSha.kt | 30 +++ .../src/main/java/io/appwrite/models/Team.kt | 30 ++- .../main/java/io/appwrite/models/TeamList.kt | 18 +- .../appwrite/models/{Account.kt => User.kt} | 38 ++- .../main/java/io/appwrite/services/Account.kt | 112 ++++---- .../java/io/appwrite/services/Databases.kt | 20 +- .../java/io/appwrite/services/Functions.kt | 2 +- .../main/java/io/appwrite/services/Storage.kt | 2 +- .../main/java/io/appwrite/services/Teams.kt | 250 +++++++++++++++--- 37 files changed, 785 insertions(+), 155 deletions(-) create mode 100644 docs/examples/java/teams/get-prefs.md rename docs/examples/java/teams/{update.md => update-name.md} (96%) create mode 100644 docs/examples/java/teams/update-prefs.md create mode 100644 docs/examples/kotlin/teams/get-prefs.md rename docs/examples/kotlin/teams/{update.md => update-name.md} (89%) create mode 100644 docs/examples/kotlin/teams/update-prefs.md create mode 100644 library/src/main/java/io/appwrite/models/AlgoArgon2.kt create mode 100644 library/src/main/java/io/appwrite/models/AlgoBcrypt.kt create mode 100644 library/src/main/java/io/appwrite/models/AlgoMd5.kt create mode 100644 library/src/main/java/io/appwrite/models/AlgoPhpass.kt create mode 100644 library/src/main/java/io/appwrite/models/AlgoScrypt.kt create mode 100644 library/src/main/java/io/appwrite/models/AlgoScryptModified.kt create mode 100644 library/src/main/java/io/appwrite/models/AlgoSha.kt rename library/src/main/java/io/appwrite/models/{Account.kt => User.kt} (81%) diff --git a/README.md b/README.md index 20edee9..97b1780 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) -**This SDK is compatible with Appwrite server version 1.2.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-android/releases).** +**This SDK is compatible with Appwrite server version 1.3.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-android/releases).** Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Android SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:1.2.1") +implementation("io.appwrite:sdk-for-android:1.3.0") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 1.2.1 + 1.3.0 ``` diff --git a/build.gradle b/build.gradle index d475d54..f2080e6 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'io.github.gradle-nexus.publish-plugin' // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = "1.7.10" + ext.kotlin_version = "1.8.0" version System.getenv("SDK_VERSION") repositories { maven { url "https://plugins.gradle.org/m2/" } diff --git a/docs/examples/java/account/create.md b/docs/examples/java/account/create.md index af0965e..68bb47e 100644 --- a/docs/examples/java/account/create.md +++ b/docs/examples/java/account/create.md @@ -11,7 +11,7 @@ Account account = new Account(client); account.create( "[USER_ID]", "email@example.com", - "password", + "", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); diff --git a/docs/examples/java/account/update-password.md b/docs/examples/java/account/update-password.md index e16aac5..aaaee66 100644 --- a/docs/examples/java/account/update-password.md +++ b/docs/examples/java/account/update-password.md @@ -9,7 +9,7 @@ Client client = new Client(context) Account account = new Account(client); account.updatePassword( - "password", + "", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); diff --git a/docs/examples/java/databases/get-document.md b/docs/examples/java/databases/get-document.md index f4e7dc6..7e3b33b 100644 --- a/docs/examples/java/databases/get-document.md +++ b/docs/examples/java/databases/get-document.md @@ -11,7 +11,7 @@ Databases databases = new Databases(client); databases.getDocument( "[DATABASE_ID]", "[COLLECTION_ID]", - "[DOCUMENT_ID]" + "[DOCUMENT_ID]", new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); diff --git a/docs/examples/java/teams/create-membership.md b/docs/examples/java/teams/create-membership.md index 9d567d6..0e5590d 100644 --- a/docs/examples/java/teams/create-membership.md +++ b/docs/examples/java/teams/create-membership.md @@ -10,7 +10,6 @@ Teams teams = new Teams(client); teams.createMembership( "[TEAM_ID]", - "email@example.com", listOf(), "https://example.com", new CoroutineCallback<>((result, error) -> { diff --git a/docs/examples/java/teams/get-prefs.md b/docs/examples/java/teams/get-prefs.md new file mode 100644 index 0000000..bbf1256 --- /dev/null +++ b/docs/examples/java/teams/get-prefs.md @@ -0,0 +1,21 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Teams; + +Client client = new Client(context) + .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + +Teams teams = new Teams(client); + +teams.getPrefs( + "[TEAM_ID]" + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); diff --git a/docs/examples/java/teams/update.md b/docs/examples/java/teams/update-name.md similarity index 96% rename from docs/examples/java/teams/update.md rename to docs/examples/java/teams/update-name.md index 86d6a3f..22a2ee0 100644 --- a/docs/examples/java/teams/update.md +++ b/docs/examples/java/teams/update-name.md @@ -8,7 +8,7 @@ Client client = new Client(context) Teams teams = new Teams(client); -teams.update( +teams.updateName( "[TEAM_ID]", "[NAME]" new CoroutineCallback<>((result, error) -> { diff --git a/docs/examples/java/teams/update-prefs.md b/docs/examples/java/teams/update-prefs.md new file mode 100644 index 0000000..a4cf82d --- /dev/null +++ b/docs/examples/java/teams/update-prefs.md @@ -0,0 +1,22 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Teams; + +Client client = new Client(context) + .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint + .setProject("5df5acd0d48c2"); // Your project ID + +Teams teams = new Teams(client); + +teams.updatePrefs( + "[TEAM_ID]", + mapOf( "a" to "b" ) + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); diff --git a/docs/examples/kotlin/account/create.md b/docs/examples/kotlin/account/create.md index 2a55fb1..eda87d3 100644 --- a/docs/examples/kotlin/account/create.md +++ b/docs/examples/kotlin/account/create.md @@ -10,5 +10,5 @@ val account = Account(client) val response = account.create( userId = "[USER_ID]", email = "email@example.com", - password = "password", + password = "", ) diff --git a/docs/examples/kotlin/account/update-password.md b/docs/examples/kotlin/account/update-password.md index cdf8178..14e746f 100644 --- a/docs/examples/kotlin/account/update-password.md +++ b/docs/examples/kotlin/account/update-password.md @@ -8,5 +8,5 @@ val client = Client(context) val account = Account(client) val response = account.updatePassword( - password = "password", + password = "", ) diff --git a/docs/examples/kotlin/databases/get-document.md b/docs/examples/kotlin/databases/get-document.md index b81f340..17c6047 100644 --- a/docs/examples/kotlin/databases/get-document.md +++ b/docs/examples/kotlin/databases/get-document.md @@ -10,5 +10,5 @@ val databases = Databases(client) val response = databases.getDocument( databaseId = "[DATABASE_ID]", collectionId = "[COLLECTION_ID]", - documentId = "[DOCUMENT_ID]" + documentId = "[DOCUMENT_ID]", ) diff --git a/docs/examples/kotlin/teams/create-membership.md b/docs/examples/kotlin/teams/create-membership.md index 60d39c0..33bbe56 100644 --- a/docs/examples/kotlin/teams/create-membership.md +++ b/docs/examples/kotlin/teams/create-membership.md @@ -9,7 +9,6 @@ val teams = Teams(client) val response = teams.createMembership( teamId = "[TEAM_ID]", - email = "email@example.com", roles = listOf(), url = "https://example.com", ) diff --git a/docs/examples/kotlin/teams/get-prefs.md b/docs/examples/kotlin/teams/get-prefs.md new file mode 100644 index 0000000..b8c2382 --- /dev/null +++ b/docs/examples/kotlin/teams/get-prefs.md @@ -0,0 +1,12 @@ +import io.appwrite.Client +import io.appwrite.services.Teams + +val client = Client(context) + .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + +val teams = Teams(client) + +val response = teams.getPrefs( + teamId = "[TEAM_ID]" +) diff --git a/docs/examples/kotlin/teams/update.md b/docs/examples/kotlin/teams/update-name.md similarity index 89% rename from docs/examples/kotlin/teams/update.md rename to docs/examples/kotlin/teams/update-name.md index 1a54434..9a2dc4a 100644 --- a/docs/examples/kotlin/teams/update.md +++ b/docs/examples/kotlin/teams/update-name.md @@ -7,7 +7,7 @@ val client = Client(context) val teams = Teams(client) -val response = teams.update( +val response = teams.updateName( teamId = "[TEAM_ID]", name = "[NAME]" ) diff --git a/docs/examples/kotlin/teams/update-prefs.md b/docs/examples/kotlin/teams/update-prefs.md new file mode 100644 index 0000000..f7f8f50 --- /dev/null +++ b/docs/examples/kotlin/teams/update-prefs.md @@ -0,0 +1,13 @@ +import io.appwrite.Client +import io.appwrite.services.Teams + +val client = Client(context) + .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint + .setProject("5df5acd0d48c2") // Your project ID + +val teams = Teams(client) + +val response = teams.updatePrefs( + teamId = "[TEAM_ID]", + prefs = mapOf( "a" to "b" ) +) diff --git a/example-java/build.gradle b/example-java/build.gradle index fb916fa..774d3ba 100644 --- a/example-java/build.gradle +++ b/example-java/build.gradle @@ -3,12 +3,12 @@ plugins { } android { - compileSdkVersion 31 + compileSdkVersion 33 defaultConfig { applicationId "io.appwrite.example_java" minSdkVersion 23 - targetSdkVersion 31 + targetSdkVersion 33 versionCode 1 versionName "1.0" @@ -30,10 +30,10 @@ android { dependencies { implementation project(path: ':library') - implementation 'androidx.appcompat:appcompat:1.3.0' - implementation 'com.google.android.material:material:1.3.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' - testImplementation 'junit:junit:4.+' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + implementation 'androidx.appcompat:appcompat:1.6.0' + implementation 'com.google.android.material:material:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' } \ No newline at end of file diff --git a/example/build.gradle b/example/build.gradle index 6c5e1f5..62a34ed 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -4,12 +4,12 @@ plugins { } android { - compileSdkVersion 31 + compileSdkVersion 33 defaultConfig { applicationId "io.appwrite.android" minSdkVersion 21 - targetSdkVersion 31 + targetSdkVersion 33 versionCode 1 versionName "1.0" @@ -39,20 +39,20 @@ dependencies { implementation project(path: ':library') implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'androidx.core:core-ktx:1.6.0' - implementation 'androidx.appcompat:appcompat:1.3.1' - implementation 'com.google.android.material:material:1.4.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.1' - implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5' - implementation "androidx.fragment:fragment-ktx:1.3.6" - implementation 'androidx.navigation:navigation-ui-ktx:2.3.5' - implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1' - implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1' - implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5' - implementation 'androidx.navigation:navigation-ui-ktx:2.3.5' + implementation 'androidx.core:core-ktx:1.9.0' + implementation 'androidx.appcompat:appcompat:1.6.0' + implementation 'com.google.android.material:material:1.8.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3' + implementation "androidx.fragment:fragment-ktx:1.5.5" + implementation 'androidx.navigation:navigation-ui-ktx:2.5.3' + implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1' + implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1' + implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3' + implementation 'androidx.navigation:navigation-ui-ktx:2.5.3' implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2" - testImplementation 'junit:junit:4.+' - androidTestImplementation 'androidx.test.ext:junit:1.1.3' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1" + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2dadb9d..85e684f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Tue Jun 01 15:55:54 IST 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/library/build.gradle b/library/build.gradle index 6be6a48..baa5b1e 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -53,7 +53,7 @@ android { } dependencies { - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION}") + implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version") api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1") api("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1") @@ -65,14 +65,14 @@ dependencies { implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.5.1") implementation("androidx.lifecycle:lifecycle-common-java8:2.5.1") - implementation("androidx.appcompat:appcompat:1.5.1") - implementation("androidx.fragment:fragment-ktx:1.5.3") - implementation("androidx.activity:activity-ktx:1.6.0") + implementation("androidx.appcompat:appcompat:1.6.0") + implementation("androidx.fragment:fragment-ktx:1.5.5") + implementation("androidx.activity:activity-ktx:1.6.1") implementation("androidx.browser:browser:1.4.0") - testImplementation 'junit:junit:4.+' - testImplementation "androidx.test.ext:junit-ktx:1.1.3" - testImplementation "androidx.test:core-ktx:1.4.0" + testImplementation 'junit:junit:4.13.2' + testImplementation "androidx.test.ext:junit-ktx:1.1.5" + testImplementation "androidx.test:core-ktx:1.5.0" testImplementation "org.robolectric:robolectric:4.5.1" testApi("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.1") } diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index 2f8623f..4460d4d 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -88,7 +88,7 @@ class Client @JvmOverloads constructor( "x-sdk-name" to "Android", "x-sdk-platform" to "client", "x-sdk-language" to "android", - "x-sdk-version" to "1.2.1", + "x-sdk-version" to "1.3.0", "x-appwrite-response-format" to "1.0.0" ) config = mutableMapOf() diff --git a/library/src/main/java/io/appwrite/Query.kt b/library/src/main/java/io/appwrite/Query.kt index 2d33a02..ad1f3ed 100644 --- a/library/src/main/java/io/appwrite/Query.kt +++ b/library/src/main/java/io/appwrite/Query.kt @@ -16,6 +16,22 @@ class Query { fun search(attribute: String, value: String) = Query.addQuery(attribute, "search", value) + fun isNull(attribute: String) = "isNull(\"${attribute}\")" + + fun isNotNull(attribute: String) = "isNotNull(\"${attribute}\")" + + fun between(attribute: String, start: Int, end: Int) = Query.addQuery(attribute, "between", listOf(start, end)) + + fun between(attribute: String, start: Double, end: Double) = Query.addQuery(attribute, "between", listOf(start, end)) + + fun between(attribute: String, start: String, end: String) = Query.addQuery(attribute, "between", listOf(start, end)) + + fun startsWith(attribute: String, value: String) = Query.addQuery(attribute, "startsWith", value) + + fun endsWith(attribute: String, value: String) = Query.addQuery(attribute, "endsWith", value) + + fun select(attributes: List) = "select([${attributes.joinToString(",") { "\"$it\"" }}])" + fun orderAsc(attribute: String) = "orderAsc(\"${attribute}\")" fun orderDesc(attribute: String) = "orderDesc(\"${attribute}\")" diff --git a/library/src/main/java/io/appwrite/models/AlgoArgon2.kt b/library/src/main/java/io/appwrite/models/AlgoArgon2.kt new file mode 100644 index 0000000..6230248 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AlgoArgon2.kt @@ -0,0 +1,54 @@ +package io.appwrite.models + +import com.google.gson.annotations.SerializedName +import io.appwrite.extensions.jsonCast + +/** + * AlgoArgon2 + */ +data class AlgoArgon2( + /** + * Algo type. + */ + @SerializedName("type") + val type: String, + + /** + * Memory used to compute hash. + */ + @SerializedName("memoryCost") + val memoryCost: Long, + + /** + * Amount of time consumed to compute hash + */ + @SerializedName("timeCost") + val timeCost: Long, + + /** + * Number of threads used to compute hash. + */ + @SerializedName("threads") + val threads: Long, + +) { + fun toMap(): Map = mapOf( + "type" to type as Any, + "memoryCost" to memoryCost as Any, + "timeCost" to timeCost as Any, + "threads" to threads as Any, + ) + + companion object { + + @Suppress("UNCHECKED_CAST") + fun from( + map: Map, + ) = AlgoArgon2( + type = map["type"] as String, + memoryCost = (map["memoryCost"] as Number).toLong(), + timeCost = (map["timeCost"] as Number).toLong(), + threads = (map["threads"] as Number).toLong(), + ) + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AlgoBcrypt.kt b/library/src/main/java/io/appwrite/models/AlgoBcrypt.kt new file mode 100644 index 0000000..24e74b8 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AlgoBcrypt.kt @@ -0,0 +1,30 @@ +package io.appwrite.models + +import com.google.gson.annotations.SerializedName +import io.appwrite.extensions.jsonCast + +/** + * AlgoBcrypt + */ +data class AlgoBcrypt( + /** + * Algo type. + */ + @SerializedName("type") + val type: String, + +) { + fun toMap(): Map = mapOf( + "type" to type as Any, + ) + + companion object { + + @Suppress("UNCHECKED_CAST") + fun from( + map: Map, + ) = AlgoBcrypt( + type = map["type"] as String, + ) + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AlgoMd5.kt b/library/src/main/java/io/appwrite/models/AlgoMd5.kt new file mode 100644 index 0000000..71baf51 --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AlgoMd5.kt @@ -0,0 +1,30 @@ +package io.appwrite.models + +import com.google.gson.annotations.SerializedName +import io.appwrite.extensions.jsonCast + +/** + * AlgoMD5 + */ +data class AlgoMd5( + /** + * Algo type. + */ + @SerializedName("type") + val type: String, + +) { + fun toMap(): Map = mapOf( + "type" to type as Any, + ) + + companion object { + + @Suppress("UNCHECKED_CAST") + fun from( + map: Map, + ) = AlgoMd5( + type = map["type"] as String, + ) + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AlgoPhpass.kt b/library/src/main/java/io/appwrite/models/AlgoPhpass.kt new file mode 100644 index 0000000..d89b8cf --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AlgoPhpass.kt @@ -0,0 +1,30 @@ +package io.appwrite.models + +import com.google.gson.annotations.SerializedName +import io.appwrite.extensions.jsonCast + +/** + * AlgoPHPass + */ +data class AlgoPhpass( + /** + * Algo type. + */ + @SerializedName("type") + val type: String, + +) { + fun toMap(): Map = mapOf( + "type" to type as Any, + ) + + companion object { + + @Suppress("UNCHECKED_CAST") + fun from( + map: Map, + ) = AlgoPhpass( + type = map["type"] as String, + ) + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AlgoScrypt.kt b/library/src/main/java/io/appwrite/models/AlgoScrypt.kt new file mode 100644 index 0000000..2e4ae1e --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AlgoScrypt.kt @@ -0,0 +1,62 @@ +package io.appwrite.models + +import com.google.gson.annotations.SerializedName +import io.appwrite.extensions.jsonCast + +/** + * AlgoScrypt + */ +data class AlgoScrypt( + /** + * Algo type. + */ + @SerializedName("type") + val type: String, + + /** + * CPU complexity of computed hash. + */ + @SerializedName("costCpu") + val costCpu: Long, + + /** + * Memory complexity of computed hash. + */ + @SerializedName("costMemory") + val costMemory: Long, + + /** + * Parallelization of computed hash. + */ + @SerializedName("costParallel") + val costParallel: Long, + + /** + * Length used to compute hash. + */ + @SerializedName("length") + val length: Long, + +) { + fun toMap(): Map = mapOf( + "type" to type as Any, + "costCpu" to costCpu as Any, + "costMemory" to costMemory as Any, + "costParallel" to costParallel as Any, + "length" to length as Any, + ) + + companion object { + + @Suppress("UNCHECKED_CAST") + fun from( + map: Map, + ) = AlgoScrypt( + type = map["type"] as String, + costCpu = (map["costCpu"] as Number).toLong(), + costMemory = (map["costMemory"] as Number).toLong(), + costParallel = (map["costParallel"] as Number).toLong(), + length = (map["length"] as Number).toLong(), + ) + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AlgoScryptModified.kt b/library/src/main/java/io/appwrite/models/AlgoScryptModified.kt new file mode 100644 index 0000000..3807d6d --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AlgoScryptModified.kt @@ -0,0 +1,54 @@ +package io.appwrite.models + +import com.google.gson.annotations.SerializedName +import io.appwrite.extensions.jsonCast + +/** + * AlgoScryptModified + */ +data class AlgoScryptModified( + /** + * Algo type. + */ + @SerializedName("type") + val type: String, + + /** + * Salt used to compute hash. + */ + @SerializedName("salt") + val salt: String, + + /** + * Separator used to compute hash. + */ + @SerializedName("saltSeparator") + val saltSeparator: String, + + /** + * Key used to compute hash. + */ + @SerializedName("signerKey") + val signerKey: String, + +) { + fun toMap(): Map = mapOf( + "type" to type as Any, + "salt" to salt as Any, + "saltSeparator" to saltSeparator as Any, + "signerKey" to signerKey as Any, + ) + + companion object { + + @Suppress("UNCHECKED_CAST") + fun from( + map: Map, + ) = AlgoScryptModified( + type = map["type"] as String, + salt = map["salt"] as String, + saltSeparator = map["saltSeparator"] as String, + signerKey = map["signerKey"] as String, + ) + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/AlgoSha.kt b/library/src/main/java/io/appwrite/models/AlgoSha.kt new file mode 100644 index 0000000..4209a0e --- /dev/null +++ b/library/src/main/java/io/appwrite/models/AlgoSha.kt @@ -0,0 +1,30 @@ +package io.appwrite.models + +import com.google.gson.annotations.SerializedName +import io.appwrite.extensions.jsonCast + +/** + * AlgoSHA + */ +data class AlgoSha( + /** + * Algo type. + */ + @SerializedName("type") + val type: String, + +) { + fun toMap(): Map = mapOf( + "type" to type as Any, + ) + + companion object { + + @Suppress("UNCHECKED_CAST") + fun from( + map: Map, + ) = AlgoSha( + type = map["type"] as String, + ) + } +} \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Team.kt b/library/src/main/java/io/appwrite/models/Team.kt index 76f7cb2..0723b90 100644 --- a/library/src/main/java/io/appwrite/models/Team.kt +++ b/library/src/main/java/io/appwrite/models/Team.kt @@ -6,7 +6,7 @@ import io.appwrite.extensions.jsonCast /** * Team */ -data class Team( +data class Team( /** * Team ID. */ @@ -37,6 +37,12 @@ data class Team( @SerializedName("total") val total: Long, + /** + * Team preferences as a key-value object + */ + @SerializedName("prefs") + val prefs: Preferences, + ) { fun toMap(): Map = mapOf( "\$id" to id as Any, @@ -44,19 +50,37 @@ data class Team( "\$updatedAt" to updatedAt as Any, "name" to name as Any, "total" to total as Any, + "prefs" to prefs.toMap() as Any, ) companion object { + operator fun invoke( + id: String, + createdAt: String, + updatedAt: String, + name: String, + total: Long, + prefs: Preferences>, + ) = Team>( + id, + createdAt, + updatedAt, + name, + total, + prefs, + ) @Suppress("UNCHECKED_CAST") - fun from( + fun from( map: Map, - ) = Team( + nestedType: Class + ) = Team( id = map["\$id"] as String, createdAt = map["\$createdAt"] as String, updatedAt = map["\$updatedAt"] as String, name = map["name"] as String, total = (map["total"] as Number).toLong(), + prefs = Preferences.from(map = map["prefs"] as Map, nestedType), ) } } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/TeamList.kt b/library/src/main/java/io/appwrite/models/TeamList.kt index ab76ed6..17ccd6b 100644 --- a/library/src/main/java/io/appwrite/models/TeamList.kt +++ b/library/src/main/java/io/appwrite/models/TeamList.kt @@ -6,7 +6,7 @@ import io.appwrite.extensions.jsonCast /** * Teams List */ -data class TeamList( +data class TeamList( /** * Total number of teams documents that matched your query. */ @@ -17,7 +17,7 @@ data class TeamList( * List of teams. */ @SerializedName("teams") - val teams: List, + val teams: List>, ) { fun toMap(): Map = mapOf( @@ -26,13 +26,21 @@ data class TeamList( ) companion object { + operator fun invoke( + total: Long, + teams: List>>, + ) = TeamList>( + total, + teams, + ) @Suppress("UNCHECKED_CAST") - fun from( + fun from( map: Map, - ) = TeamList( + nestedType: Class + ) = TeamList( total = (map["total"] as Number).toLong(), - teams = (map["teams"] as List>).map { Team.from(map = it) }, + teams = (map["teams"] as List>).map { Team.from(map = it, nestedType) }, ) } } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Account.kt b/library/src/main/java/io/appwrite/models/User.kt similarity index 81% rename from library/src/main/java/io/appwrite/models/Account.kt rename to library/src/main/java/io/appwrite/models/User.kt index 1b87beb..81551e6 100644 --- a/library/src/main/java/io/appwrite/models/Account.kt +++ b/library/src/main/java/io/appwrite/models/User.kt @@ -4,9 +4,9 @@ import com.google.gson.annotations.SerializedName import io.appwrite.extensions.jsonCast /** - * Account + * User */ -data class Account( +data class User( /** * User ID. */ @@ -31,6 +31,24 @@ data class Account( @SerializedName("name") val name: String, + /** + * Hashed user password. + */ + @SerializedName("password") + var password: String?, + + /** + * Password hashing algorithm. + */ + @SerializedName("hash") + var hash: String?, + + /** + * Password hashing algorithm configuration. + */ + @SerializedName("hashOptions") + var hashOptions: Any?, + /** * User registration date in ISO 8601 format. */ @@ -85,6 +103,9 @@ data class Account( "\$createdAt" to createdAt as Any, "\$updatedAt" to updatedAt as Any, "name" to name as Any, + "password" to password as Any, + "hash" to hash as Any, + "hashOptions" to hashOptions as Any, "registration" to registration as Any, "status" to status as Any, "passwordUpdate" to passwordUpdate as Any, @@ -101,6 +122,9 @@ data class Account( createdAt: String, updatedAt: String, name: String, + password: String?, + hash: String?, + hashOptions: Any?, registration: String, status: Boolean, passwordUpdate: String, @@ -109,11 +133,14 @@ data class Account( emailVerification: Boolean, phoneVerification: Boolean, prefs: Preferences>, - ) = Account>( + ) = User>( id, createdAt, updatedAt, name, + password, + hash, + hashOptions, registration, status, passwordUpdate, @@ -128,11 +155,14 @@ data class Account( fun from( map: Map, nestedType: Class - ) = Account( + ) = User( id = map["\$id"] as String, createdAt = map["\$createdAt"] as String, updatedAt = map["\$updatedAt"] as String, name = map["name"] as String, + password = map["password"] as? String?, + hash = map["hash"] as? String?, + hashOptions = map["hashOptions"] as? Any?, registration = map["registration"] as String, status = map["status"] as Boolean, passwordUpdate = map["passwordUpdate"] as String, diff --git a/library/src/main/java/io/appwrite/services/Account.kt b/library/src/main/java/io/appwrite/services/Account.kt index fec82f4..2a88a5b 100644 --- a/library/src/main/java/io/appwrite/services/Account.kt +++ b/library/src/main/java/io/appwrite/services/Account.kt @@ -24,11 +24,11 @@ class Account : Service { * * Get currently logged in user data as JSON object. * - * @return [io.appwrite.models.Account] + * @return [io.appwrite.models.User] */ suspend fun get( nestedType: Class, - ): io.appwrite.models.Account { + ): io.appwrite.models.User { val path = "/account" val params = mutableMapOf( @@ -36,8 +36,8 @@ class Account : Service { val headers = mutableMapOf( "content-type" to "application/json", ) - val converter: (Any) -> io.appwrite.models.Account = { - io.appwrite.models.Account.from(map = it as Map, nestedType) + val converter: (Any) -> io.appwrite.models.User = { + io.appwrite.models.User.from(map = it as Map, nestedType) } return client.call( "GET", @@ -54,11 +54,11 @@ class Account : Service { * * Get currently logged in user data as JSON object. * - * @return [io.appwrite.models.Account] + * @return [io.appwrite.models.User] */ @Throws(AppwriteException::class) suspend fun get( - ) = get( + ): io.appwrite.models.User> = get( nestedType = classOf(), ) @@ -69,9 +69,9 @@ class Account : Service { * * @param userId Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @param email User email. - * @param password User password. Must be at least 8 chars. + * @param password New user password. Must be at least 8 chars. * @param name User name. Max length: 128 chars. - * @return [io.appwrite.models.Account] + * @return [io.appwrite.models.User] */ @JvmOverloads suspend fun create( @@ -80,7 +80,7 @@ class Account : Service { password: String, name: String? = null, nestedType: Class, - ): io.appwrite.models.Account { + ): io.appwrite.models.User { val path = "/account" val params = mutableMapOf( @@ -92,8 +92,8 @@ class Account : Service { val headers = mutableMapOf( "content-type" to "application/json", ) - val converter: (Any) -> io.appwrite.models.Account = { - io.appwrite.models.Account.from(map = it as Map, nestedType) + val converter: (Any) -> io.appwrite.models.User = { + io.appwrite.models.User.from(map = it as Map, nestedType) } return client.call( "POST", @@ -112,9 +112,9 @@ class Account : Service { * * @param userId Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @param email User email. - * @param password User password. Must be at least 8 chars. + * @param password New user password. Must be at least 8 chars. * @param name User name. Max length: 128 chars. - * @return [io.appwrite.models.Account] + * @return [io.appwrite.models.User] */ @JvmOverloads @Throws(AppwriteException::class) @@ -123,7 +123,7 @@ class Account : Service { email: String, password: String, name: String? = null, - ) = create( + ): io.appwrite.models.User> = create( userId, email, password, @@ -138,13 +138,13 @@ class Account : Service { * * @param email User email. * @param password User password. Must be at least 8 chars. - * @return [io.appwrite.models.Account] + * @return [io.appwrite.models.User] */ suspend fun updateEmail( email: String, password: String, nestedType: Class, - ): io.appwrite.models.Account { + ): io.appwrite.models.User { val path = "/account/email" val params = mutableMapOf( @@ -154,8 +154,8 @@ class Account : Service { val headers = mutableMapOf( "content-type" to "application/json", ) - val converter: (Any) -> io.appwrite.models.Account = { - io.appwrite.models.Account.from(map = it as Map, nestedType) + val converter: (Any) -> io.appwrite.models.User = { + io.appwrite.models.User.from(map = it as Map, nestedType) } return client.call( "PATCH", @@ -174,13 +174,13 @@ class Account : Service { * * @param email User email. * @param password User password. Must be at least 8 chars. - * @return [io.appwrite.models.Account] + * @return [io.appwrite.models.User] */ @Throws(AppwriteException::class) suspend fun updateEmail( email: String, password: String, - ) = updateEmail( + ): io.appwrite.models.User> = updateEmail( email, password, nestedType = classOf(), @@ -221,7 +221,7 @@ class Account : Service { * * Get currently logged in user list of latest security activity logs. Each log returns user IP address, location and date and time of log. * - * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only supported methods are limit and offset + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset * @return [io.appwrite.models.LogList] */ @JvmOverloads @@ -256,12 +256,12 @@ class Account : Service { * Update currently logged in user account name. * * @param name User name. Max length: 128 chars. - * @return [io.appwrite.models.Account] + * @return [io.appwrite.models.User] */ suspend fun updateName( name: String, nestedType: Class, - ): io.appwrite.models.Account { + ): io.appwrite.models.User { val path = "/account/name" val params = mutableMapOf( @@ -270,8 +270,8 @@ class Account : Service { val headers = mutableMapOf( "content-type" to "application/json", ) - val converter: (Any) -> io.appwrite.models.Account = { - io.appwrite.models.Account.from(map = it as Map, nestedType) + val converter: (Any) -> io.appwrite.models.User = { + io.appwrite.models.User.from(map = it as Map, nestedType) } return client.call( "PATCH", @@ -289,12 +289,12 @@ class Account : Service { * Update currently logged in user account name. * * @param name User name. Max length: 128 chars. - * @return [io.appwrite.models.Account] + * @return [io.appwrite.models.User] */ @Throws(AppwriteException::class) suspend fun updateName( name: String, - ) = updateName( + ): io.appwrite.models.User> = updateName( name, nestedType = classOf(), ) @@ -306,14 +306,14 @@ class Account : Service { * * @param password New user password. Must be at least 8 chars. * @param oldPassword Current user password. Must be at least 8 chars. - * @return [io.appwrite.models.Account] + * @return [io.appwrite.models.User] */ @JvmOverloads suspend fun updatePassword( password: String, oldPassword: String? = null, nestedType: Class, - ): io.appwrite.models.Account { + ): io.appwrite.models.User { val path = "/account/password" val params = mutableMapOf( @@ -323,8 +323,8 @@ class Account : Service { val headers = mutableMapOf( "content-type" to "application/json", ) - val converter: (Any) -> io.appwrite.models.Account = { - io.appwrite.models.Account.from(map = it as Map, nestedType) + val converter: (Any) -> io.appwrite.models.User = { + io.appwrite.models.User.from(map = it as Map, nestedType) } return client.call( "PATCH", @@ -343,14 +343,14 @@ class Account : Service { * * @param password New user password. Must be at least 8 chars. * @param oldPassword Current user password. Must be at least 8 chars. - * @return [io.appwrite.models.Account] + * @return [io.appwrite.models.User] */ @JvmOverloads @Throws(AppwriteException::class) suspend fun updatePassword( password: String, oldPassword: String? = null, - ) = updatePassword( + ): io.appwrite.models.User> = updatePassword( password, oldPassword, nestedType = classOf(), @@ -363,13 +363,13 @@ class Account : Service { * * @param phone Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212. * @param password User password. Must be at least 8 chars. - * @return [io.appwrite.models.Account] + * @return [io.appwrite.models.User] */ suspend fun updatePhone( phone: String, password: String, nestedType: Class, - ): io.appwrite.models.Account { + ): io.appwrite.models.User { val path = "/account/phone" val params = mutableMapOf( @@ -379,8 +379,8 @@ class Account : Service { val headers = mutableMapOf( "content-type" to "application/json", ) - val converter: (Any) -> io.appwrite.models.Account = { - io.appwrite.models.Account.from(map = it as Map, nestedType) + val converter: (Any) -> io.appwrite.models.User = { + io.appwrite.models.User.from(map = it as Map, nestedType) } return client.call( "PATCH", @@ -399,13 +399,13 @@ class Account : Service { * * @param phone Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212. * @param password User password. Must be at least 8 chars. - * @return [io.appwrite.models.Account] + * @return [io.appwrite.models.User] */ @Throws(AppwriteException::class) suspend fun updatePhone( phone: String, password: String, - ) = updatePhone( + ): io.appwrite.models.User> = updatePhone( phone, password, nestedType = classOf(), @@ -450,7 +450,7 @@ class Account : Service { */ @Throws(AppwriteException::class) suspend fun getPrefs( - ) = getPrefs( + ): io.appwrite.models.Preferences> = getPrefs( nestedType = classOf(), ) @@ -460,12 +460,12 @@ class Account : Service { * Update currently logged in user account preferences. The object you pass is stored as is, and replaces any previous value. The maximum allowed prefs size is 64kB and throws error if exceeded. * * @param prefs Prefs key-value JSON object. - * @return [io.appwrite.models.Account] + * @return [io.appwrite.models.User] */ suspend fun updatePrefs( prefs: Any, nestedType: Class, - ): io.appwrite.models.Account { + ): io.appwrite.models.User { val path = "/account/prefs" val params = mutableMapOf( @@ -474,8 +474,8 @@ class Account : Service { val headers = mutableMapOf( "content-type" to "application/json", ) - val converter: (Any) -> io.appwrite.models.Account = { - io.appwrite.models.Account.from(map = it as Map, nestedType) + val converter: (Any) -> io.appwrite.models.User = { + io.appwrite.models.User.from(map = it as Map, nestedType) } return client.call( "PATCH", @@ -493,12 +493,12 @@ class Account : Service { * Update currently logged in user account preferences. The object you pass is stored as is, and replaces any previous value. The maximum allowed prefs size is 64kB and throws error if exceeded. * * @param prefs Prefs key-value JSON object. - * @return [io.appwrite.models.Account] + * @return [io.appwrite.models.User] */ @Throws(AppwriteException::class) suspend fun updatePrefs( prefs: Any, - ) = updatePrefs( + ): io.appwrite.models.User> = updatePrefs( prefs, nestedType = classOf(), ) @@ -670,7 +670,7 @@ class Account : Service { /** * Create Email Session * - * Allow the user to login into their account by providing a valid email and password combination. This route will create a new session for the user.A user is limited to 10 active sessions at a time by default. [Learn more about session limits](/docs/authentication#limits). + * Allow the user to login into their account by providing a valid email and password combination. This route will create a new session for the user.A user is limited to 10 active sessions at a time by default. [Learn more about session limits](/docs/authentication-security#limits). * * @param email User email. * @param password User password. Must be at least 8 chars. @@ -706,7 +706,7 @@ class Account : Service { /** * Create Magic URL session * - * Sends the user an email with a secret key for creating a session. If the provided user ID has not be registered, a new user will be created. When the user clicks the link in the email, the user is redirected back to the URL you provided with the secret key and userId values attached to the URL query string. Use the query string parameters to submit a request to the [PUT /account/sessions/magic-url](/docs/client/account#accountUpdateMagicURLSession) endpoint to complete the login process. The link sent to the user's email address is valid for 1 hour. If you are on a mobile device you can leave the URL parameter empty, so that the login completion will be handled by your Appwrite instance by default.A user is limited to 10 active sessions at a time by default. [Learn more about session limits](/docs/authentication#limits). + * Sends the user an email with a secret key for creating a session. If the provided user ID has not be registered, a new user will be created. When the user clicks the link in the email, the user is redirected back to the URL you provided with the secret key and userId values attached to the URL query string. Use the query string parameters to submit a request to the [PUT /account/sessions/magic-url](/docs/client/account#accountUpdateMagicURLSession) endpoint to complete the login process. The link sent to the user's email address is valid for 1 hour. If you are on a mobile device you can leave the URL parameter empty, so that the login completion will be handled by your Appwrite instance by default.A user is limited to 10 active sessions at a time by default. [Learn more about session limits](/docs/authentication-security#limits). * * @param userId Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @param email User email. @@ -782,7 +782,7 @@ class Account : Service { /** * Create OAuth2 Session * - * Allow the user to login to their account using the OAuth2 provider of their choice. Each OAuth2 provider should be enabled from the Appwrite console first. Use the success and failure arguments to provide a redirect URL's back to your app when login is completed.If there is already an active session, the new session will be attached to the logged-in account. If there are no active sessions, the server will attempt to look for a user with the same email address as the email received from the OAuth2 provider and attach the new session to the existing user. If no matching user is found - the server will create a new user.A user is limited to 10 active sessions at a time by default. [Learn more about session limits](/docs/authentication#limits). + * Allow the user to login to their account using the OAuth2 provider of their choice. Each OAuth2 provider should be enabled from the Appwrite console first. Use the success and failure arguments to provide a redirect URL's back to your app when login is completed.If there is already an active session, the new session will be attached to the logged-in account. If there are no active sessions, the server will attempt to look for a user with the same email address as the email received from the OAuth2 provider and attach the new session to the existing user. If no matching user is found - the server will create a new user.A user is limited to 10 active sessions at a time by default. [Learn more about session limits](/docs/authentication-security#limits). * * @param provider OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, github, gitlab, google, linkedin, microsoft, notion, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoom. * @param success URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. @@ -854,7 +854,7 @@ class Account : Service { /** * Create Phone session * - * Sends the user an SMS with a secret key for creating a session. If the provided user ID has not be registered, a new user will be created. Use the returned user ID and secret and submit a request to the [PUT /account/sessions/phone](/docs/client/account#accountUpdatePhoneSession) endpoint to complete the login process. The secret sent to the user's phone is valid for 15 minutes.A user is limited to 10 active sessions at a time by default. [Learn more about session limits](/docs/authentication#limits). + * Sends the user an SMS with a secret key for creating a session. If the provided user ID has not be registered, a new user will be created. Use the returned user ID and secret and submit a request to the [PUT /account/sessions/phone](/docs/client/account#accountUpdatePhoneSession) endpoint to complete the login process. The secret sent to the user's phone is valid for 15 minutes.A user is limited to 10 active sessions at a time by default. [Learn more about session limits](/docs/authentication-security#limits). * * @param userId Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @param phone Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212. @@ -1023,11 +1023,11 @@ class Account : Service { * * Block the currently logged in user account. Behind the scene, the user record is not deleted but permanently blocked from any access. To completely delete a user, use the Users API instead. * - * @return [io.appwrite.models.Account] + * @return [io.appwrite.models.User] */ suspend fun updateStatus( nestedType: Class, - ): io.appwrite.models.Account { + ): io.appwrite.models.User { val path = "/account/status" val params = mutableMapOf( @@ -1035,8 +1035,8 @@ class Account : Service { val headers = mutableMapOf( "content-type" to "application/json", ) - val converter: (Any) -> io.appwrite.models.Account = { - io.appwrite.models.Account.from(map = it as Map, nestedType) + val converter: (Any) -> io.appwrite.models.User = { + io.appwrite.models.User.from(map = it as Map, nestedType) } return client.call( "PATCH", @@ -1053,11 +1053,11 @@ class Account : Service { * * Block the currently logged in user account. Behind the scene, the user record is not deleted but permanently blocked from any access. To completely delete a user, use the Users API instead. * - * @return [io.appwrite.models.Account] + * @return [io.appwrite.models.User] */ @Throws(AppwriteException::class) suspend fun updateStatus( - ) = updateStatus( + ): io.appwrite.models.User> = updateStatus( nestedType = classOf(), ) diff --git a/library/src/main/java/io/appwrite/services/Databases.kt b/library/src/main/java/io/appwrite/services/Databases.kt index 26094eb..0744693 100644 --- a/library/src/main/java/io/appwrite/services/Databases.kt +++ b/library/src/main/java/io/appwrite/services/Databases.kt @@ -22,7 +22,7 @@ class Databases : Service { * * @param databaseId Database ID. * @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). - * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of 100 queries are allowed, each 4096 characters long. + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. * @return [io.appwrite.models.DocumentList] */ @JvmOverloads @@ -62,7 +62,7 @@ class Databases : Service { * * @param databaseId Database ID. * @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). - * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of 100 queries are allowed, each 4096 characters long. + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. * @return [io.appwrite.models.DocumentList] */ @JvmOverloads @@ -71,7 +71,7 @@ class Databases : Service { databaseId: String, collectionId: String, queries: List? = null, - ) = listDocuments( + ): io.appwrite.models.DocumentList> = listDocuments( databaseId, collectionId, queries, @@ -144,7 +144,7 @@ class Databases : Service { documentId: String, data: Any, permissions: List? = null, - ) = createDocument( + ): io.appwrite.models.Document> = createDocument( databaseId, collectionId, documentId, @@ -161,12 +161,15 @@ class Databases : Service { * @param databaseId Database ID. * @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @param documentId Document ID. + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only method allowed is select. * @return [io.appwrite.models.Document] */ + @JvmOverloads suspend fun getDocument( databaseId: String, collectionId: String, documentId: String, + queries: List? = null, nestedType: Class, ): io.appwrite.models.Document { val path = "/databases/{databaseId}/collections/{collectionId}/documents/{documentId}" @@ -175,6 +178,7 @@ class Databases : Service { .replace("{documentId}", documentId) val params = mutableMapOf( + "queries" to queries, ) val headers = mutableMapOf( "content-type" to "application/json", @@ -200,17 +204,21 @@ class Databases : Service { * @param databaseId Database ID. * @param collectionId Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). * @param documentId Document ID. + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Only method allowed is select. * @return [io.appwrite.models.Document] */ + @JvmOverloads @Throws(AppwriteException::class) suspend fun getDocument( databaseId: String, collectionId: String, documentId: String, - ) = getDocument( + queries: List? = null, + ): io.appwrite.models.Document> = getDocument( databaseId, collectionId, documentId, + queries, nestedType = classOf(), ) @@ -280,7 +288,7 @@ class Databases : Service { documentId: String, data: Any? = null, permissions: List? = null, - ) = updateDocument( + ): io.appwrite.models.Document> = updateDocument( databaseId, collectionId, documentId, diff --git a/library/src/main/java/io/appwrite/services/Functions.kt b/library/src/main/java/io/appwrite/services/Functions.kt index a9d33ca..ffa350a 100644 --- a/library/src/main/java/io/appwrite/services/Functions.kt +++ b/library/src/main/java/io/appwrite/services/Functions.kt @@ -21,7 +21,7 @@ class Functions : Service { * Get a list of all the current user function execution logs. You can use the query params to filter your results. * * @param functionId Function ID. - * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: trigger, status, statusCode, duration + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: trigger, status, statusCode, duration * @param search Search term to filter your list results. Max length: 256 chars. * @return [io.appwrite.models.ExecutionList] */ diff --git a/library/src/main/java/io/appwrite/services/Storage.kt b/library/src/main/java/io/appwrite/services/Storage.kt index fd7dc1b..ecc9284 100644 --- a/library/src/main/java/io/appwrite/services/Storage.kt +++ b/library/src/main/java/io/appwrite/services/Storage.kt @@ -23,7 +23,7 @@ class Storage : Service { * Get a list of all the user files. You can use the query params to filter your results. * * @param bucketId Storage bucket unique ID. You can create a new storage bucket using the Storage service [server integration](/docs/server/storage#createBucket). - * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, signature, mimeType, sizeOriginal, chunksTotal, chunksUploaded + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, signature, mimeType, sizeOriginal, chunksTotal, chunksUploaded * @param search Search term to filter your list results. Max length: 256 chars. * @return [io.appwrite.models.FileList] */ diff --git a/library/src/main/java/io/appwrite/services/Teams.kt b/library/src/main/java/io/appwrite/services/Teams.kt index e188330..333f438 100644 --- a/library/src/main/java/io/appwrite/services/Teams.kt +++ b/library/src/main/java/io/appwrite/services/Teams.kt @@ -20,15 +20,16 @@ class Teams : Service { * * Get a list of all the teams in which the current user is a member. You can use the parameters to filter your results. * - * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, total + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, total * @param search Search term to filter your list results. Max length: 256 chars. - * @return [io.appwrite.models.TeamList] + * @return [io.appwrite.models.TeamList] */ @JvmOverloads - suspend fun list( + suspend fun list( queries: List? = null, search: String? = null, - ): io.appwrite.models.TeamList { + nestedType: Class, + ): io.appwrite.models.TeamList { val path = "/teams" val params = mutableMapOf( @@ -38,19 +39,38 @@ class Teams : Service { val headers = mutableMapOf( "content-type" to "application/json", ) - val converter: (Any) -> io.appwrite.models.TeamList = { - io.appwrite.models.TeamList.from(map = it as Map) + val converter: (Any) -> io.appwrite.models.TeamList = { + io.appwrite.models.TeamList.from(map = it as Map, nestedType) } return client.call( "GET", path, headers, params, - responseType = io.appwrite.models.TeamList::class.java, + responseType = classOf(), converter, ) } + /** + * List Teams + * + * Get a list of all the teams in which the current user is a member. You can use the parameters to filter your results. + * + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, total + * @param search Search term to filter your list results. Max length: 256 chars. + * @return [io.appwrite.models.TeamList] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun list( + queries: List? = null, + search: String? = null, + ): io.appwrite.models.TeamList> = list( + queries, + search, + nestedType = classOf(), + ) /** * Create Team @@ -60,14 +80,15 @@ class Teams : Service { * @param teamId Team ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @param name Team name. Max length: 128 chars. * @param roles Array of strings. Use this param to set the roles in the team for the user who created it. The default role is **owner**. A role can be any string. Learn more about [roles and permissions](/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long. - * @return [io.appwrite.models.Team] + * @return [io.appwrite.models.Team] */ @JvmOverloads - suspend fun create( + suspend fun create( teamId: String, name: String, roles: List? = null, - ): io.appwrite.models.Team { + nestedType: Class, + ): io.appwrite.models.Team { val path = "/teams" val params = mutableMapOf( @@ -78,19 +99,41 @@ class Teams : Service { val headers = mutableMapOf( "content-type" to "application/json", ) - val converter: (Any) -> io.appwrite.models.Team = { - io.appwrite.models.Team.from(map = it as Map) + val converter: (Any) -> io.appwrite.models.Team = { + io.appwrite.models.Team.from(map = it as Map, nestedType) } return client.call( "POST", path, headers, params, - responseType = io.appwrite.models.Team::class.java, + responseType = classOf(), converter, ) } + /** + * Create Team + * + * Create a new team. The user who creates the team will automatically be assigned as the owner of the team. Only the users with the owner role can invite new members, add new owners and delete or update the team. + * + * @param teamId Team ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. + * @param name Team name. Max length: 128 chars. + * @param roles Array of strings. Use this param to set the roles in the team for the user who created it. The default role is **owner**. A role can be any string. Learn more about [roles and permissions](/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long. + * @return [io.appwrite.models.Team] + */ + @JvmOverloads + @Throws(AppwriteException::class) + suspend fun create( + teamId: String, + name: String, + roles: List? = null, + ): io.appwrite.models.Team> = create( + teamId, + name, + roles, + nestedType = classOf(), + ) /** * Get Team @@ -98,11 +141,12 @@ class Teams : Service { * Get a team by its ID. All team members have read access for this resource. * * @param teamId Team ID. - * @return [io.appwrite.models.Team] + * @return [io.appwrite.models.Team] */ - suspend fun get( + suspend fun get( teamId: String, - ): io.appwrite.models.Team { + nestedType: Class, + ): io.appwrite.models.Team { val path = "/teams/{teamId}" .replace("{teamId}", teamId) @@ -111,33 +155,49 @@ class Teams : Service { val headers = mutableMapOf( "content-type" to "application/json", ) - val converter: (Any) -> io.appwrite.models.Team = { - io.appwrite.models.Team.from(map = it as Map) + val converter: (Any) -> io.appwrite.models.Team = { + io.appwrite.models.Team.from(map = it as Map, nestedType) } return client.call( "GET", path, headers, params, - responseType = io.appwrite.models.Team::class.java, + responseType = classOf(), converter, ) } + /** + * Get Team + * + * Get a team by its ID. All team members have read access for this resource. + * + * @param teamId Team ID. + * @return [io.appwrite.models.Team] + */ + @Throws(AppwriteException::class) + suspend fun get( + teamId: String, + ): io.appwrite.models.Team> = get( + teamId, + nestedType = classOf(), + ) /** - * Update Team + * Update Name * - * Update a team using its ID. Only members with the owner role can update the team. + * Update the team's name by its unique ID. * * @param teamId Team ID. * @param name New team name. Max length: 128 chars. - * @return [io.appwrite.models.Team] + * @return [io.appwrite.models.Team] */ - suspend fun update( + suspend fun updateName( teamId: String, name: String, - ): io.appwrite.models.Team { + nestedType: Class, + ): io.appwrite.models.Team { val path = "/teams/{teamId}" .replace("{teamId}", teamId) @@ -147,19 +207,37 @@ class Teams : Service { val headers = mutableMapOf( "content-type" to "application/json", ) - val converter: (Any) -> io.appwrite.models.Team = { - io.appwrite.models.Team.from(map = it as Map) + val converter: (Any) -> io.appwrite.models.Team = { + io.appwrite.models.Team.from(map = it as Map, nestedType) } return client.call( "PUT", path, headers, params, - responseType = io.appwrite.models.Team::class.java, + responseType = classOf(), converter, ) } + /** + * Update Name + * + * Update the team's name by its unique ID. + * + * @param teamId Team ID. + * @param name New team name. Max length: 128 chars. + * @return [io.appwrite.models.Team] + */ + @Throws(AppwriteException::class) + suspend fun updateName( + teamId: String, + name: String, + ): io.appwrite.models.Team> = updateName( + teamId, + name, + nestedType = classOf(), + ) /** * Delete Team @@ -196,7 +274,7 @@ class Teams : Service { * Use this endpoint to list a team's members using the team's ID. All team members have read access to this endpoint. * * @param teamId Team ID. - * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/databases#querying-documents). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: userId, teamId, invited, joined, confirm + * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: userId, teamId, invited, joined, confirm * @param search Search term to filter your list results. Max length: 256 chars. * @return [io.appwrite.models.MembershipList] */ @@ -233,21 +311,25 @@ class Teams : Service { /** * Create Team Membership * - * Invite a new member to join your team. If initiated from the client SDK, an email with a link to join the team will be sent to the member's email address and an account will be created for them should they not be signed up already. If initiated from server-side SDKs, the new member will automatically be added to the team.Use the 'url' parameter to redirect the user from the invitation email back to your app. When the user is redirected, use the [Update Team Membership Status](/docs/client/teams#teamsUpdateMembershipStatus) endpoint to allow the user to accept the invitation to the team. Please note that to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) the only valid redirect URL's are the once from domains you have set when adding your platforms in the console interface. + * Invite a new member to join your team. Provide an ID for existing users, or invite unregistered users using an email or phone number. If initiated from a Client SDK, Appwrite will send an email or sms with a link to join the team to the invited user, and an account will be created for them if one doesn't exist. If initiated from a Server SDK, the new member will be added automatically to the team.You only need to provide one of a user ID, email, or phone number. Appwrite will prioritize accepting the user ID > email > phone number if you provide more than one of these parameters.Use the `url` parameter to redirect the user from the invitation email to your app. After the user is redirected, use the [Update Team Membership Status](/docs/client/teams#teamsUpdateMembershipStatus) endpoint to allow the user to accept the invitation to the team. Please note that to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) Appwrite will accept the only redirect URLs under the domains you have added as a platform on the Appwrite Console. * * @param teamId Team ID. - * @param email Email of the new team member. * @param roles Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long. * @param url URL to redirect the user back to your app from the invitation email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. + * @param email Email of the new team member. + * @param userId ID of the user to be added to a team. + * @param phone Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212. * @param name Name of the new team member. Max length: 128 chars. * @return [io.appwrite.models.Membership] */ @JvmOverloads suspend fun createMembership( teamId: String, - email: String, roles: List, url: String, + email: String? = null, + userId: String? = null, + phone: String? = null, name: String? = null, ): io.appwrite.models.Membership { val path = "/teams/{teamId}/memberships" @@ -255,6 +337,8 @@ class Teams : Service { val params = mutableMapOf( "email" to email, + "userId" to userId, + "phone" to phone, "roles" to roles, "url" to url, "name" to name, @@ -425,4 +509,108 @@ class Teams : Service { } + /** + * Get Team Preferences + * + * Get the team's shared preferences by its unique ID. If a preference doesn't need to be shared by all team members, prefer storing them in [user preferences](/docs/client/account#accountGetPrefs). + * + * @param teamId Team ID. + * @return [io.appwrite.models.Preferences] + */ + suspend fun getPrefs( + teamId: String, + nestedType: Class, + ): io.appwrite.models.Preferences { + val path = "/teams/{teamId}/prefs" + .replace("{teamId}", teamId) + + val params = mutableMapOf( + ) + val headers = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Preferences = { + io.appwrite.models.Preferences.from(map = it as Map, nestedType) + } + return client.call( + "GET", + path, + headers, + params, + responseType = classOf(), + converter, + ) + } + + /** + * Get Team Preferences + * + * Get the team's shared preferences by its unique ID. If a preference doesn't need to be shared by all team members, prefer storing them in [user preferences](/docs/client/account#accountGetPrefs). + * + * @param teamId Team ID. + * @return [io.appwrite.models.Preferences] + */ + @Throws(AppwriteException::class) + suspend fun getPrefs( + teamId: String, + ): io.appwrite.models.Preferences> = getPrefs( + teamId, + nestedType = classOf(), + ) + + /** + * Update Preferences + * + * Update the team's preferences by its unique ID. The object you pass is stored as is and replaces any previous value. The maximum allowed prefs size is 64kB and throws an error if exceeded. + * + * @param teamId Team ID. + * @param prefs Prefs key-value JSON object. + * @return [io.appwrite.models.Preferences] + */ + suspend fun updatePrefs( + teamId: String, + prefs: Any, + nestedType: Class, + ): io.appwrite.models.Preferences { + val path = "/teams/{teamId}/prefs" + .replace("{teamId}", teamId) + + val params = mutableMapOf( + "prefs" to prefs, + ) + val headers = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Preferences = { + io.appwrite.models.Preferences.from(map = it as Map, nestedType) + } + return client.call( + "PUT", + path, + headers, + params, + responseType = classOf(), + converter, + ) + } + + /** + * Update Preferences + * + * Update the team's preferences by its unique ID. The object you pass is stored as is and replaces any previous value. The maximum allowed prefs size is 64kB and throws an error if exceeded. + * + * @param teamId Team ID. + * @param prefs Prefs key-value JSON object. + * @return [io.appwrite.models.Preferences] + */ + @Throws(AppwriteException::class) + suspend fun updatePrefs( + teamId: String, + prefs: Any, + ): io.appwrite.models.Preferences> = updatePrefs( + teamId, + prefs, + nestedType = classOf(), + ) + } \ No newline at end of file