diff --git a/firebase-functions/api.txt b/firebase-functions/api.txt index 323ba72e22f..2963a38621f 100644 --- a/firebase-functions/api.txt +++ b/firebase-functions/api.txt @@ -23,12 +23,10 @@ package com.google.firebase.functions { } public final class FirebaseFunctionsException extends com.google.firebase.FirebaseException { - method @Nullable public static com.google.firebase.functions.FirebaseFunctionsException fromResponse(@NonNull com.google.firebase.functions.FirebaseFunctionsException.Code code, @Nullable String body, @NonNull com.google.firebase.functions.Serializer serializer); method @NonNull public com.google.firebase.functions.FirebaseFunctionsException.Code getCode(); method @Nullable public Object getDetails(); property @NonNull public final com.google.firebase.functions.FirebaseFunctionsException.Code code; property @Nullable public final Object details; - field @NonNull public static final com.google.firebase.functions.FirebaseFunctionsException.Companion Companion; } public enum FirebaseFunctionsException.Code { @@ -61,10 +59,6 @@ package com.google.firebase.functions { method @NonNull public com.google.firebase.functions.FirebaseFunctionsException.Code fromValue(int value); } - public static final class FirebaseFunctionsException.Companion { - method @Nullable public com.google.firebase.functions.FirebaseFunctionsException fromResponse(@NonNull com.google.firebase.functions.FirebaseFunctionsException.Code code, @Nullable String body, @NonNull com.google.firebase.functions.Serializer serializer); - } - public final class FunctionsKt { method @NonNull public static com.google.firebase.functions.FirebaseFunctions functions(@NonNull com.google.firebase.Firebase, @NonNull String regionOrCustomDomain); method @NonNull public static com.google.firebase.functions.FirebaseFunctions functions(@NonNull com.google.firebase.Firebase, @NonNull com.google.firebase.FirebaseApp app); @@ -74,16 +68,6 @@ package com.google.firebase.functions { method @NonNull public static com.google.firebase.functions.HttpsCallableReference getHttpsCallableFromUrl(@NonNull com.google.firebase.functions.FirebaseFunctions, @NonNull java.net.URL url, @NonNull kotlin.jvm.functions.Function1 init); } - public final class HttpsCallOptions { - ctor public HttpsCallOptions(@NonNull com.google.firebase.functions.HttpsCallableOptions publicCallableOptions); - ctor public HttpsCallOptions(); - method @NonNull public okhttp3.OkHttpClient apply(@NonNull okhttp3.OkHttpClient client); - method public boolean getLimitedUseAppCheckTokens(); - method public long getTimeout(); - method public void setTimeout(long timeout, @NonNull java.util.concurrent.TimeUnit units); - field public final boolean limitedUseAppCheckTokens; - } - public final class HttpsCallableOptions { method public boolean getLimitedUseAppCheckTokens(); field public final boolean limitedUseAppCheckTokens; @@ -100,11 +84,9 @@ package com.google.firebase.functions { public final class HttpsCallableReference { method @NonNull public com.google.android.gms.tasks.Task call(@Nullable Object data); method @NonNull public com.google.android.gms.tasks.Task call(); - method @NonNull public com.google.firebase.functions.HttpsCallOptions getOptions(); method public long getTimeout(); method public void setTimeout(long timeout, @NonNull java.util.concurrent.TimeUnit units); method @NonNull public com.google.firebase.functions.HttpsCallableReference withTimeout(long timeout, @NonNull java.util.concurrent.TimeUnit units); - property @NonNull public final com.google.firebase.functions.HttpsCallOptions options; property public final long timeout; } @@ -113,18 +95,6 @@ package com.google.firebase.functions { field @Nullable public final Object data; } - public final class Serializer { - ctor public Serializer(); - method @Nullable public Object decode(@NonNull Object obj); - method @NonNull public Object encode(@Nullable Object obj); - field @NonNull public static final com.google.firebase.functions.Serializer.Companion Companion; - field @NonNull @VisibleForTesting public static final String LONG_TYPE = "type.googleapis.com/google.protobuf.Int64Value"; - field @NonNull @VisibleForTesting public static final String UNSIGNED_LONG_TYPE = "type.googleapis.com/google.protobuf.UInt64Value"; - } - - public static final class Serializer.Companion { - } - } package com.google.firebase.functions.ktx { diff --git a/firebase-functions/ktx/src/androidTest/kotlin/com/google/firebase/functions/ktx/CallTests.kt b/firebase-functions/ktx/src/androidTest/kotlin/com/google/firebase/functions/ktx/CallTests.kt deleted file mode 100644 index 87ca19f8348..00000000000 --- a/firebase-functions/ktx/src/androidTest/kotlin/com/google/firebase/functions/ktx/CallTests.kt +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.firebase.functions.ktx - -import androidx.test.InstrumentationRegistry -import androidx.test.runner.AndroidJUnit4 -import com.google.android.gms.tasks.Tasks -import com.google.common.truth.Truth.assertThat -import com.google.firebase.FirebaseApp -import com.google.firebase.ktx.Firebase -import com.google.firebase.ktx.app -import com.google.firebase.ktx.initialize -import org.junit.AfterClass -import org.junit.BeforeClass -import org.junit.Test -import org.junit.runner.RunWith - -const val APP_ID = "APP_ID" -const val API_KEY = "API_KEY" - -@RunWith(AndroidJUnit4::class) -class CallTests { - companion object { - lateinit var app: FirebaseApp - - @BeforeClass - @JvmStatic - fun setup() { - app = Firebase.initialize(InstrumentationRegistry.getContext())!! - } - - @AfterClass - @JvmStatic - fun cleanup() { - app.delete() - } - } - - @Test - fun testDataCall() { - val functions = Firebase.functions(app) - val input = - hashMapOf( - "bool" to true, - "int" to 2, - "long" to 3L, - "string" to "four", - "array" to listOf(5, 6), - "null" to null - ) - - var function = functions.getHttpsCallable("dataTest") - val actual = Tasks.await(function.call(input)).getData() - - assertThat(actual).isInstanceOf(Map::class.java) - @Suppress("UNCHECKED_CAST") val map = actual as Map - assertThat(map["message"]).isEqualTo("stub response") - assertThat(map["code"]).isEqualTo(42) - assertThat(map["long"]).isEqualTo(420L) - } - - @Test - fun testNullDataCall() { - val functions = Firebase.functions(app) - var function = functions.getHttpsCallable("nullTest") - val actual = Tasks.await(function.call(null)).getData() - - assertThat(actual).isNull() - } - - @Test - fun testEmptyDataCall() { - val functions = Firebase.functions(app) - var function = functions.getHttpsCallable("nullTest") - val actual = Tasks.await(function.call()).getData() - - assertThat(actual).isNull() - } -} diff --git a/firebase-functions/ktx/src/test/kotlin/com/google/firebase/functions/TestVisibilityUtil.kt b/firebase-functions/ktx/src/test/kotlin/com/google/firebase/functions/TestVisibilityUtil.kt deleted file mode 100644 index 9a8be4b4f9c..00000000000 --- a/firebase-functions/ktx/src/test/kotlin/com/google/firebase/functions/TestVisibilityUtil.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.firebase.functions - -/** - * Returns true if the {@link HttpsCallableReference} is configured to use FAC limited-use tokens. - */ -fun HttpsCallableReference.usesLimitedUseFacTokens() = options.getLimitedUseAppCheckTokens() diff --git a/firebase-functions/ktx/src/test/kotlin/com/google/firebase/functions/ktx/FunctionsTests.kt b/firebase-functions/ktx/src/test/kotlin/com/google/firebase/functions/ktx/FunctionsTests.kt deleted file mode 100644 index 34e845c7927..00000000000 --- a/firebase-functions/ktx/src/test/kotlin/com/google/firebase/functions/ktx/FunctionsTests.kt +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.firebase.functions.ktx - -import androidx.test.core.app.ApplicationProvider -import com.google.common.truth.Truth.assertThat -import com.google.firebase.FirebaseApp -import com.google.firebase.FirebaseOptions -import com.google.firebase.functions.FirebaseFunctions -import com.google.firebase.functions.usesLimitedUseFacTokens -import com.google.firebase.ktx.Firebase -import com.google.firebase.ktx.app -import com.google.firebase.ktx.initialize -import com.google.firebase.platforminfo.UserAgentPublisher -import java.net.URL -import org.junit.After -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.robolectric.RobolectricTestRunner - -const val APP_ID = "APP_ID" -const val API_KEY = "API_KEY" - -const val EXISTING_APP = "existing" - -abstract class BaseTestCase { - @Before - fun setUp() { - Firebase.initialize( - ApplicationProvider.getApplicationContext(), - FirebaseOptions.Builder() - .setApplicationId(APP_ID) - .setApiKey(API_KEY) - .setProjectId("123") - .build() - ) - - Firebase.initialize( - ApplicationProvider.getApplicationContext(), - FirebaseOptions.Builder() - .setApplicationId(APP_ID) - .setApiKey(API_KEY) - .setProjectId("123") - .build(), - EXISTING_APP - ) - } - - @After - fun cleanUp() { - FirebaseApp.clearInstancesForTest() - } -} - -@RunWith(RobolectricTestRunner::class) -class FunctionsTests : BaseTestCase() { - - @Test - fun `functions should delegate to FirebaseFunctions#getInstance()`() { - assertThat(Firebase.functions).isSameInstanceAs(FirebaseFunctions.getInstance()) - } - - @Test - fun `FirebaseApp#functions should delegate to FirebaseFunctions#getInstance(FirebaseApp)`() { - val app = Firebase.app(EXISTING_APP) - assertThat(Firebase.functions(app)).isSameInstanceAs(FirebaseFunctions.getInstance(app)) - } - - @Test - fun `Firebase#functions should delegate to FirebaseFunctions#getInstance(region)`() { - val region = "valid_region" - assertThat(Firebase.functions(region)).isSameInstanceAs(FirebaseFunctions.getInstance(region)) - } - - @Test - fun `Firebase#functions should delegate to FirebaseFunctions#getInstance(FirebaseApp, region)`() { - val app = Firebase.app(EXISTING_APP) - val region = "valid_region" - assertThat(Firebase.functions(app, region)) - .isSameInstanceAs(FirebaseFunctions.getInstance(app, region)) - } -} - -@RunWith(RobolectricTestRunner::class) -class LibraryVersionTest : BaseTestCase() { - @Test - fun `library version should be registered with runtime`() { - val publisher = Firebase.app.get(UserAgentPublisher::class.java) - assertThat(publisher.userAgent).contains(LIBRARY_NAME) - } -} - -@RunWith(RobolectricTestRunner::class) -class AppCheckLimitedUseTest : BaseTestCase() { - @Test - fun `FirebaseFunctions#getHttpsCallable should not use limited-use tokens by default`() { - val callable = Firebase.functions.getHttpsCallable("function") - assertThat(callable.usesLimitedUseFacTokens()).isFalse() - } - - @Test - fun `FirebaseFunctions#getHttpsCallable should build callable with FAC settings (when true)`() { - val callable = - Firebase.functions.getHttpsCallable("function") { limitedUseAppCheckTokens = true } - assertThat(callable.usesLimitedUseFacTokens()).isTrue() - } - - @Test - fun `FirebaseFunctions#getHttpsCallable should build callable with FAC settings (when false)`() { - val callable = - Firebase.functions.getHttpsCallable("function") { limitedUseAppCheckTokens = false } - assertThat(callable.usesLimitedUseFacTokens()).isFalse() - } - - @Test - fun `FirebaseFunctions#getHttpsCallableFromUrl should not use limited-use tokens by default`() { - val callable = Firebase.functions.getHttpsCallableFromUrl(URL("https://functions.test")) - assertThat(callable.usesLimitedUseFacTokens()).isFalse() - } - - @Test - fun `FirebaseFunctions#getHttpsCallableFromUrl callable with FAC settings (when true)`() { - val callable = - Firebase.functions.getHttpsCallableFromUrl(URL("https://functions.test")) { - limitedUseAppCheckTokens = true - } - assertThat(callable.usesLimitedUseFacTokens()).isTrue() - } - - @Test - fun `FirebaseFunctions#getHttpsCallableFromUrl callable with FAC settings (when false)`() { - val callable = - Firebase.functions.getHttpsCallableFromUrl(URL("https://functions.test")) { - limitedUseAppCheckTokens = false - } - assertThat(callable.usesLimitedUseFacTokens()).isFalse() - } -} diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.kt b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.kt index 3c0e7d6553e..824670c4346 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.kt @@ -146,7 +146,7 @@ internal constructor( } } - @Deprecated("Use {@link #useEmulator(String, int)} to connect to the emulator. ") + @Deprecated("Use useEmulator to connect to the emulator.") public fun useFunctionsEmulator(origin: String) { Preconditions.checkNotNull(origin, "origin cannot be null") urlFormat = "$origin/%2\$s/%1\$s/%3\$s" diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctionsException.kt b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctionsException.kt index 87102e0fc7b..06a2818ea1c 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctionsException.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctionsException.kt @@ -29,8 +29,8 @@ public class FirebaseFunctionsException : FirebaseException { */ public enum class Code(@Suppress("unused") private val value: Int) { /** - * The operation completed successfully. FirebaseFunctionsException will never have a status of - * OK. + * The operation completed successfully. `FirebaseFunctionsException` will never have a status + * of `OK`. */ OK(0), @@ -41,9 +41,9 @@ public class FirebaseFunctionsException : FirebaseException { UNKNOWN(2), /** - * Client specified an invalid argument. Note that this differs from FAILED_PRECONDITION. - * INVALID_ARGUMENT indicates arguments that are problematic regardless of the state of the - * system (e.g., an invalid field name). + * Client specified an invalid argument. Note that this differs from `FAILED_PRECONDITION`. + * `INVALID_ARGUMENT` indicates arguments that are problematic regardless of the state of the + * system (For example, an invalid field name). */ INVALID_ARGUMENT(3), @@ -126,12 +126,12 @@ public class FirebaseFunctionsException : FirebaseException { } /** - * Takes an HTTP status code and returns the corresponding FUNErrorCode error code. This is - * the standard HTTP status code -> error mapping defined in: + * Takes an HTTP status code and returns the corresponding [Code] error code. This is the + * standard HTTP status code -> error mapping defined in: * https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto * * @param status An HTTP status code. - * @return The corresponding Code, or Code.UNKNOWN if none. + * @return The corresponding `Code`, or `Code.UNKNOWN` if none. */ @JvmStatic public fun fromHttpStatus(status: Int): Code { @@ -157,7 +157,7 @@ public class FirebaseFunctionsException : FirebaseException { /** * Gets the error code for the operation that failed. * - * @return the code for the FirebaseFunctionsException + * @return the code for the `FirebaseFunctionsException` */ public val code: Code @@ -183,7 +183,7 @@ public class FirebaseFunctionsException : FirebaseException { this.details = details } - public companion object { + internal companion object { /** * Takes an HTTP response and returns the corresponding Exception if any. * @@ -193,7 +193,7 @@ public class FirebaseFunctionsException : FirebaseException { * @return The corresponding Exception, or null if none. */ @JvmStatic - public fun fromResponse( + internal fun fromResponse( code: Code, body: String?, serializer: Serializer diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallOptions.kt b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallOptions.kt index 6e36efffe18..f6b0e3f07c3 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallOptions.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallOptions.kt @@ -17,22 +17,22 @@ import java.util.concurrent.TimeUnit import okhttp3.OkHttpClient /** An internal class for keeping track of options applied to an HttpsCallableReference. */ -public class HttpsCallOptions { +internal class HttpsCallOptions { // The timeout to use for calls from references created by this Functions. private var timeout = DEFAULT_TIMEOUT private var timeoutUnits = DEFAULT_TIMEOUT_UNITS @JvmField public val limitedUseAppCheckTokens: Boolean /** Creates an (internal) HttpsCallOptions from the (external) [HttpsCallableOptions]. */ - public constructor(publicCallableOptions: HttpsCallableOptions) { + internal constructor(publicCallableOptions: HttpsCallableOptions) { limitedUseAppCheckTokens = publicCallableOptions.limitedUseAppCheckTokens } - public constructor() { + internal constructor() { limitedUseAppCheckTokens = false } - public fun getLimitedUseAppCheckTokens(): Boolean { + internal fun getLimitedUseAppCheckTokens(): Boolean { return limitedUseAppCheckTokens } @@ -42,7 +42,7 @@ public class HttpsCallOptions { * @param timeout The length of the timeout, in the given units. * @param units The units for the specified timeout. */ - public fun setTimeout(timeout: Long, units: TimeUnit) { + internal fun setTimeout(timeout: Long, units: TimeUnit) { this.timeout = timeout timeoutUnits = units } @@ -52,12 +52,12 @@ public class HttpsCallOptions { * * @return The timeout, in milliseconds. */ - public fun getTimeout(): Long { + internal fun getTimeout(): Long { return timeoutUnits.toMillis(timeout) } /** Creates a new OkHttpClient with these options applied to it. */ - public fun apply(client: OkHttpClient): OkHttpClient { + internal fun apply(client: OkHttpClient): OkHttpClient { return client .newBuilder() .callTimeout(timeout, timeoutUnits) diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableOptions.kt b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableOptions.kt index 32b05afded2..63aa4547e64 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableOptions.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableOptions.kt @@ -31,7 +31,7 @@ private constructor( return limitedUseAppCheckTokens } - /** Builder class for [com.google.firebase.functions.HttpsCallableOptions] */ + /** A builder for creating [com.google.firebase.functions.HttpsCallableOptions]. */ public class Builder { @JvmField public var limitedUseAppCheckTokens: Boolean = false diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.kt b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.kt index 90bdb63221b..88db9db4ee4 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.kt @@ -32,7 +32,7 @@ public class HttpsCallableReference { private val url: URL? // Options for how to do the HTTPS call. - @VisibleForTesting public val options: HttpsCallOptions + @VisibleForTesting internal val options: HttpsCallOptions /** Creates a new reference with the given options. */ internal constructor( @@ -81,7 +81,7 @@ public class HttpsCallableReference { * Auth, an auth token for the user will also be automatically included. * * Firebase Instance ID sends data to the Firebase backend periodically to collect information - * regarding the app instance. To stop this, see [ ] + * regarding the app instance. To stop this, see * [com.google.firebase.iid.FirebaseInstanceId.deleteInstanceId]. It will resume with a new * Instance ID the next time you call this method. * @@ -111,7 +111,7 @@ public class HttpsCallableReference { * Auth, an auth token for the user will also be automatically included. * * Firebase Instance ID sends data to the Firebase backend periodically to collect information - * regarding the app instance. To stop this, see [ ] + * regarding the app instance. To stop this, see * [com.google.firebase.iid.FirebaseInstanceId.deleteInstanceId]. It will resume with a new * Instance ID the next time you call this method. * diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableResult.kt b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableResult.kt index 19fec093d2d..ac4a10638a2 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableResult.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableResult.kt @@ -13,7 +13,7 @@ // limitations under the License. package com.google.firebase.functions -/** The result of calling a HttpsCallableReference function. */ +/** The result of calling a `HttpsCallableReference` function. */ public class HttpsCallableResult internal constructor( // The actual result data, as generic types decoded from JSON. /** diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/Serializer.kt b/firebase-functions/src/main/java/com/google/firebase/functions/Serializer.kt index 619ae2d75f1..3ab2ebb0756 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/Serializer.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/Serializer.kt @@ -23,7 +23,7 @@ import org.json.JSONException import org.json.JSONObject /** Converts raw Java types into JSON objects. */ -public class Serializer { +internal class Serializer { private val dateFormat: DateFormat init { @@ -168,11 +168,12 @@ public class Serializer { throw IllegalArgumentException("Object cannot be decoded from JSON: $obj") } - public companion object { + internal companion object { @VisibleForTesting - public const val LONG_TYPE: String = "type.googleapis.com/google.protobuf.Int64Value" + internal const val LONG_TYPE: String = "type.googleapis.com/google.protobuf.Int64Value" @VisibleForTesting - public const val UNSIGNED_LONG_TYPE: String = "type.googleapis.com/google.protobuf.UInt64Value" + internal const val UNSIGNED_LONG_TYPE: String = + "type.googleapis.com/google.protobuf.UInt64Value" } }