Skip to content

Commit 6cb1317

Browse files
committed
Upgrade to latest APIS and add SnapshotListenOptions support
TODO: The Java SDK should be updated
1 parent 95a8eb2 commit 6cb1317

File tree

38 files changed

+412
-22
lines changed

38 files changed

+412
-22
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ buildscript {
3232

3333
val compileSdkVersion by extra(34)
3434
val targetSdkVersion by extra(34)
35-
val minSdkVersion by extra(21)
35+
val minSdkVersion by extra(23)
3636

3737
tasks {
3838
register("updateVersions") {

firebase-app/src/appleMain/kotlin/dev/gitlive/firebase/firebase.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public actual data class FirebaseApp internal constructor(internal val ios: FIRA
2929
actual val name: String
3030
get() = ios.name
3131
actual val options: FirebaseOptions
32-
get() = ios.options.run { FirebaseOptions(bundleID, APIKey!!, databaseURL!!, trackingID, storageBucket, projectID, GCMSenderID) }
32+
get() = ios.options.run { FirebaseOptions(bundleID, APIKey!!, databaseURL!!, null, storageBucket, projectID, GCMSenderID) }
3333

3434
public actual suspend fun delete() {
3535
val deleted = CompletableDeferred<Unit>()
@@ -46,7 +46,6 @@ public actual fun Firebase.apps(context: Any?): List<FirebaseApp> = FIRApp.allAp
4646
private fun FirebaseOptions.toIos() = FIROptions(this@toIos.applicationId, this@toIos.gcmSenderId ?: "").apply {
4747
APIKey = this@toIos.apiKey
4848
databaseURL = this@toIos.databaseUrl
49-
trackingID = this@toIos.gaTrackingId
5049
storageBucket = this@toIos.storageBucket
5150
projectID = this@toIos.projectId
5251
}

firebase-auth/src/androidMain/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,25 @@ public actual class FirebaseAuth internal constructor(internal val android: com.
9191
@Suppress("UNCHECKED_CAST")
9292
return when (result.operation) {
9393
SIGN_IN_WITH_EMAIL_LINK -> ActionCodeResult.SignInWithEmailLink
94+
9495
VERIFY_EMAIL -> ActionCodeResult.VerifyEmail(result.info!!.email)
96+
9597
PASSWORD_RESET -> ActionCodeResult.PasswordReset(result.info!!.email)
98+
9699
RECOVER_EMAIL -> (result.info as ActionCodeEmailInfo).run {
97100
ActionCodeResult.RecoverEmail(email, previousEmail)
98101
}
102+
99103
VERIFY_BEFORE_CHANGE_EMAIL -> (result.info as ActionCodeEmailInfo).run {
100104
ActionCodeResult.VerifyBeforeChangeEmail(email, previousEmail)
101105
}
106+
102107
REVERT_SECOND_FACTOR_ADDITION -> (result.info as ActionCodeMultiFactorInfo).run {
103108
ActionCodeResult.RevertSecondFactorAddition(email, MultiFactorInfo(multiFactorInfo))
104109
}
110+
105111
ERROR -> throw UnsupportedOperationException(result.operation.toString())
112+
106113
else -> throw UnsupportedOperationException(result.operation.toString())
107114
} as T
108115
}

firebase-auth/src/appleMain/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,5 +266,6 @@ private fun NSError.toException() = when (domain) {
266266

267267
else -> FirebaseAuthException(toString())
268268
}
269+
269270
else -> FirebaseAuthException(toString())
270271
}

firebase-auth/src/jsMain/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,23 @@ public actual class FirebaseAuth internal constructor(internal val js: Auth) {
104104
@Suppress("UNCHECKED_CAST")
105105
return when (result.operation) {
106106
"EMAIL_SIGNIN" -> ActionCodeResult.SignInWithEmailLink
107+
107108
"VERIFY_EMAIL" -> ActionCodeResult.VerifyEmail(result.data.email!!)
109+
108110
"PASSWORD_RESET" -> ActionCodeResult.PasswordReset(result.data.email!!)
111+
109112
"RECOVER_EMAIL" -> ActionCodeResult.RecoverEmail(result.data.email!!, result.data.previousEmail!!)
113+
110114
"VERIFY_AND_CHANGE_EMAIL" -> ActionCodeResult.VerifyBeforeChangeEmail(
111115
result.data.email!!,
112116
result.data.previousEmail!!,
113117
)
118+
114119
"REVERT_SECOND_FACTOR_ADDITION" -> ActionCodeResult.RevertSecondFactorAddition(
115120
result.data.email!!,
116121
result.data.multiFactorInfo?.let { MultiFactorInfo(it) },
117122
)
123+
118124
else -> throw UnsupportedOperationException(result.operation)
119125
} as T
120126
}
@@ -208,26 +214,39 @@ private inline fun <R> rethrow(function: () -> R): R {
208214

209215
private fun errorToException(cause: dynamic) = when (val code = cause.code?.toString()?.lowercase()) {
210216
"auth/invalid-user-token" -> FirebaseAuthInvalidUserException(code, cause.unsafeCast<Throwable>())
217+
211218
"auth/requires-recent-login" -> FirebaseAuthRecentLoginRequiredException(code, cause.unsafeCast<Throwable>())
219+
212220
"auth/user-disabled" -> FirebaseAuthInvalidUserException(code, cause.unsafeCast<Throwable>())
221+
213222
"auth/user-token-expired" -> FirebaseAuthInvalidUserException(code, cause.unsafeCast<Throwable>())
223+
214224
"auth/web-storage-unsupported" -> FirebaseAuthWebException(code, cause.unsafeCast<Throwable>())
225+
215226
"auth/network-request-failed" -> FirebaseNetworkException(code, cause.unsafeCast<Throwable>())
227+
216228
"auth/timeout" -> FirebaseNetworkException(code, cause.unsafeCast<Throwable>())
229+
217230
"auth/weak-password" -> FirebaseAuthWeakPasswordException(code, cause.unsafeCast<Throwable>())
231+
218232
"auth/invalid-credential",
219233
"auth/invalid-verification-code",
220234
"auth/missing-verification-code",
221235
"auth/invalid-verification-id",
222236
"auth/missing-verification-id",
223237
-> FirebaseAuthInvalidCredentialsException(code, cause.unsafeCast<Throwable>())
238+
224239
"auth/maximum-second-factor-count-exceeded",
225240
"auth/second-factor-already-in-use",
226241
-> FirebaseAuthMultiFactorException(code, cause.unsafeCast<Throwable>())
242+
227243
"auth/credential-already-in-use" -> FirebaseAuthUserCollisionException(code, cause.unsafeCast<Throwable>())
244+
228245
"auth/email-already-in-use" -> FirebaseAuthUserCollisionException(code, cause.unsafeCast<Throwable>())
246+
229247
"auth/invalid-email" -> FirebaseAuthEmailException(code, cause.unsafeCast<Throwable>())
230-
// "auth/app-deleted" ->
248+
249+
// "auth/app-deleted" ->
231250
// "auth/app-not-authorized" ->
232251
// "auth/argument-error" ->
233252
// "auth/invalid-api-key" ->

firebase-auth/src/jvmMain/kotlin/dev/gitlive/firebase/auth/auth.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,25 @@ public actual class FirebaseAuth internal constructor(internal val android: com.
9898
@Suppress("UNCHECKED_CAST")
9999
return when (result.operation) {
100100
SIGN_IN_WITH_EMAIL_LINK -> ActionCodeResult.SignInWithEmailLink
101+
101102
VERIFY_EMAIL -> ActionCodeResult.VerifyEmail(result.info!!.email)
103+
102104
PASSWORD_RESET -> ActionCodeResult.PasswordReset(result.info!!.email)
105+
103106
RECOVER_EMAIL -> (result.info as ActionCodeEmailInfo).run {
104107
ActionCodeResult.RecoverEmail(email, previousEmail)
105108
}
109+
106110
VERIFY_BEFORE_CHANGE_EMAIL -> (result.info as ActionCodeEmailInfo).run {
107111
ActionCodeResult.VerifyBeforeChangeEmail(email, previousEmail)
108112
}
113+
109114
REVERT_SECOND_FACTOR_ADDITION -> (result.info as ActionCodeMultiFactorInfo).run {
110115
ActionCodeResult.RevertSecondFactorAddition(email, MultiFactorInfo(multiFactorInfo))
111116
}
117+
112118
ERROR -> throw UnsupportedOperationException(result.operation.toString())
119+
113120
else -> throw UnsupportedOperationException(result.operation.toString())
114121
} as T
115122
}

firebase-common-internal/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ kotlin {
155155
if (supportedPlatforms.contains(TargetPlatform.Js)) {
156156
getByName("jsMain") {
157157
dependencies {
158-
api(npm("firebase", "10.12.2"))
158+
api(npm("firebase", libs.versions.firebase.npm.get()))
159159
}
160160
}
161161
}

firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import kotlinx.serialization.encoding.CompositeDecoder
1111

1212
internal actual fun FirebaseDecoderImpl.structureDecoder(descriptor: SerialDescriptor, polymorphicIsNested: Boolean): CompositeDecoder = when (descriptor.kind) {
1313
StructureKind.CLASS, StructureKind.OBJECT -> decodeAsMap(false)
14+
1415
StructureKind.LIST -> (value as? List<*>).orEmpty().let {
1516
FirebaseCompositeDecoder(it.size, settings) { _, index -> it[index] }
1617
}
@@ -23,6 +24,7 @@ internal actual fun FirebaseDecoderImpl.structureDecoder(descriptor: SerialDescr
2324
}
2425

2526
is PolymorphicKind -> decodeAsMap(polymorphicIsNested)
27+
2628
else -> TODO("The firebase-kotlin-sdk does not support $descriptor for serialization yet")
2729
}
2830

firebase-common-internal/src/androidMain/kotlin/dev/gitlive/firebase/internal/_encoders.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ internal actual fun FirebaseEncoderImpl.structureEncoder(descriptor: SerialDescr
1313
StructureKind.LIST -> mutableListOf<Any?>()
1414
.also { value = it }
1515
.let { FirebaseCompositeEncoder(settings) { _, index, value -> it.add(index, value) } }
16+
1617
StructureKind.MAP -> mutableListOf<Any?>()
1718
.let { FirebaseCompositeEncoder(settings, { value = it.chunked(2).associate { (k, v) -> k to v } }) { _, _, value -> it.add(value) } }
19+
1820
StructureKind.CLASS, StructureKind.OBJECT -> encodeAsMap(descriptor)
21+
1922
is PolymorphicKind -> encodeAsMap(descriptor)
23+
2024
else -> TODO("The firebase-kotlin-sdk does not support $descriptor for serialization yet")
2125
}
2226

firebase-common-internal/src/appleMain/kotlin/dev/gitlive/firebase/internal/_decoders.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ import kotlin.collections.get
1212

1313
internal actual fun FirebaseDecoderImpl.structureDecoder(descriptor: SerialDescriptor, polymorphicIsNested: Boolean): CompositeDecoder = when (descriptor.kind) {
1414
StructureKind.CLASS, StructureKind.OBJECT -> decodeAsMap(false)
15+
1516
StructureKind.LIST -> decodeAsList()
17+
1618
StructureKind.MAP -> (value as? Map<*, *>).orEmpty().entries.toList().let {
1719
FirebaseCompositeDecoder(it.size, settings) { _, index -> it[index / 2].run { if (index % 2 == 0) key else value } }
1820
}
21+
1922
is PolymorphicKind -> decodeAsMap(polymorphicIsNested)
23+
2024
else -> TODO("The firebase-kotlin-sdk does not support $descriptor for serialization yet")
2125
}
2226

0 commit comments

Comments
 (0)