From 3017598d1ca9a876989099a934b7f373186701ca Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 24 Apr 2024 19:28:09 +1200 Subject: [PATCH 1/2] Fix okttp with AGP 8.2+ --- README.md | 6 ++-- library/build.gradle | 5 +-- library/src/main/java/io/appwrite/Client.kt | 2 +- library/src/main/java/io/appwrite/ID.kt | 30 +++++++++++++++-- .../java/io/appwrite/models/MfaFactors.kt | 14 ++++++-- .../main/java/io/appwrite/models/Session.kt | 8 +++++ .../main/java/io/appwrite/services/Account.kt | 32 +++---------------- 7 files changed, 55 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 67a7e52..57a4335 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Maven Central](https://img.shields.io/maven-central/v/io.appwrite/sdk-for-android.svg?color=green&style=flat-square) ![License](https://img.shields.io/github/license/appwrite/sdk-for-android.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.5.1-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.5.4-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![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) @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:5.0.0") +implementation("io.appwrite:sdk-for-android:5.0.1") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 5.0.0 + 5.0.1 ``` diff --git a/library/build.gradle b/library/build.gradle index b741c76..998da2b 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -59,10 +59,7 @@ dependencies { api("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1") api("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1") - api(platform("com.squareup.okhttp3:okhttp-bom:4.12.0")) - api("com.squareup.okhttp3:okhttp") - implementation("com.squareup.okhttp3:okhttp-urlconnection") - implementation("com.squareup.okhttp3:logging-interceptor") + implementation("com.squareup.okhttp3:okhttp:4.12.0") implementation("com.google.code.gson:gson:2.10.1") implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0") diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index 4eb2557..f2db946 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -83,7 +83,7 @@ class Client @JvmOverloads constructor( "x-sdk-name" to "Android", "x-sdk-platform" to "client", "x-sdk-language" to "android", - "x-sdk-version" to "5.0.0", + "x-sdk-version" to "5.0.1", "x-appwrite-response-format" to "1.5.0" ) config = mutableMapOf() diff --git a/library/src/main/java/io/appwrite/ID.kt b/library/src/main/java/io/appwrite/ID.kt index fe8e656..e661192 100644 --- a/library/src/main/java/io/appwrite/ID.kt +++ b/library/src/main/java/io/appwrite/ID.kt @@ -1,10 +1,34 @@ package io.appwrite +import java.time.Instant +import kotlin.math.floor +import kotlin.random.Random + class ID { companion object { + // Generate an hex ID based on timestamp + // Recreated from https://www.php.net/manual/en/function.uniqid.php + private fun hexTimestamp(): String { + val now = Instant.now() + val sec = now.epochSecond + val usec = (System.nanoTime() / 1000) % 1000 + + val hexTimestamp = "%08x%05x".format(sec, usec) + + return hexTimestamp + } + fun custom(id: String): String = id - fun unique(): String - = "unique()" + + // Generate a unique ID with padding to have a longer ID + fun unique(padding: Int = 7): String { + val baseId = hexTimestamp() + val randomPadding = (1..padding) + .map { Random.nextInt(0, 16).toString(16) } + .joinToString("") + + return baseId + randomPadding + } } -} \ No newline at end of file +} diff --git a/library/src/main/java/io/appwrite/models/MfaFactors.kt b/library/src/main/java/io/appwrite/models/MfaFactors.kt index 904a10b..ddde40c 100644 --- a/library/src/main/java/io/appwrite/models/MfaFactors.kt +++ b/library/src/main/java/io/appwrite/models/MfaFactors.kt @@ -8,28 +8,35 @@ import io.appwrite.extensions.jsonCast */ data class MfaFactors( /** - * TOTP + * Can TOTP be used for MFA challenge for this account. */ @SerializedName("totp") val totp: Boolean, /** - * Phone + * Can phone (SMS) be used for MFA challenge for this account. */ @SerializedName("phone") val phone: Boolean, /** - * Email + * Can email be used for MFA challenge for this account. */ @SerializedName("email") val email: Boolean, + /** + * Can recovery code be used for MFA challenge for this account. + */ + @SerializedName("recoveryCode") + val recoveryCode: Boolean, + ) { fun toMap(): Map = mapOf( "totp" to totp as Any, "phone" to phone as Any, "email" to email as Any, + "recoveryCode" to recoveryCode as Any, ) companion object { @@ -41,6 +48,7 @@ data class MfaFactors( totp = map["totp"] as Boolean, phone = map["phone"] as Boolean, email = map["email"] as Boolean, + recoveryCode = map["recoveryCode"] as Boolean, ) } } \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/models/Session.kt b/library/src/main/java/io/appwrite/models/Session.kt index 1eaed4d..1c6a7b2 100644 --- a/library/src/main/java/io/appwrite/models/Session.kt +++ b/library/src/main/java/io/appwrite/models/Session.kt @@ -19,6 +19,12 @@ data class Session( @SerializedName("\$createdAt") val createdAt: String, + /** + * Session update date in ISO 8601 format. + */ + @SerializedName("\$updatedAt") + val updatedAt: String, + /** * User ID. */ @@ -179,6 +185,7 @@ data class Session( fun toMap(): Map = mapOf( "\$id" to id as Any, "\$createdAt" to createdAt as Any, + "\$updatedAt" to updatedAt as Any, "userId" to userId as Any, "expire" to expire as Any, "provider" to provider as Any, @@ -215,6 +222,7 @@ data class Session( ) = Session( id = map["\$id"] as String, createdAt = map["\$createdAt"] as String, + updatedAt = map["\$updatedAt"] as String, userId = map["userId"] as String, expire = map["expire"] as String, provider = map["provider"] 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 46d5c42..1b8457e 100644 --- a/library/src/main/java/io/appwrite/services/Account.kt +++ b/library/src/main/java/io/appwrite/services/Account.kt @@ -466,13 +466,12 @@ class Account(client: Client) : Service(client) { * * @param type Type of authenticator. * @param otp Valid verification token. - * @return [io.appwrite.models.User] + * @return [Any] */ - suspend fun deleteMfaAuthenticator( + suspend fun deleteMfaAuthenticator( type: io.appwrite.enums.AuthenticatorType, otp: String, - nestedType: Class, - ): io.appwrite.models.User { + ): Any { val apiPath = "/account/mfa/authenticators/{type}" .replace("{type}", type.value) @@ -482,38 +481,15 @@ class Account(client: Client) : Service(client) { val apiHeaders = mutableMapOf( "content-type" to "application/json", ) - val converter: (Any) -> io.appwrite.models.User = { - @Suppress("UNCHECKED_CAST") - 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 for a user by ID. - * - * @param type Type of authenticator. - * @param otp Valid verification token. - * @return [io.appwrite.models.User] - */ - @Throws(AppwriteException::class) - suspend fun deleteMfaAuthenticator( - type: io.appwrite.enums.AuthenticatorType, - otp: String, - ): io.appwrite.models.User> = deleteMfaAuthenticator( - type, - otp, - nestedType = classOf(), - ) /** * Create 2FA Challenge From 8ef821bd360f088fb01d2a51ee101925b27e9d78 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 24 Apr 2024 19:35:03 +1200 Subject: [PATCH 2/2] Bump minor version for other changes --- README.md | 4 ++-- library/src/main/java/io/appwrite/Client.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 57a4335..5a41187 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:5.0.1") +implementation("io.appwrite:sdk-for-android:5.1.0") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 5.0.1 + 5.1.0 ``` diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index f2db946..5240d60 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -83,7 +83,7 @@ class Client @JvmOverloads constructor( "x-sdk-name" to "Android", "x-sdk-platform" to "client", "x-sdk-language" to "android", - "x-sdk-version" to "5.0.1", + "x-sdk-version" to "5.1.0", "x-appwrite-response-format" to "1.5.0" ) config = mutableMapOf()