diff --git a/LICENSE.md b/LICENSE.md index 5479bb8..c1602fc 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2024 Appwrite (https://appwrite.io) and individual contributors. +Copyright (c) 2025 Appwrite (https://appwrite.io) and individual contributors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/README.md b/README.md index 5786e19..be83985 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-kotlin:6.2.0") +implementation("io.appwrite:sdk-for-kotlin:7.0.0") ``` ### Maven @@ -50,7 +50,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-kotlin - 6.2.0 + 7.0.0 ``` diff --git a/src/main/kotlin/io/appwrite/Client.kt b/src/main/kotlin/io/appwrite/Client.kt index c8ff8d9..cf5e7c4 100644 --- a/src/main/kotlin/io/appwrite/Client.kt +++ b/src/main/kotlin/io/appwrite/Client.kt @@ -57,11 +57,11 @@ class Client @JvmOverloads constructor( init { headers = mutableMapOf( "content-type" to "application/json", - "user-agent" to "AppwriteKotlinSDK/6.2.0 ${System.getProperty("http.agent")}", + "user-agent" to "AppwriteKotlinSDK/7.0.0 ${System.getProperty("http.agent")}", "x-sdk-name" to "Kotlin", "x-sdk-platform" to "server", "x-sdk-language" to "kotlin", - "x-sdk-version" to "6.2.0", + "x-sdk-version" to "7.0.0", "x-appwrite-response-format" to "1.6.0", ) @@ -235,9 +235,28 @@ class Client @JvmOverloads constructor( return this } + /** + * Sends a "ping" request to Appwrite to verify connectivity. + * + * @return String + */ + suspend fun ping(): String { + val apiPath = "/ping" + val apiParams = mutableMapOf() + val apiHeaders = mutableMapOf("content-type" to "application/json") + + return call( + "GET", + apiPath, + apiHeaders, + apiParams, + responseType = String::class.java + ) + } + /** * Prepare the HTTP request - * + * * @param method * @param path * @param headers @@ -332,7 +351,7 @@ class Client @JvmOverloads constructor( * @param headers * @param params * - * @return [T] + * @return [T] */ @Throws(AppwriteException::class) suspend fun call( @@ -355,7 +374,7 @@ class Client @JvmOverloads constructor( * @param headers * @param params * - * @return [T] + * @return [T] */ @Throws(AppwriteException::class) suspend fun redirect( @@ -427,7 +446,7 @@ class Client @JvmOverloads constructor( var offset = 0L var result: Map<*, *>? = null - if (idParamName?.isNotEmpty() == true && params[idParamName] != "unique()") { + if (idParamName?.isNotEmpty() == true) { // Make a request to check if a file already exists val current = call( method = "GET", @@ -494,7 +513,7 @@ class Client @JvmOverloads constructor( return converter(result as Map) } - /** + /** * Await Redirect * * @param request @@ -521,14 +540,14 @@ class Client @JvmOverloads constructor( .charStream() .buffered() .use(BufferedReader::readText) - + val error = if (response.headers["content-type"]?.contains("application/json") == true) { val map = body.fromJson>() AppwriteException( - map["message"] as? String ?: "", + map["message"] as? String ?: "", (map["code"] as Number).toInt(), - map["type"] as? String ?: "", + map["type"] as? String ?: "", body ) } else { @@ -572,14 +591,14 @@ class Client @JvmOverloads constructor( .charStream() .buffered() .use(BufferedReader::readText) - + val error = if (response.headers["content-type"]?.contains("application/json") == true) { val map = body.fromJson>() AppwriteException( - map["message"] as? String ?: "", + map["message"] as? String ?: "", (map["code"] as Number).toInt(), - map["type"] as? String ?: "", + map["type"] as? String ?: "", body ) } else { @@ -601,6 +620,14 @@ class Client @JvmOverloads constructor( it.resume(true as T) return } + responseType == String::class.java -> { + val body = response.body!! + .charStream() + .buffered() + .use(BufferedReader::readText) + it.resume(body as T) + return + } responseType == ByteArray::class.java -> { it.resume(response.body!! .byteStream() @@ -629,4 +656,4 @@ class Client @JvmOverloads constructor( } }) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/io/appwrite/enums/ImageFormat.kt b/src/main/kotlin/io/appwrite/enums/ImageFormat.kt index 25eea90..7249f2a 100644 --- a/src/main/kotlin/io/appwrite/enums/ImageFormat.kt +++ b/src/main/kotlin/io/appwrite/enums/ImageFormat.kt @@ -13,6 +13,8 @@ enum class ImageFormat(val value: String) { PNG("png"), @SerializedName("webp") WEBP("webp"), + @SerializedName("heic") + HEIC("heic"), @SerializedName("avif") AVIF("avif"); diff --git a/src/main/kotlin/io/appwrite/services/Account.kt b/src/main/kotlin/io/appwrite/services/Account.kt index aaa851c..a06e99f 100644 --- a/src/main/kotlin/io/appwrite/services/Account.kt +++ b/src/main/kotlin/io/appwrite/services/Account.kt @@ -518,13 +518,13 @@ class Account(client: Client) : Service(client) { * * @param challengeId ID of the challenge. * @param otp Valid verification token. - * @return [Any] + * @return [io.appwrite.models.Session] */ @Throws(AppwriteException::class) suspend fun updateMfaChallenge( challengeId: String, otp: String, - ): Any { + ): io.appwrite.models.Session { val apiPath = "/account/mfa/challenge" val apiParams = mutableMapOf( @@ -534,12 +534,16 @@ class Account(client: Client) : Service(client) { val apiHeaders = mutableMapOf( "content-type" to "application/json", ) + val converter: (Any) -> io.appwrite.models.Session = { + io.appwrite.models.Session.from(map = it as Map) + } return client.call( "PUT", apiPath, apiHeaders, apiParams, - responseType = Any::class.java, + responseType = io.appwrite.models.Session::class.java, + converter, ) } diff --git a/src/main/kotlin/io/appwrite/services/Functions.kt b/src/main/kotlin/io/appwrite/services/Functions.kt index d0a98f5..df94e53 100644 --- a/src/main/kotlin/io/appwrite/services/Functions.kt +++ b/src/main/kotlin/io/appwrite/services/Functions.kt @@ -554,7 +554,7 @@ class Functions(client: Client) : Service(client) { /** * Rebuild deployment * - * + * Create a new build for an existing function deployment. This endpoint allows you to rebuild a deployment with the updated function configuration, including its entrypoint and build commands if they have been modified The build process will be queued and executed asynchronously. The original deployment's code will be preserved and used for the new build. * * @param functionId Function ID. * @param deploymentId Deployment ID. @@ -590,7 +590,7 @@ class Functions(client: Client) : Service(client) { /** * Cancel deployment * - * + * Cancel an ongoing function deployment build. If the build is already in progress, it will be stopped and marked as canceled. If the build hasn't started yet, it will be marked as canceled without executing. You cannot cancel builds that have already completed (status 'ready') or failed. The response includes the final build status and details. * * @param functionId Function ID. * @param deploymentId Deployment ID. diff --git a/src/main/kotlin/io/appwrite/services/Messaging.kt b/src/main/kotlin/io/appwrite/services/Messaging.kt index be6c259..b1eac2a 100644 --- a/src/main/kotlin/io/appwrite/services/Messaging.kt +++ b/src/main/kotlin/io/appwrite/services/Messaging.kt @@ -415,7 +415,7 @@ class Messaging(client: Client) : Service(client) { /** * Update SMS * - * Update an email message by its unique ID. + * Update an SMS message by its unique ID. * * @param messageId Message ID. * @param topics List of Topic IDs. diff --git a/src/main/kotlin/io/appwrite/services/Users.kt b/src/main/kotlin/io/appwrite/services/Users.kt index 28c3cf3..00d266b 100644 --- a/src/main/kotlin/io/appwrite/services/Users.kt +++ b/src/main/kotlin/io/appwrite/services/Users.kt @@ -1121,14 +1121,13 @@ class Users(client: Client) : Service(client) { * * @param userId User ID. * @param type Type of authenticator. - * @return [io.appwrite.models.User] + * @return [Any] */ @Throws(AppwriteException::class) - suspend fun deleteMfaAuthenticator( + suspend fun deleteMfaAuthenticator( userId: String, type: io.appwrite.enums.AuthenticatorType, - nestedType: Class, - ): io.appwrite.models.User { + ): Any { val apiPath = "/users/{userId}/mfa/authenticators/{type}" .replace("{userId}", userId) .replace("{type}", type.value) @@ -1138,38 +1137,15 @@ class Users(client: Client) : Service(client) { val apiHeaders = mutableMapOf( "content-type" to "application/json", ) - val converter: (Any) -> io.appwrite.models.User = { - io.appwrite.models.User.from(map = it as Map, nestedType) - } return client.call( "DELETE", apiPath, apiHeaders, apiParams, - responseType = classOf(), - converter, + responseType = Any::class.java, ) } - /** - * Delete authenticator - * - * Delete an authenticator app. - * - * @param userId User ID. - * @param type Type of authenticator. - * @return [io.appwrite.models.User] - */ - @Throws(AppwriteException::class) - suspend fun deleteMfaAuthenticator( - userId: String, - type: io.appwrite.enums.AuthenticatorType, - ): io.appwrite.models.User> = deleteMfaAuthenticator( - userId, - type, - nestedType = classOf(), - ) - /** * List factors *