From ec6bbd113adcaca4931130fb789a0694c11bf973 Mon Sep 17 00:00:00 2001 From: Tyler-Larkin Date: Sun, 1 Dec 2024 17:25:27 -0800 Subject: [PATCH] chore(datastore,analytics,auth,notifications,storage): updated/regenerated pigeon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -renamed setup to setUp in various locations -added pigeonVar_binaryMessenger and pigeonVar_messageChannelSuffix to AmplifyNativeLegacyWrapper -renamed PigeonLegacyDataProvider to PinpointLegacyDataProvider (API can’t start with Pigeon) -updated signInWithUrl’s return value (this was updated 3 years ago) --- .../pigeons/NativePluginBindings.kt | 533 +++++++++------ .../pigeons/NativePluginBindings.swift | 643 +++++++++++------- .../lib/amplify_datastore.dart | 4 +- .../lib/src/native_plugin.g.dart | 633 ++++++++++------- packages/amplify_datastore/pubspec.yaml | 2 +- .../pigeons/LegacyNativePluginPigeon.kt | 39 +- .../Pigeons/AmplifyNativeLegacyPlugin.swift | 114 +++- .../lib/amplify_native_legacy_plugin.g.dart | 171 +++-- .../lib/amplify_native_legacy_wrapper.dart | 9 + .../pubspec.yaml | 2 +- .../amplify_analytics_pinpoint/Messages.java | 73 +- .../AmplifyAnalyticsPinpointPlugin.kt | 6 +- .../data_provider.android.dart | 5 +- ...pigeon_legacy_data_provider.android.g.dart | 88 ++- .../pigeons/pigeon_config_android.dart | 2 +- .../amplify_analytics_pinpoint/pubspec.yaml | 2 +- .../pigeons/NativeAuthPluginBindingsPigeon.kt | 212 +++--- .../darwin/Classes/pigeons/messages.g.swift | 275 +++++--- .../native_auth_bridge_test.dart | 6 +- .../Flutter/GeneratedPluginRegistrant.swift | 2 - .../lib/src/auth_plugin_impl.dart | 2 +- .../lib/src/native_auth_plugin.g.dart | 476 +++++++------ .../auth/amplify_auth_cognito/pubspec.yaml | 2 +- .../test/hosted_ui_platform_flutter_test.dart | 2 +- .../PushNotificationsHostApiBindings.java | 278 +++++--- .../Classes/PushNotificationsNativePlugin.h | 31 +- .../Classes/PushNotificationsNativePlugin.m | 260 ++++--- .../native_push_notifications_plugin.g.dart | 385 ++++++----- .../src/push_notifications_flutter_api.dart | 4 +- .../amplify_push_notifications/pubspec.yaml | 2 +- .../pigeons/AmplifySecureStoragePigeon.kt | 35 +- .../pigeons/NSUserDefaultsPigeon.swift | 74 +- .../amplify_secure_storage_pigeon.g.dart | 180 +++-- .../pigeons/ns_user_defaults_pigeon.g.dart | 115 ++-- .../pigeons/NSUserDefaultsPigeon.swift | 74 +- .../amplify_secure_storage/pubspec.yaml | 2 +- .../amplify_storage_s3_dart/pubspec.yaml | 4 +- pubspec.yaml | 2 +- 38 files changed, 2829 insertions(+), 1920 deletions(-) diff --git a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/pigeons/NativePluginBindings.kt b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/pigeons/NativePluginBindings.kt index 6b936216b1..725df140ba 100644 --- a/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/pigeons/NativePluginBindings.kt +++ b/packages/amplify_datastore/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/pigeons/NativePluginBindings.kt @@ -1,8 +1,9 @@ -// +// // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Autogenerated from Pigeon (v11.0.1), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon +@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass") package com.amazonaws.amplify.amplify_datastore.pigeons @@ -19,14 +20,14 @@ private fun wrapResult(result: Any?): List { } private fun wrapError(exception: Throwable): List { - if (exception is FlutterError) { - return listOf( + return if (exception is FlutterError) { + listOf( exception.code, exception.message, exception.details ) } else { - return listOf( + listOf( exception.javaClass.simpleName, exception.toString(), "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception) @@ -34,6 +35,9 @@ private fun wrapError(exception: Throwable): List { } } +private fun createConnectionError(channelName: String): FlutterError { + return FlutterError("channel-error", "Unable to establish connection on channel: '$channelName'.", "")} + /** * Error class for passing custom error details to Flutter via a thrown PlatformException. * @property code The error code. @@ -53,30 +57,25 @@ data class NativeAuthSession ( val userPoolTokens: NativeUserPoolTokens? = null, val identityId: String? = null, val awsCredentials: NativeAWSCredentials? = null - -) { +) + { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): NativeAuthSession { - val isSignedIn = list[0] as Boolean - val userSub = list[1] as String? - val userPoolTokens: NativeUserPoolTokens? = (list[2] as List?)?.let { - NativeUserPoolTokens.fromList(it) - } - val identityId = list[3] as String? - val awsCredentials: NativeAWSCredentials? = (list[4] as List?)?.let { - NativeAWSCredentials.fromList(it) - } + fun fromList(pigeonVar_list: List): NativeAuthSession { + val isSignedIn = pigeonVar_list[0] as Boolean + val userSub = pigeonVar_list[1] as String? + val userPoolTokens = pigeonVar_list[2] as NativeUserPoolTokens? + val identityId = pigeonVar_list[3] as String? + val awsCredentials = pigeonVar_list[4] as NativeAWSCredentials? return NativeAuthSession(isSignedIn, userSub, userPoolTokens, identityId, awsCredentials) } } fun toList(): List { - return listOf( + return listOf( isSignedIn, userSub, - userPoolTokens?.toList(), + userPoolTokens, identityId, - awsCredentials?.toList(), + awsCredentials, ) } } @@ -85,18 +84,17 @@ data class NativeAuthSession ( data class NativeAuthUser ( val userId: String, val username: String - -) { +) + { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): NativeAuthUser { - val userId = list[0] as String - val username = list[1] as String + fun fromList(pigeonVar_list: List): NativeAuthUser { + val userId = pigeonVar_list[0] as String + val username = pigeonVar_list[1] as String return NativeAuthUser(userId, username) } } fun toList(): List { - return listOf( + return listOf( userId, username, ) @@ -108,19 +106,18 @@ data class NativeUserPoolTokens ( val accessToken: String, val refreshToken: String, val idToken: String - -) { +) + { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): NativeUserPoolTokens { - val accessToken = list[0] as String - val refreshToken = list[1] as String - val idToken = list[2] as String + fun fromList(pigeonVar_list: List): NativeUserPoolTokens { + val accessToken = pigeonVar_list[0] as String + val refreshToken = pigeonVar_list[1] as String + val idToken = pigeonVar_list[2] as String return NativeUserPoolTokens(accessToken, refreshToken, idToken) } } fun toList(): List { - return listOf( + return listOf( accessToken, refreshToken, idToken, @@ -134,20 +131,19 @@ data class NativeAWSCredentials ( val secretAccessKey: String, val sessionToken: String? = null, val expirationIso8601Utc: String? = null - -) { +) + { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): NativeAWSCredentials { - val accessKeyId = list[0] as String - val secretAccessKey = list[1] as String - val sessionToken = list[2] as String? - val expirationIso8601Utc = list[3] as String? + fun fromList(pigeonVar_list: List): NativeAWSCredentials { + val accessKeyId = pigeonVar_list[0] as String + val secretAccessKey = pigeonVar_list[1] as String + val sessionToken = pigeonVar_list[2] as String? + val expirationIso8601Utc = pigeonVar_list[3] as String? return NativeAWSCredentials(accessKeyId, secretAccessKey, sessionToken, expirationIso8601Utc) } } fun toList(): List { - return listOf( + return listOf( accessKeyId, secretAccessKey, sessionToken, @@ -156,20 +152,58 @@ data class NativeAWSCredentials ( } } +/** Generated class from Pigeon that represents data sent in messages. */ +data class LegacyCredentialStoreData ( + val identityId: String? = null, + val accessKeyId: String? = null, + val secretAccessKey: String? = null, + val sessionToken: String? = null, + val expirationMsSinceEpoch: Long? = null, + val accessToken: String? = null, + val refreshToken: String? = null, + val idToken: String? = null +) + { + companion object { + fun fromList(pigeonVar_list: List): LegacyCredentialStoreData { + val identityId = pigeonVar_list[0] as String? + val accessKeyId = pigeonVar_list[1] as String? + val secretAccessKey = pigeonVar_list[2] as String? + val sessionToken = pigeonVar_list[3] as String? + val expirationMsSinceEpoch = pigeonVar_list[4] as Long? + val accessToken = pigeonVar_list[5] as String? + val refreshToken = pigeonVar_list[6] as String? + val idToken = pigeonVar_list[7] as String? + return LegacyCredentialStoreData(identityId, accessKeyId, secretAccessKey, sessionToken, expirationMsSinceEpoch, accessToken, refreshToken, idToken) + } + } + fun toList(): List { + return listOf( + identityId, + accessKeyId, + secretAccessKey, + sessionToken, + expirationMsSinceEpoch, + accessToken, + refreshToken, + idToken, + ) + } +} + /** Generated class from Pigeon that represents data sent in messages. */ data class NativeGraphQLResponse ( val payloadJson: String? = null - -) { +) + { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): NativeGraphQLResponse { - val payloadJson = list[0] as String? + fun fromList(pigeonVar_list: List): NativeGraphQLResponse { + val payloadJson = pigeonVar_list[0] as String? return NativeGraphQLResponse(payloadJson) } } fun toList(): List { - return listOf( + return listOf( payloadJson, ) } @@ -180,19 +214,18 @@ data class NativeGraphQLSubscriptionResponse ( val type: String, val subscriptionId: String, val payloadJson: String? = null - -) { +) + { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): NativeGraphQLSubscriptionResponse { - val type = list[0] as String - val subscriptionId = list[1] as String - val payloadJson = list[2] as String? + fun fromList(pigeonVar_list: List): NativeGraphQLSubscriptionResponse { + val type = pigeonVar_list[0] as String + val subscriptionId = pigeonVar_list[1] as String + val payloadJson = pigeonVar_list[2] as String? return NativeGraphQLSubscriptionResponse(type, subscriptionId, payloadJson) } } fun toList(): List { - return listOf( + return listOf( type, subscriptionId, payloadJson, @@ -209,23 +242,22 @@ data class NativeGraphQLRequest ( val decodePath: String? = null, val options: String? = null, val authMode: String? = null - -) { +) + { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): NativeGraphQLRequest { - val document = list[0] as String - val apiName = list[1] as String? - val variablesJson = list[2] as String? - val responseType = list[3] as String? - val decodePath = list[4] as String? - val options = list[5] as String? - val authMode = list[6] as String? + fun fromList(pigeonVar_list: List): NativeGraphQLRequest { + val document = pigeonVar_list[0] as String + val apiName = pigeonVar_list[1] as String? + val variablesJson = pigeonVar_list[2] as String? + val responseType = pigeonVar_list[3] as String? + val decodePath = pigeonVar_list[4] as String? + val options = pigeonVar_list[5] as String? + val authMode = pigeonVar_list[6] as String? return NativeGraphQLRequest(document, apiName, variablesJson, responseType, decodePath, options, authMode) } } fun toList(): List { - return listOf( + return listOf( document, apiName, variablesJson, @@ -236,167 +268,264 @@ data class NativeGraphQLRequest ( ) } } - -@Suppress("UNCHECKED_CAST") -private object NativeAuthPluginCodec : StandardMessageCodec() { +private open class NativePluginBindingsPigeonCodec : StandardMessageCodec() { override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { return when (type) { - 128.toByte() -> { - return (readValue(buffer) as? List)?.let { - NativeAWSCredentials.fromList(it) - } - } 129.toByte() -> { return (readValue(buffer) as? List)?.let { NativeAuthSession.fromList(it) } } 130.toByte() -> { + return (readValue(buffer) as? List)?.let { + NativeAuthUser.fromList(it) + } + } + 131.toByte() -> { return (readValue(buffer) as? List)?.let { NativeUserPoolTokens.fromList(it) } } + 132.toByte() -> { + return (readValue(buffer) as? List)?.let { + NativeAWSCredentials.fromList(it) + } + } + 133.toByte() -> { + return (readValue(buffer) as? List)?.let { + LegacyCredentialStoreData.fromList(it) + } + } + 134.toByte() -> { + return (readValue(buffer) as? List)?.let { + NativeGraphQLResponse.fromList(it) + } + } + 135.toByte() -> { + return (readValue(buffer) as? List)?.let { + NativeGraphQLSubscriptionResponse.fromList(it) + } + } + 136.toByte() -> { + return (readValue(buffer) as? List)?.let { + NativeGraphQLRequest.fromList(it) + } + } else -> super.readValueOfType(type, buffer) } } override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { when (value) { - is NativeAWSCredentials -> { - stream.write(128) - writeValue(stream, value.toList()) - } is NativeAuthSession -> { stream.write(129) writeValue(stream, value.toList()) } - is NativeUserPoolTokens -> { + is NativeAuthUser -> { stream.write(130) writeValue(stream, value.toList()) } + is NativeUserPoolTokens -> { + stream.write(131) + writeValue(stream, value.toList()) + } + is NativeAWSCredentials -> { + stream.write(132) + writeValue(stream, value.toList()) + } + is LegacyCredentialStoreData -> { + stream.write(133) + writeValue(stream, value.toList()) + } + is NativeGraphQLResponse -> { + stream.write(134) + writeValue(stream, value.toList()) + } + is NativeGraphQLSubscriptionResponse -> { + stream.write(135) + writeValue(stream, value.toList()) + } + is NativeGraphQLRequest -> { + stream.write(136) + writeValue(stream, value.toList()) + } else -> super.writeValue(stream, value) } } } + /** * Bridge for calling Auth from Native into Flutter * * Generated class from Pigeon that represents Flutter messages that can be called from Kotlin. */ -@Suppress("UNCHECKED_CAST") -class NativeAuthPlugin(private val binaryMessenger: BinaryMessenger) { +class NativeAuthPlugin(private val binaryMessenger: BinaryMessenger, private val messageChannelSuffix: String = "") { companion object { /** The codec used by NativeAuthPlugin. */ val codec: MessageCodec by lazy { - NativeAuthPluginCodec + NativePluginBindingsPigeonCodec() } } - fun fetchAuthSession(callback: (NativeAuthSession) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeAuthPlugin.fetchAuthSession", codec) + fun fetchAuthSession(callback: (Result) -> Unit) +{ + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" + val channelName = "dev.flutter.pigeon.amplify_datastore.NativeAuthPlugin.fetchAuthSession$separatedMessageChannelSuffix" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(null) { - val result = it as NativeAuthSession - callback(result) - } - } -} -@Suppress("UNCHECKED_CAST") -private object NativeApiPluginCodec : StandardMessageCodec() { - override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { - return when (type) { - 128.toByte() -> { - return (readValue(buffer) as? List)?.let { - NativeGraphQLRequest.fromList(it) - } - } - 129.toByte() -> { - return (readValue(buffer) as? List)?.let { - NativeGraphQLResponse.fromList(it) - } - } - 130.toByte() -> { - return (readValue(buffer) as? List)?.let { - NativeGraphQLSubscriptionResponse.fromList(it) + if (it is List<*>) { + if (it.size > 1) { + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) + } else if (it[0] == null) { + callback(Result.failure(FlutterError("null-error", "Flutter api returned null value for non-null return value.", ""))) + } else { + val output = it[0] as NativeAuthSession + callback(Result.success(output)) } - } - else -> super.readValueOfType(type, buffer) - } - } - override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { - when (value) { - is NativeGraphQLRequest -> { - stream.write(128) - writeValue(stream, value.toList()) - } - is NativeGraphQLResponse -> { - stream.write(129) - writeValue(stream, value.toList()) - } - is NativeGraphQLSubscriptionResponse -> { - stream.write(130) - writeValue(stream, value.toList()) - } - else -> super.writeValue(stream, value) + } else { + callback(Result.failure(createConnectionError(channelName))) + } } } } - /** * Bridge for calling API plugin from Native into Flutter * * Generated class from Pigeon that represents Flutter messages that can be called from Kotlin. */ -@Suppress("UNCHECKED_CAST") -class NativeApiPlugin(private val binaryMessenger: BinaryMessenger) { +class NativeApiPlugin(private val binaryMessenger: BinaryMessenger, private val messageChannelSuffix: String = "") { companion object { /** The codec used by NativeApiPlugin. */ val codec: MessageCodec by lazy { - NativeApiPluginCodec + NativePluginBindingsPigeonCodec() } } - fun getLatestAuthToken(providerNameArg: String, callback: (String?) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.getLatestAuthToken", codec) + fun getLatestAuthToken(providerNameArg: String, callback: (Result) -> Unit) +{ + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" + val channelName = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.getLatestAuthToken$separatedMessageChannelSuffix" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(providerNameArg)) { - val result = it as String? - callback(result) + if (it is List<*>) { + if (it.size > 1) { + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + val output = it[0] as String? + callback(Result.success(output)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } } } - fun mutate(requestArg: NativeGraphQLRequest, callback: (NativeGraphQLResponse) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.mutate", codec) + fun mutate(requestArg: NativeGraphQLRequest, callback: (Result) -> Unit) +{ + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" + val channelName = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.mutate$separatedMessageChannelSuffix" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(requestArg)) { - val result = it as NativeGraphQLResponse - callback(result) + if (it is List<*>) { + if (it.size > 1) { + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) + } else if (it[0] == null) { + callback(Result.failure(FlutterError("null-error", "Flutter api returned null value for non-null return value.", ""))) + } else { + val output = it[0] as NativeGraphQLResponse + callback(Result.success(output)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } } } - fun query(requestArg: NativeGraphQLRequest, callback: (NativeGraphQLResponse) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.query", codec) + fun query(requestArg: NativeGraphQLRequest, callback: (Result) -> Unit) +{ + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" + val channelName = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.query$separatedMessageChannelSuffix" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(requestArg)) { - val result = it as NativeGraphQLResponse - callback(result) + if (it is List<*>) { + if (it.size > 1) { + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) + } else if (it[0] == null) { + callback(Result.failure(FlutterError("null-error", "Flutter api returned null value for non-null return value.", ""))) + } else { + val output = it[0] as NativeGraphQLResponse + callback(Result.success(output)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } } } - fun subscribe(requestArg: NativeGraphQLRequest, callback: (NativeGraphQLSubscriptionResponse) -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.subscribe", codec) + fun subscribe(requestArg: NativeGraphQLRequest, callback: (Result) -> Unit) +{ + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" + val channelName = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.subscribe$separatedMessageChannelSuffix" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(requestArg)) { - val result = it as NativeGraphQLSubscriptionResponse - callback(result) + if (it is List<*>) { + if (it.size > 1) { + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) + } else if (it[0] == null) { + callback(Result.failure(FlutterError("null-error", "Flutter api returned null value for non-null return value.", ""))) + } else { + val output = it[0] as NativeGraphQLSubscriptionResponse + callback(Result.success(output)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } } } - fun unsubscribe(subscriptionIdArg: String, callback: () -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.unsubscribe", codec) + fun unsubscribe(subscriptionIdArg: String, callback: (Result) -> Unit) +{ + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" + val channelName = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.unsubscribe$separatedMessageChannelSuffix" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(listOf(subscriptionIdArg)) { - callback() + if (it is List<*>) { + if (it.size > 1) { + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } } } - fun deviceOffline(callback: () -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.deviceOffline", codec) + fun deviceOffline(callback: (Result) -> Unit) +{ + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" + val channelName = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.deviceOffline$separatedMessageChannelSuffix" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(null) { - callback() + if (it is List<*>) { + if (it.size > 1) { + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } } } - fun onStop(callback: () -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.onStop", codec) + fun onStop(callback: (Result) -> Unit) +{ + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" + val channelName = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.onStop$separatedMessageChannelSuffix" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) channel.send(null) { - callback() + if (it is List<*>) { + if (it.size > 1) { + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } } } } @@ -411,13 +540,14 @@ interface NativeAmplifyBridge { companion object { /** The codec used by NativeAmplifyBridge. */ val codec: MessageCodec by lazy { - StandardMessageCodec() + NativePluginBindingsPigeonCodec() } /** Sets up an instance of `NativeAmplifyBridge` to handle messages through the `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") - fun setUp(binaryMessenger: BinaryMessenger, api: NativeAmplifyBridge?) { + @JvmOverloads + fun setUp(binaryMessenger: BinaryMessenger, api: NativeAmplifyBridge?, messageChannelSuffix: String = "") { + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeAmplifyBridge.configure", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeAmplifyBridge.configure$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List @@ -439,29 +569,6 @@ interface NativeAmplifyBridge { } } } -@Suppress("UNCHECKED_CAST") -private object NativeAuthBridgeCodec : StandardMessageCodec() { - override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { - return when (type) { - 128.toByte() -> { - return (readValue(buffer) as? List)?.let { - NativeAuthUser.fromList(it) - } - } - else -> super.readValueOfType(type, buffer) - } - } - override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { - when (value) { - is NativeAuthUser -> { - stream.write(128) - writeValue(stream, value.toList()) - } - else -> super.writeValue(stream, value) - } - } -} - /** * Bridge for calling Auth plugin from Flutter into Native * @@ -474,16 +581,17 @@ interface NativeAuthBridge { companion object { /** The codec used by NativeAuthBridge. */ val codec: MessageCodec by lazy { - NativeAuthBridgeCodec + NativePluginBindingsPigeonCodec() } /** Sets up an instance of `NativeAuthBridge` to handle messages through the `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") - fun setUp(binaryMessenger: BinaryMessenger, api: NativeAuthBridge?) { + @JvmOverloads + fun setUp(binaryMessenger: BinaryMessenger, api: NativeAuthBridge?, messageChannelSuffix: String = "") { + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.addAuthPlugin", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.addAuthPlugin$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { _, reply -> - api.addAuthPlugin() { result: Result -> + api.addAuthPlugin{ result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -497,17 +605,16 @@ interface NativeAuthBridge { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.updateCurrentUser", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.updateCurrentUser$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List val userArg = args[0] as NativeAuthUser? - var wrapped: List - try { + val wrapped: List = try { api.updateCurrentUser(userArg) - wrapped = listOf(null) + listOf(null) } catch (exception: Throwable) { - wrapped = wrapError(exception) + wrapError(exception) } reply.reply(wrapped) } @@ -518,29 +625,6 @@ interface NativeAuthBridge { } } } -@Suppress("UNCHECKED_CAST") -private object NativeApiBridgeCodec : StandardMessageCodec() { - override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { - return when (type) { - 128.toByte() -> { - return (readValue(buffer) as? List)?.let { - NativeGraphQLSubscriptionResponse.fromList(it) - } - } - else -> super.readValueOfType(type, buffer) - } - } - override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { - when (value) { - is NativeGraphQLSubscriptionResponse -> { - stream.write(128) - writeValue(stream, value.toList()) - } - else -> super.writeValue(stream, value) - } - } -} - /** * Bridge for calling API methods from Flutter into Native * @@ -553,13 +637,14 @@ interface NativeApiBridge { companion object { /** The codec used by NativeApiBridge. */ val codec: MessageCodec by lazy { - NativeApiBridgeCodec + NativePluginBindingsPigeonCodec() } /** Sets up an instance of `NativeApiBridge` to handle messages through the `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") - fun setUp(binaryMessenger: BinaryMessenger, api: NativeApiBridge?) { + @JvmOverloads + fun setUp(binaryMessenger: BinaryMessenger, api: NativeApiBridge?, messageChannelSuffix: String = "") { + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeApiBridge.addApiPlugin", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeApiBridge.addApiPlugin$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List @@ -579,7 +664,7 @@ interface NativeApiBridge { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeApiBridge.sendSubscriptionEvent", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_datastore.NativeApiBridge.sendSubscriptionEvent$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List diff --git a/packages/amplify_datastore/ios/Classes/pigeons/NativePluginBindings.swift b/packages/amplify_datastore/ios/Classes/pigeons/NativePluginBindings.swift index df1b268a75..cfd8646841 100644 --- a/packages/amplify_datastore/ios/Classes/pigeons/NativePluginBindings.swift +++ b/packages/amplify_datastore/ios/Classes/pigeons/NativePluginBindings.swift @@ -1,20 +1,35 @@ -// +// // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Autogenerated from Pigeon (v11.0.1), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation + #if os(iOS) -import Flutter + import Flutter #elseif os(macOS) -import FlutterMacOS + import FlutterMacOS #else -#error("Unsupported platform.") + #error("Unsupported platform.") #endif -private func isNullish(_ value: Any?) -> Bool { - return value is NSNull || value == nil +/// Error class for passing custom error details to Dart side. +final class PigeonError: Error { + let code: String + let message: String? + let details: Any? + + init(code: String, message: String?, details: Any?) { + self.code = code + self.message = message + self.details = details + } + + var localizedDescription: String { + return + "PigeonError(code: \(code), message: \(message ?? ""), details: \(details ?? "")" + } } private func wrapResult(_ result: Any?) -> [Any?] { @@ -22,20 +37,35 @@ private func wrapResult(_ result: Any?) -> [Any?] { } private func wrapError(_ error: Any) -> [Any?] { + if let pigeonError = error as? PigeonError { + return [ + pigeonError.code, + pigeonError.message, + pigeonError.details, + ] + } if let flutterError = error as? FlutterError { return [ flutterError.code, flutterError.message, - flutterError.details + flutterError.details, ] } return [ "\(error)", "\(type(of: error))", - "Stacktrace: \(Thread.callStackSymbols)" + "Stacktrace: \(Thread.callStackSymbols)", ] } +private func createConnectionError(withChannelName channelName: String) -> PigeonError { + return PigeonError(code: "channel-error", message: "Unable to establish connection on channel: '\(channelName)'.", details: "") +} + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + private func nilOrValue(_ value: Any?) -> T? { if value is NSNull { return nil } return value as! T? @@ -49,18 +79,15 @@ struct NativeAuthSession { var identityId: String? = nil var awsCredentials: NativeAWSCredentials? = nil - static func fromList(_ list: [Any?]) -> NativeAuthSession? { - let isSignedIn = list[0] as! Bool - let userSub: String? = nilOrValue(list[1]) - var userPoolTokens: NativeUserPoolTokens? = nil - if let userPoolTokensList: [Any?] = nilOrValue(list[2]) { - userPoolTokens = NativeUserPoolTokens.fromList(userPoolTokensList) - } - let identityId: String? = nilOrValue(list[3]) - var awsCredentials: NativeAWSCredentials? = nil - if let awsCredentialsList: [Any?] = nilOrValue(list[4]) { - awsCredentials = NativeAWSCredentials.fromList(awsCredentialsList) - } + + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> NativeAuthSession? { + let isSignedIn = pigeonVar_list[0] as! Bool + let userSub: String? = nilOrValue(pigeonVar_list[1]) + let userPoolTokens: NativeUserPoolTokens? = nilOrValue(pigeonVar_list[2]) + let identityId: String? = nilOrValue(pigeonVar_list[3]) + let awsCredentials: NativeAWSCredentials? = nilOrValue(pigeonVar_list[4]) return NativeAuthSession( isSignedIn: isSignedIn, @@ -74,9 +101,9 @@ struct NativeAuthSession { return [ isSignedIn, userSub, - userPoolTokens?.toList(), + userPoolTokens, identityId, - awsCredentials?.toList(), + awsCredentials, ] } } @@ -86,9 +113,12 @@ struct NativeAuthUser { var userId: String var username: String - static func fromList(_ list: [Any?]) -> NativeAuthUser? { - let userId = list[0] as! String - let username = list[1] as! String + + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> NativeAuthUser? { + let userId = pigeonVar_list[0] as! String + let username = pigeonVar_list[1] as! String return NativeAuthUser( userId: userId, @@ -109,10 +139,13 @@ struct NativeUserPoolTokens { var refreshToken: String var idToken: String - static func fromList(_ list: [Any?]) -> NativeUserPoolTokens? { - let accessToken = list[0] as! String - let refreshToken = list[1] as! String - let idToken = list[2] as! String + + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> NativeUserPoolTokens? { + let accessToken = pigeonVar_list[0] as! String + let refreshToken = pigeonVar_list[1] as! String + let idToken = pigeonVar_list[2] as! String return NativeUserPoolTokens( accessToken: accessToken, @@ -136,11 +169,14 @@ struct NativeAWSCredentials { var sessionToken: String? = nil var expirationIso8601Utc: String? = nil - static func fromList(_ list: [Any?]) -> NativeAWSCredentials? { - let accessKeyId = list[0] as! String - let secretAccessKey = list[1] as! String - let sessionToken: String? = nilOrValue(list[2]) - let expirationIso8601Utc: String? = nilOrValue(list[3]) + + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> NativeAWSCredentials? { + let accessKeyId = pigeonVar_list[0] as! String + let secretAccessKey = pigeonVar_list[1] as! String + let sessionToken: String? = nilOrValue(pigeonVar_list[2]) + let expirationIso8601Utc: String? = nilOrValue(pigeonVar_list[3]) return NativeAWSCredentials( accessKeyId: accessKeyId, @@ -159,12 +195,64 @@ struct NativeAWSCredentials { } } +/// Generated class from Pigeon that represents data sent in messages. +struct LegacyCredentialStoreData { + var identityId: String? = nil + var accessKeyId: String? = nil + var secretAccessKey: String? = nil + var sessionToken: String? = nil + var expirationMsSinceEpoch: Int64? = nil + var accessToken: String? = nil + var refreshToken: String? = nil + var idToken: String? = nil + + + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> LegacyCredentialStoreData? { + let identityId: String? = nilOrValue(pigeonVar_list[0]) + let accessKeyId: String? = nilOrValue(pigeonVar_list[1]) + let secretAccessKey: String? = nilOrValue(pigeonVar_list[2]) + let sessionToken: String? = nilOrValue(pigeonVar_list[3]) + let expirationMsSinceEpoch: Int64? = nilOrValue(pigeonVar_list[4]) + let accessToken: String? = nilOrValue(pigeonVar_list[5]) + let refreshToken: String? = nilOrValue(pigeonVar_list[6]) + let idToken: String? = nilOrValue(pigeonVar_list[7]) + + return LegacyCredentialStoreData( + identityId: identityId, + accessKeyId: accessKeyId, + secretAccessKey: secretAccessKey, + sessionToken: sessionToken, + expirationMsSinceEpoch: expirationMsSinceEpoch, + accessToken: accessToken, + refreshToken: refreshToken, + idToken: idToken + ) + } + func toList() -> [Any?] { + return [ + identityId, + accessKeyId, + secretAccessKey, + sessionToken, + expirationMsSinceEpoch, + accessToken, + refreshToken, + idToken, + ] + } +} + /// Generated class from Pigeon that represents data sent in messages. struct NativeGraphQLResponse { var payloadJson: String? = nil - static func fromList(_ list: [Any?]) -> NativeGraphQLResponse? { - let payloadJson: String? = nilOrValue(list[0]) + + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> NativeGraphQLResponse? { + let payloadJson: String? = nilOrValue(pigeonVar_list[0]) return NativeGraphQLResponse( payloadJson: payloadJson @@ -172,7 +260,7 @@ struct NativeGraphQLResponse { } func toList() -> [Any?] { return [ - payloadJson, + payloadJson ] } } @@ -183,10 +271,13 @@ struct NativeGraphQLSubscriptionResponse { var subscriptionId: String var payloadJson: String? = nil - static func fromList(_ list: [Any?]) -> NativeGraphQLSubscriptionResponse? { - let type = list[0] as! String - let subscriptionId = list[1] as! String - let payloadJson: String? = nilOrValue(list[2]) + + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> NativeGraphQLSubscriptionResponse? { + let type = pigeonVar_list[0] as! String + let subscriptionId = pigeonVar_list[1] as! String + let payloadJson: String? = nilOrValue(pigeonVar_list[2]) return NativeGraphQLSubscriptionResponse( type: type, @@ -213,14 +304,17 @@ struct NativeGraphQLRequest { var options: String? = nil var authMode: String? = nil - static func fromList(_ list: [Any?]) -> NativeGraphQLRequest? { - let document = list[0] as! String - let apiName: String? = nilOrValue(list[1]) - let variablesJson: String? = nilOrValue(list[2]) - let responseType: String? = nilOrValue(list[3]) - let decodePath: String? = nilOrValue(list[4]) - let options: String? = nilOrValue(list[5]) - let authMode: String? = nilOrValue(list[6]) + + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> NativeGraphQLRequest? { + let document = pigeonVar_list[0] as! String + let apiName: String? = nilOrValue(pigeonVar_list[1]) + let variablesJson: String? = nilOrValue(pigeonVar_list[2]) + let responseType: String? = nilOrValue(pigeonVar_list[3]) + let decodePath: String? = nilOrValue(pigeonVar_list[4]) + let options: String? = nilOrValue(pigeonVar_list[5]) + let authMode: String? = nilOrValue(pigeonVar_list[6]) return NativeGraphQLRequest( document: document, @@ -245,172 +339,272 @@ struct NativeGraphQLRequest { } } -private class NativeAuthPluginCodecReader: FlutterStandardReader { +private class NativePluginBindingsPigeonCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { - case 128: - return NativeAWSCredentials.fromList(self.readValue() as! [Any?]) - case 129: - return NativeAuthSession.fromList(self.readValue() as! [Any?]) - case 130: - return NativeUserPoolTokens.fromList(self.readValue() as! [Any?]) - default: - return super.readValue(ofType: type) + case 129: + return NativeAuthSession.fromList(self.readValue() as! [Any?]) + case 130: + return NativeAuthUser.fromList(self.readValue() as! [Any?]) + case 131: + return NativeUserPoolTokens.fromList(self.readValue() as! [Any?]) + case 132: + return NativeAWSCredentials.fromList(self.readValue() as! [Any?]) + case 133: + return LegacyCredentialStoreData.fromList(self.readValue() as! [Any?]) + case 134: + return NativeGraphQLResponse.fromList(self.readValue() as! [Any?]) + case 135: + return NativeGraphQLSubscriptionResponse.fromList(self.readValue() as! [Any?]) + case 136: + return NativeGraphQLRequest.fromList(self.readValue() as! [Any?]) + default: + return super.readValue(ofType: type) } } } -private class NativeAuthPluginCodecWriter: FlutterStandardWriter { +private class NativePluginBindingsPigeonCodecWriter: FlutterStandardWriter { override func writeValue(_ value: Any) { - if let value = value as? NativeAWSCredentials { - super.writeByte(128) - super.writeValue(value.toList()) - } else if let value = value as? NativeAuthSession { + if let value = value as? NativeAuthSession { super.writeByte(129) super.writeValue(value.toList()) - } else if let value = value as? NativeUserPoolTokens { + } else if let value = value as? NativeAuthUser { super.writeByte(130) super.writeValue(value.toList()) + } else if let value = value as? NativeUserPoolTokens { + super.writeByte(131) + super.writeValue(value.toList()) + } else if let value = value as? NativeAWSCredentials { + super.writeByte(132) + super.writeValue(value.toList()) + } else if let value = value as? LegacyCredentialStoreData { + super.writeByte(133) + super.writeValue(value.toList()) + } else if let value = value as? NativeGraphQLResponse { + super.writeByte(134) + super.writeValue(value.toList()) + } else if let value = value as? NativeGraphQLSubscriptionResponse { + super.writeByte(135) + super.writeValue(value.toList()) + } else if let value = value as? NativeGraphQLRequest { + super.writeByte(136) + super.writeValue(value.toList()) } else { super.writeValue(value) } } } -private class NativeAuthPluginCodecReaderWriter: FlutterStandardReaderWriter { +private class NativePluginBindingsPigeonCodecReaderWriter: FlutterStandardReaderWriter { override func reader(with data: Data) -> FlutterStandardReader { - return NativeAuthPluginCodecReader(data: data) + return NativePluginBindingsPigeonCodecReader(data: data) } override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return NativeAuthPluginCodecWriter(data: data) + return NativePluginBindingsPigeonCodecWriter(data: data) } } -class NativeAuthPluginCodec: FlutterStandardMessageCodec { - static let shared = NativeAuthPluginCodec(readerWriter: NativeAuthPluginCodecReaderWriter()) +class NativePluginBindingsPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable { + static let shared = NativePluginBindingsPigeonCodec(readerWriter: NativePluginBindingsPigeonCodecReaderWriter()) } + /// Bridge for calling Auth from Native into Flutter /// -/// Generated class from Pigeon that represents Flutter messages that can be called from Swift. -class NativeAuthPlugin { +/// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift. +protocol NativeAuthPluginProtocol { + func fetchAuthSession(completion: @escaping (Result) -> Void) +} +class NativeAuthPlugin: NativeAuthPluginProtocol { private let binaryMessenger: FlutterBinaryMessenger - init(binaryMessenger: FlutterBinaryMessenger){ + private let messageChannelSuffix: String + init(binaryMessenger: FlutterBinaryMessenger, messageChannelSuffix: String = "") { self.binaryMessenger = binaryMessenger + self.messageChannelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" } - var codec: FlutterStandardMessageCodec { - return NativeAuthPluginCodec.shared + var codec: NativePluginBindingsPigeonCodec { + return NativePluginBindingsPigeonCodec.shared } - func fetchAuthSession(completion: @escaping (NativeAuthSession) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeAuthPlugin.fetchAuthSession", binaryMessenger: binaryMessenger, codec: codec) + func fetchAuthSession(completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.amplify_datastore.NativeAuthPlugin.fetchAuthSession\(messageChannelSuffix)" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage(nil) { response in - let result = response as! NativeAuthSession - completion(result) - } - } -} -private class NativeApiPluginCodecReader: FlutterStandardReader { - override func readValue(ofType type: UInt8) -> Any? { - switch type { - case 128: - return NativeGraphQLRequest.fromList(self.readValue() as! [Any?]) - case 129: - return NativeGraphQLResponse.fromList(self.readValue() as! [Any?]) - case 130: - return NativeGraphQLSubscriptionResponse.fromList(self.readValue() as! [Any?]) - default: - return super.readValue(ofType: type) - } - } -} - -private class NativeApiPluginCodecWriter: FlutterStandardWriter { - override func writeValue(_ value: Any) { - if let value = value as? NativeGraphQLRequest { - super.writeByte(128) - super.writeValue(value.toList()) - } else if let value = value as? NativeGraphQLResponse { - super.writeByte(129) - super.writeValue(value.toList()) - } else if let value = value as? NativeGraphQLSubscriptionResponse { - super.writeByte(130) - super.writeValue(value.toList()) - } else { - super.writeValue(value) + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion(.failure(PigeonError(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! NativeAuthSession + completion(.success(result)) + } } } } - -private class NativeApiPluginCodecReaderWriter: FlutterStandardReaderWriter { - override func reader(with data: Data) -> FlutterStandardReader { - return NativeApiPluginCodecReader(data: data) - } - - override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return NativeApiPluginCodecWriter(data: data) - } -} - -class NativeApiPluginCodec: FlutterStandardMessageCodec { - static let shared = NativeApiPluginCodec(readerWriter: NativeApiPluginCodecReaderWriter()) -} - /// Bridge for calling API plugin from Native into Flutter /// -/// Generated class from Pigeon that represents Flutter messages that can be called from Swift. -class NativeApiPlugin { +/// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift. +protocol NativeApiPluginProtocol { + func getLatestAuthToken(providerName providerNameArg: String, completion: @escaping (Result) -> Void) + func mutate(request requestArg: NativeGraphQLRequest, completion: @escaping (Result) -> Void) + func query(request requestArg: NativeGraphQLRequest, completion: @escaping (Result) -> Void) + func subscribe(request requestArg: NativeGraphQLRequest, completion: @escaping (Result) -> Void) + func unsubscribe(subscriptionId subscriptionIdArg: String, completion: @escaping (Result) -> Void) + func deviceOffline(completion: @escaping (Result) -> Void) + func onStop(completion: @escaping (Result) -> Void) +} +class NativeApiPlugin: NativeApiPluginProtocol { private let binaryMessenger: FlutterBinaryMessenger - init(binaryMessenger: FlutterBinaryMessenger){ + private let messageChannelSuffix: String + init(binaryMessenger: FlutterBinaryMessenger, messageChannelSuffix: String = "") { self.binaryMessenger = binaryMessenger + self.messageChannelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" } - var codec: FlutterStandardMessageCodec { - return NativeApiPluginCodec.shared + var codec: NativePluginBindingsPigeonCodec { + return NativePluginBindingsPigeonCodec.shared } - func getLatestAuthToken(providerName providerNameArg: String, completion: @escaping (String?) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.getLatestAuthToken", binaryMessenger: binaryMessenger, codec: codec) + func getLatestAuthToken(providerName providerNameArg: String, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.getLatestAuthToken\(messageChannelSuffix)" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([providerNameArg] as [Any?]) { response in - let result: String? = nilOrValue(response) - completion(result) + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + let result: String? = nilOrValue(listResponse[0]) + completion(.success(result)) + } } } - func mutate(request requestArg: NativeGraphQLRequest, completion: @escaping (NativeGraphQLResponse) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.mutate", binaryMessenger: binaryMessenger, codec: codec) + func mutate(request requestArg: NativeGraphQLRequest, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.mutate\(messageChannelSuffix)" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([requestArg] as [Any?]) { response in - let result = response as! NativeGraphQLResponse - completion(result) + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion(.failure(PigeonError(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! NativeGraphQLResponse + completion(.success(result)) + } } } - func query(request requestArg: NativeGraphQLRequest, completion: @escaping (NativeGraphQLResponse) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.query", binaryMessenger: binaryMessenger, codec: codec) + func query(request requestArg: NativeGraphQLRequest, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.query\(messageChannelSuffix)" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([requestArg] as [Any?]) { response in - let result = response as! NativeGraphQLResponse - completion(result) + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion(.failure(PigeonError(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! NativeGraphQLResponse + completion(.success(result)) + } } } - func subscribe(request requestArg: NativeGraphQLRequest, completion: @escaping (NativeGraphQLSubscriptionResponse) -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.subscribe", binaryMessenger: binaryMessenger, codec: codec) + func subscribe(request requestArg: NativeGraphQLRequest, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.subscribe\(messageChannelSuffix)" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) channel.sendMessage([requestArg] as [Any?]) { response in - let result = response as! NativeGraphQLSubscriptionResponse - completion(result) + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else if listResponse[0] == nil { + completion(.failure(PigeonError(code: "null-error", message: "Flutter api returned null value for non-null return value.", details: ""))) + } else { + let result = listResponse[0] as! NativeGraphQLSubscriptionResponse + completion(.success(result)) + } } } - func unsubscribe(subscriptionId subscriptionIdArg: String, completion: @escaping () -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.unsubscribe", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage([subscriptionIdArg] as [Any?]) { _ in - completion() + func unsubscribe(subscriptionId subscriptionIdArg: String, completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.unsubscribe\(messageChannelSuffix)" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([subscriptionIdArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } } } - func deviceOffline(completion: @escaping () -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.deviceOffline", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage(nil) { _ in - completion() + func deviceOffline(completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.deviceOffline\(messageChannelSuffix)" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage(nil) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } } } - func onStop(completion: @escaping () -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.onStop", binaryMessenger: binaryMessenger, codec: codec) - channel.sendMessage(nil) { _ in - completion() + func onStop(completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.onStop\(messageChannelSuffix)" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage(nil) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } } } } @@ -423,10 +617,11 @@ protocol NativeAmplifyBridge { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class NativeAmplifyBridgeSetup { - /// The codec used by NativeAmplifyBridge. + static var codec: FlutterStandardMessageCodec { NativePluginBindingsPigeonCodec.shared } /// Sets up an instance of `NativeAmplifyBridge` to handle messages through the `binaryMessenger`. - static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NativeAmplifyBridge?) { - let configureChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeAmplifyBridge.configure", binaryMessenger: binaryMessenger) + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NativeAmplifyBridge?, messageChannelSuffix: String = "") { + let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" + let configureChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeAmplifyBridge.configure\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { configureChannel.setMessageHandler { message, reply in let args = message as! [Any?] @@ -434,10 +629,10 @@ class NativeAmplifyBridgeSetup { let configArg = args[1] as! String api.configure(version: versionArg, config: configArg) { result in switch result { - case .success: - reply(wrapResult(nil)) - case .failure(let error): - reply(wrapError(error)) + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) } } } @@ -446,42 +641,6 @@ class NativeAmplifyBridgeSetup { } } } -private class NativeAuthBridgeCodecReader: FlutterStandardReader { - override func readValue(ofType type: UInt8) -> Any? { - switch type { - case 128: - return NativeAuthUser.fromList(self.readValue() as! [Any?]) - default: - return super.readValue(ofType: type) - } - } -} - -private class NativeAuthBridgeCodecWriter: FlutterStandardWriter { - override func writeValue(_ value: Any) { - if let value = value as? NativeAuthUser { - super.writeByte(128) - super.writeValue(value.toList()) - } else { - super.writeValue(value) - } - } -} - -private class NativeAuthBridgeCodecReaderWriter: FlutterStandardReaderWriter { - override func reader(with data: Data) -> FlutterStandardReader { - return NativeAuthBridgeCodecReader(data: data) - } - - override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return NativeAuthBridgeCodecWriter(data: data) - } -} - -class NativeAuthBridgeCodec: FlutterStandardMessageCodec { - static let shared = NativeAuthBridgeCodec(readerWriter: NativeAuthBridgeCodecReaderWriter()) -} - /// Bridge for calling Auth plugin from Flutter into Native /// /// Generated protocol from Pigeon that represents a handler of messages from Flutter. @@ -492,26 +651,26 @@ protocol NativeAuthBridge { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class NativeAuthBridgeSetup { - /// The codec used by NativeAuthBridge. - static var codec: FlutterStandardMessageCodec { NativeAuthBridgeCodec.shared } + static var codec: FlutterStandardMessageCodec { NativePluginBindingsPigeonCodec.shared } /// Sets up an instance of `NativeAuthBridge` to handle messages through the `binaryMessenger`. - static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NativeAuthBridge?) { - let addAuthPluginChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.addAuthPlugin", binaryMessenger: binaryMessenger, codec: codec) + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NativeAuthBridge?, messageChannelSuffix: String = "") { + let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" + let addAuthPluginChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.addAuthPlugin\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { addAuthPluginChannel.setMessageHandler { _, reply in - api.addAuthPlugin() { result in + api.addAuthPlugin { result in switch result { - case .success: - reply(wrapResult(nil)) - case .failure(let error): - reply(wrapError(error)) + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) } } } } else { addAuthPluginChannel.setMessageHandler(nil) } - let updateCurrentUserChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.updateCurrentUser", binaryMessenger: binaryMessenger, codec: codec) + let updateCurrentUserChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.updateCurrentUser\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { updateCurrentUserChannel.setMessageHandler { message, reply in let args = message as! [Any?] @@ -528,42 +687,6 @@ class NativeAuthBridgeSetup { } } } -private class NativeApiBridgeCodecReader: FlutterStandardReader { - override func readValue(ofType type: UInt8) -> Any? { - switch type { - case 128: - return NativeGraphQLSubscriptionResponse.fromList(self.readValue() as! [Any?]) - default: - return super.readValue(ofType: type) - } - } -} - -private class NativeApiBridgeCodecWriter: FlutterStandardWriter { - override func writeValue(_ value: Any) { - if let value = value as? NativeGraphQLSubscriptionResponse { - super.writeByte(128) - super.writeValue(value.toList()) - } else { - super.writeValue(value) - } - } -} - -private class NativeApiBridgeCodecReaderWriter: FlutterStandardReaderWriter { - override func reader(with data: Data) -> FlutterStandardReader { - return NativeApiBridgeCodecReader(data: data) - } - - override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return NativeApiBridgeCodecWriter(data: data) - } -} - -class NativeApiBridgeCodec: FlutterStandardMessageCodec { - static let shared = NativeApiBridgeCodec(readerWriter: NativeApiBridgeCodecReaderWriter()) -} - /// Bridge for calling API methods from Flutter into Native /// /// Generated protocol from Pigeon that represents a handler of messages from Flutter. @@ -574,11 +697,11 @@ protocol NativeApiBridge { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class NativeApiBridgeSetup { - /// The codec used by NativeApiBridge. - static var codec: FlutterStandardMessageCodec { NativeApiBridgeCodec.shared } + static var codec: FlutterStandardMessageCodec { NativePluginBindingsPigeonCodec.shared } /// Sets up an instance of `NativeApiBridge` to handle messages through the `binaryMessenger`. - static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NativeApiBridge?) { - let addApiPluginChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeApiBridge.addApiPlugin", binaryMessenger: binaryMessenger, codec: codec) + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NativeApiBridge?, messageChannelSuffix: String = "") { + let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" + let addApiPluginChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeApiBridge.addApiPlugin\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { addApiPluginChannel.setMessageHandler { message, reply in let args = message as! [Any?] @@ -586,27 +709,27 @@ class NativeApiBridgeSetup { let endpointsArg = args[1] as! [String: String] api.addApiPlugin(authProvidersList: authProvidersListArg, endpoints: endpointsArg) { result in switch result { - case .success: - reply(wrapResult(nil)) - case .failure(let error): - reply(wrapError(error)) + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) } } } } else { addApiPluginChannel.setMessageHandler(nil) } - let sendSubscriptionEventChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeApiBridge.sendSubscriptionEvent", binaryMessenger: binaryMessenger, codec: codec) + let sendSubscriptionEventChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_datastore.NativeApiBridge.sendSubscriptionEvent\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { sendSubscriptionEventChannel.setMessageHandler { message, reply in let args = message as! [Any?] let eventArg = args[0] as! NativeGraphQLSubscriptionResponse api.sendSubscriptionEvent(event: eventArg) { result in switch result { - case .success: - reply(wrapResult(nil)) - case .failure(let error): - reply(wrapError(error)) + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) } } } diff --git a/packages/amplify_datastore/lib/amplify_datastore.dart b/packages/amplify_datastore/lib/amplify_datastore.dart index b71231d95c..f94384ed6a 100644 --- a/packages/amplify_datastore/lib/amplify_datastore.dart +++ b/packages/amplify_datastore/lib/amplify_datastore.dart @@ -61,7 +61,7 @@ class AmplifyDataStore extends DataStorePluginInterface if (authPlugin != null) { // Configure this plugin to act as a native iOS/Android plugin. final nativePlugin = _NativeAmplifyAuthCognito(); - NativeAuthPlugin.setup(nativePlugin); + NativeAuthPlugin.setUp(nativePlugin); final nativeBridge = NativeAuthBridge(); try { await nativeBridge.addAuthPlugin(); @@ -109,7 +109,7 @@ class AmplifyDataStore extends DataStorePluginInterface endpoints[e.key] = e.value.defaultAuthorizationType.name; }); final nativePlugin = NativeAmplifyApi(authProviders); - NativeApiPlugin.setup(nativePlugin); + NativeApiPlugin.setUp(nativePlugin); final nativeBridge = NativeApiBridge(); try { diff --git a/packages/amplify_datastore/lib/src/native_plugin.g.dart b/packages/amplify_datastore/lib/src/native_plugin.g.dart index c87f9b9994..f385d6c848 100644 --- a/packages/amplify_datastore/lib/src/native_plugin.g.dart +++ b/packages/amplify_datastore/lib/src/native_plugin.g.dart @@ -1,9 +1,9 @@ // // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Autogenerated from Pigeon (v11.0.1), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -11,6 +11,24 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + +List wrapResponse( + {Object? result, PlatformException? error, bool empty = false}) { + if (empty) { + return []; + } + if (error == null) { + return [result]; + } + return [error.code, error.message, error.details]; +} + class NativeAuthSession { NativeAuthSession({ required this.isSignedIn, @@ -34,9 +52,9 @@ class NativeAuthSession { return [ isSignedIn, userSub, - userPoolTokens?.encode(), + userPoolTokens, identityId, - awsCredentials?.encode(), + awsCredentials, ]; } @@ -45,13 +63,9 @@ class NativeAuthSession { return NativeAuthSession( isSignedIn: result[0]! as bool, userSub: result[1] as String?, - userPoolTokens: result[2] != null - ? NativeUserPoolTokens.decode(result[2]! as List) - : null, + userPoolTokens: result[2] as NativeUserPoolTokens?, identityId: result[3] as String?, - awsCredentials: result[4] != null - ? NativeAWSCredentials.decode(result[4]! as List) - : null, + awsCredentials: result[4] as NativeAWSCredentials?, ); } } @@ -149,6 +163,62 @@ class NativeAWSCredentials { } } +class LegacyCredentialStoreData { + LegacyCredentialStoreData({ + this.identityId, + this.accessKeyId, + this.secretAccessKey, + this.sessionToken, + this.expirationMsSinceEpoch, + this.accessToken, + this.refreshToken, + this.idToken, + }); + + String? identityId; + + String? accessKeyId; + + String? secretAccessKey; + + String? sessionToken; + + int? expirationMsSinceEpoch; + + String? accessToken; + + String? refreshToken; + + String? idToken; + + Object encode() { + return [ + identityId, + accessKeyId, + secretAccessKey, + sessionToken, + expirationMsSinceEpoch, + accessToken, + refreshToken, + idToken, + ]; + } + + static LegacyCredentialStoreData decode(Object result) { + result as List; + return LegacyCredentialStoreData( + identityId: result[0] as String?, + accessKeyId: result[1] as String?, + secretAccessKey: result[2] as String?, + sessionToken: result[3] as String?, + expirationMsSinceEpoch: result[4] as int?, + accessToken: result[5] as String?, + refreshToken: result[6] as String?, + idToken: result[7] as String?, + ); + } +} + class NativeGraphQLResponse { NativeGraphQLResponse({ this.payloadJson, @@ -252,19 +322,37 @@ class NativeGraphQLRequest { } } -class _NativeAuthPluginCodec extends StandardMessageCodec { - const _NativeAuthPluginCodec(); +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is NativeAWSCredentials) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); + if (value is int) { + buffer.putUint8(4); + buffer.putInt64(value); } else if (value is NativeAuthSession) { buffer.putUint8(129); writeValue(buffer, value.encode()); - } else if (value is NativeUserPoolTokens) { + } else if (value is NativeAuthUser) { buffer.putUint8(130); writeValue(buffer, value.encode()); + } else if (value is NativeUserPoolTokens) { + buffer.putUint8(131); + writeValue(buffer, value.encode()); + } else if (value is NativeAWSCredentials) { + buffer.putUint8(132); + writeValue(buffer, value.encode()); + } else if (value is LegacyCredentialStoreData) { + buffer.putUint8(133); + writeValue(buffer, value.encode()); + } else if (value is NativeGraphQLResponse) { + buffer.putUint8(134); + writeValue(buffer, value.encode()); + } else if (value is NativeGraphQLSubscriptionResponse) { + buffer.putUint8(135); + writeValue(buffer, value.encode()); + } else if (value is NativeGraphQLRequest) { + buffer.putUint8(136); + writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -273,12 +361,22 @@ class _NativeAuthPluginCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: - return NativeAWSCredentials.decode(readValue(buffer)!); case 129: return NativeAuthSession.decode(readValue(buffer)!); case 130: + return NativeAuthUser.decode(readValue(buffer)!); + case 131: return NativeUserPoolTokens.decode(readValue(buffer)!); + case 132: + return NativeAWSCredentials.decode(readValue(buffer)!); + case 133: + return LegacyCredentialStoreData.decode(readValue(buffer)!); + case 134: + return NativeGraphQLResponse.decode(readValue(buffer)!); + case 135: + return NativeGraphQLSubscriptionResponse.decode(readValue(buffer)!); + case 136: + return NativeGraphQLRequest.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); } @@ -287,65 +385,46 @@ class _NativeAuthPluginCodec extends StandardMessageCodec { /// Bridge for calling Auth from Native into Flutter abstract class NativeAuthPlugin { - static const MessageCodec codec = _NativeAuthPluginCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); Future fetchAuthSession(); - static void setup(NativeAuthPlugin? api, {BinaryMessenger? binaryMessenger}) { + static void setUp( + NativeAuthPlugin? api, { + BinaryMessenger? binaryMessenger, + String messageChannelSuffix = '', + }) { + messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_datastore.NativeAuthPlugin.fetchAuthSession', - codec, + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.amplify_datastore.NativeAuthPlugin.fetchAuthSession$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + pigeonVar_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { - // ignore message - final NativeAuthSession output = await api.fetchAuthSession(); - return output; + pigeonVar_channel.setMessageHandler((Object? message) async { + try { + final NativeAuthSession output = await api.fetchAuthSession(); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } }); } } } } -class _NativeApiPluginCodec extends StandardMessageCodec { - const _NativeApiPluginCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is NativeGraphQLRequest) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is NativeGraphQLResponse) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else if (value is NativeGraphQLSubscriptionResponse) { - buffer.putUint8(130); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return NativeGraphQLRequest.decode(readValue(buffer)!); - case 129: - return NativeGraphQLResponse.decode(readValue(buffer)!); - case 130: - return NativeGraphQLSubscriptionResponse.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - /// Bridge for calling API plugin from Native into Flutter abstract class NativeApiPlugin { - static const MessageCodec codec = _NativeApiPluginCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); Future getLatestAuthToken(String providerName); @@ -362,36 +441,54 @@ abstract class NativeApiPlugin { Future onStop(); - static void setup(NativeApiPlugin? api, {BinaryMessenger? binaryMessenger}) { + static void setUp( + NativeApiPlugin? api, { + BinaryMessenger? binaryMessenger, + String messageChannelSuffix = '', + }) { + messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.getLatestAuthToken', - codec, + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.getLatestAuthToken$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + pigeonVar_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.getLatestAuthToken was null.'); final List args = (message as List?)!; final String? arg_providerName = (args[0] as String?); assert(arg_providerName != null, 'Argument for dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.getLatestAuthToken was null, expected non-null String.'); - final String? output = - await api.getLatestAuthToken(arg_providerName!); - return output; + try { + final String? output = + await api.getLatestAuthToken(arg_providerName!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } }); } } { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.mutate', codec, + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.mutate$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + pigeonVar_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.mutate was null.'); final List args = (message as List?)!; @@ -399,19 +496,29 @@ abstract class NativeApiPlugin { (args[0] as NativeGraphQLRequest?); assert(arg_request != null, 'Argument for dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.mutate was null, expected non-null NativeGraphQLRequest.'); - final NativeGraphQLResponse output = await api.mutate(arg_request!); - return output; + try { + final NativeGraphQLResponse output = await api.mutate(arg_request!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } }); } } { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.query', codec, + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.query$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + pigeonVar_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.query was null.'); final List args = (message as List?)!; @@ -419,20 +526,29 @@ abstract class NativeApiPlugin { (args[0] as NativeGraphQLRequest?); assert(arg_request != null, 'Argument for dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.query was null, expected non-null NativeGraphQLRequest.'); - final NativeGraphQLResponse output = await api.query(arg_request!); - return output; + try { + final NativeGraphQLResponse output = await api.query(arg_request!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } }); } } { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.subscribe', - codec, + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.subscribe$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + pigeonVar_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.subscribe was null.'); final List args = (message as List?)!; @@ -440,58 +556,91 @@ abstract class NativeApiPlugin { (args[0] as NativeGraphQLRequest?); assert(arg_request != null, 'Argument for dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.subscribe was null, expected non-null NativeGraphQLRequest.'); - final NativeGraphQLSubscriptionResponse output = - await api.subscribe(arg_request!); - return output; + try { + final NativeGraphQLSubscriptionResponse output = + await api.subscribe(arg_request!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } }); } } { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.unsubscribe', - codec, + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.unsubscribe$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + pigeonVar_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.unsubscribe was null.'); final List args = (message as List?)!; final String? arg_subscriptionId = (args[0] as String?); assert(arg_subscriptionId != null, 'Argument for dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.unsubscribe was null, expected non-null String.'); - await api.unsubscribe(arg_subscriptionId!); - return; + try { + await api.unsubscribe(arg_subscriptionId!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } }); } } { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.deviceOffline', - codec, + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.deviceOffline$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + pigeonVar_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { - // ignore message - await api.deviceOffline(); - return; + pigeonVar_channel.setMessageHandler((Object? message) async { + try { + await api.deviceOffline(); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } }); } } { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.onStop', codec, + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.amplify_datastore.NativeApiPlugin.onStop$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + pigeonVar_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { - // ignore message - await api.onStop(); - return; + pigeonVar_channel.setMessageHandler((Object? message) async { + try { + await api.onStop(); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } }); } } @@ -503,29 +652,35 @@ class NativeAmplifyBridge { /// Constructor for [NativeAmplifyBridge]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - NativeAmplifyBridge({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = StandardMessageCodec(); - - Future configure(String arg_version, String arg_config) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_datastore.NativeAmplifyBridge.configure', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_version, arg_config]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + NativeAmplifyBridge( + {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) + : pigeonVar_binaryMessenger = binaryMessenger, + pigeonVar_messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final BinaryMessenger? pigeonVar_binaryMessenger; + + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); + + final String pigeonVar_messageChannelSuffix; + + Future configure(String version, String config) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_datastore.NativeAmplifyBridge.configure$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([version, config]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; @@ -533,79 +688,64 @@ class NativeAmplifyBridge { } } -class _NativeAuthBridgeCodec extends StandardMessageCodec { - const _NativeAuthBridgeCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is NativeAuthUser) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return NativeAuthUser.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - /// Bridge for calling Auth plugin from Flutter into Native class NativeAuthBridge { /// Constructor for [NativeAuthBridge]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - NativeAuthBridge({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + NativeAuthBridge( + {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) + : pigeonVar_binaryMessenger = binaryMessenger, + pigeonVar_messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final BinaryMessenger? pigeonVar_binaryMessenger; + + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); - static const MessageCodec codec = _NativeAuthBridgeCodec(); + final String pigeonVar_messageChannelSuffix; Future addAuthPlugin() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.addAuthPlugin', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.addAuthPlugin$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send(null) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future updateCurrentUser(NativeAuthUser? arg_user) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.updateCurrentUser', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_user]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + Future updateCurrentUser(NativeAuthUser? user) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_datastore.NativeAuthBridge.updateCurrentUser$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([user]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; @@ -613,59 +753,41 @@ class NativeAuthBridge { } } -class _NativeApiBridgeCodec extends StandardMessageCodec { - const _NativeApiBridgeCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is NativeGraphQLSubscriptionResponse) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return NativeGraphQLSubscriptionResponse.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - /// Bridge for calling API methods from Flutter into Native class NativeApiBridge { /// Constructor for [NativeApiBridge]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - NativeApiBridge({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = _NativeApiBridgeCodec(); - - Future addApiPlugin(List arg_authProvidersList, - Map arg_endpoints) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_datastore.NativeApiBridge.addApiPlugin', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_authProvidersList, arg_endpoints]) - as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + NativeApiBridge( + {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) + : pigeonVar_binaryMessenger = binaryMessenger, + pigeonVar_messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final BinaryMessenger? pigeonVar_binaryMessenger; + + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); + + final String pigeonVar_messageChannelSuffix; + + Future addApiPlugin( + List authProvidersList, Map endpoints) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_datastore.NativeApiBridge.addApiPlugin$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([authProvidersList, endpoints]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; @@ -673,23 +795,24 @@ class NativeApiBridge { } Future sendSubscriptionEvent( - NativeGraphQLSubscriptionResponse arg_event) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_datastore.NativeApiBridge.sendSubscriptionEvent', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_event]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + NativeGraphQLSubscriptionResponse event) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_datastore.NativeApiBridge.sendSubscriptionEvent$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([event]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; diff --git a/packages/amplify_datastore/pubspec.yaml b/packages/amplify_datastore/pubspec.yaml index 9664299fd5..725360770d 100644 --- a/packages/amplify_datastore/pubspec.yaml +++ b/packages/amplify_datastore/pubspec.yaml @@ -25,7 +25,7 @@ dev_dependencies: flutter_test: sdk: flutter fake_async: ^1.2.0 - pigeon: ^11.0.0 + pigeon: ^22.6.2 # The following section is specific to Flutter. flutter: diff --git a/packages/amplify_native_legacy_wrapper/android/src/main/kotlin/com/amazonaws/amplify/amplify_native_legacy_wrapper/pigeons/LegacyNativePluginPigeon.kt b/packages/amplify_native_legacy_wrapper/android/src/main/kotlin/com/amazonaws/amplify/amplify_native_legacy_wrapper/pigeons/LegacyNativePluginPigeon.kt index f6035accd1..f4b6a8668f 100644 --- a/packages/amplify_native_legacy_wrapper/android/src/main/kotlin/com/amazonaws/amplify/amplify_native_legacy_wrapper/pigeons/LegacyNativePluginPigeon.kt +++ b/packages/amplify_native_legacy_wrapper/android/src/main/kotlin/com/amazonaws/amplify/amplify_native_legacy_wrapper/pigeons/LegacyNativePluginPigeon.kt @@ -1,8 +1,9 @@ -// +// // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Autogenerated from Pigeon (v11.0.1), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon +@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass") package com.amazonaws.amplify.amplify_native_legacy_wrapper.pigeons @@ -19,14 +20,14 @@ private fun wrapResult(result: Any?): List { } private fun wrapError(exception: Throwable): List { - if (exception is FlutterError) { - return listOf( + return if (exception is FlutterError) { + listOf( exception.code, exception.message, exception.details ) } else { - return listOf( + listOf( exception.javaClass.simpleName, exception.toString(), "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception) @@ -45,6 +46,15 @@ class FlutterError ( override val message: String? = null, val details: Any? = null ) : Throwable() +private open class LegacyNativePluginPigeonPigeonCodec : StandardMessageCodec() { + override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { + return super.readValueOfType(type, buffer) + } + override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { + super.writeValue(stream, value) + } +} + /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ interface LegacyNativePlugin { @@ -56,13 +66,14 @@ interface LegacyNativePlugin { companion object { /** The codec used by LegacyNativePlugin. */ val codec: MessageCodec by lazy { - StandardMessageCodec() + LegacyNativePluginPigeonPigeonCodec() } /** Sets up an instance of `LegacyNativePlugin` to handle messages through the `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") - fun setUp(binaryMessenger: BinaryMessenger, api: LegacyNativePlugin?) { + @JvmOverloads + fun setUp(binaryMessenger: BinaryMessenger, api: LegacyNativePlugin?, messageChannelSuffix: String = "") { + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.configure", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.configure$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List @@ -81,10 +92,10 @@ interface LegacyNativePlugin { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.signOut", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.signOut$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { _, reply -> - api.signOut() { result: Result -> + api.signOut{ result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -98,7 +109,7 @@ interface LegacyNativePlugin { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.signIn", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.signIn$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List @@ -118,10 +129,10 @@ interface LegacyNativePlugin { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.rememberDevice", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.rememberDevice$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { _, reply -> - api.rememberDevice() { result: Result -> + api.rememberDevice{ result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) diff --git a/packages/amplify_native_legacy_wrapper/ios/Classes/Pigeons/AmplifyNativeLegacyPlugin.swift b/packages/amplify_native_legacy_wrapper/ios/Classes/Pigeons/AmplifyNativeLegacyPlugin.swift index dd47b3f22d..8933534d7c 100644 --- a/packages/amplify_native_legacy_wrapper/ios/Classes/Pigeons/AmplifyNativeLegacyPlugin.swift +++ b/packages/amplify_native_legacy_wrapper/ios/Classes/Pigeons/AmplifyNativeLegacyPlugin.swift @@ -1,20 +1,35 @@ -// +// // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Autogenerated from Pigeon (v11.0.1), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation + #if os(iOS) -import Flutter + import Flutter #elseif os(macOS) -import FlutterMacOS + import FlutterMacOS #else -#error("Unsupported platform.") + #error("Unsupported platform.") #endif -private func isNullish(_ value: Any?) -> Bool { - return value is NSNull || value == nil +/// Error class for passing custom error details to Dart side. +final class PigeonError: Error { + let code: String + let message: String? + let details: Any? + + init(code: String, message: String?, details: Any?) { + self.code = code + self.message = message + self.details = details + } + + var localizedDescription: String { + return + "PigeonError(code: \(code), message: \(message ?? ""), details: \(details ?? "")" + } } private func wrapResult(_ result: Any?) -> [Any?] { @@ -22,25 +37,57 @@ private func wrapResult(_ result: Any?) -> [Any?] { } private func wrapError(_ error: Any) -> [Any?] { + if let pigeonError = error as? PigeonError { + return [ + pigeonError.code, + pigeonError.message, + pigeonError.details, + ] + } if let flutterError = error as? FlutterError { return [ flutterError.code, flutterError.message, - flutterError.details + flutterError.details, ] } return [ "\(error)", "\(type(of: error))", - "Stacktrace: \(Thread.callStackSymbols)" + "Stacktrace: \(Thread.callStackSymbols)", ] } +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + private func nilOrValue(_ value: Any?) -> T? { if value is NSNull { return nil } return value as! T? } +private class AmplifyNativeLegacyPluginPigeonCodecReader: FlutterStandardReader { +} + +private class AmplifyNativeLegacyPluginPigeonCodecWriter: FlutterStandardWriter { +} + +private class AmplifyNativeLegacyPluginPigeonCodecReaderWriter: FlutterStandardReaderWriter { + override func reader(with data: Data) -> FlutterStandardReader { + return AmplifyNativeLegacyPluginPigeonCodecReader(data: data) + } + + override func writer(with data: NSMutableData) -> FlutterStandardWriter { + return AmplifyNativeLegacyPluginPigeonCodecWriter(data: data) + } +} + +class AmplifyNativeLegacyPluginPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable { + static let shared = AmplifyNativeLegacyPluginPigeonCodec(readerWriter: AmplifyNativeLegacyPluginPigeonCodecReaderWriter()) +} + + /// Generated protocol from Pigeon that represents a handler of messages from Flutter. protocol LegacyNativePlugin { func configure(config: String, completion: @escaping (Result) -> Void) @@ -51,42 +98,43 @@ protocol LegacyNativePlugin { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class LegacyNativePluginSetup { - /// The codec used by LegacyNativePlugin. + static var codec: FlutterStandardMessageCodec { AmplifyNativeLegacyPluginPigeonCodec.shared } /// Sets up an instance of `LegacyNativePlugin` to handle messages through the `binaryMessenger`. - static func setUp(binaryMessenger: FlutterBinaryMessenger, api: LegacyNativePlugin?) { - let configureChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.configure", binaryMessenger: binaryMessenger) + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: LegacyNativePlugin?, messageChannelSuffix: String = "") { + let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" + let configureChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.configure\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { configureChannel.setMessageHandler { message, reply in let args = message as! [Any?] let configArg = args[0] as! String api.configure(config: configArg) { result in switch result { - case .success: - reply(wrapResult(nil)) - case .failure(let error): - reply(wrapError(error)) + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) } } } } else { configureChannel.setMessageHandler(nil) } - let signOutChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.signOut", binaryMessenger: binaryMessenger) + let signOutChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.signOut\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { signOutChannel.setMessageHandler { _, reply in - api.signOut() { result in + api.signOut { result in switch result { - case .success: - reply(wrapResult(nil)) - case .failure(let error): - reply(wrapError(error)) + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) } } } } else { signOutChannel.setMessageHandler(nil) } - let signInChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.signIn", binaryMessenger: binaryMessenger) + let signInChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.signIn\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { signInChannel.setMessageHandler { message, reply in let args = message as! [Any?] @@ -94,25 +142,25 @@ class LegacyNativePluginSetup { let passwordArg = args[1] as! String api.signIn(username: usernameArg, password: passwordArg) { result in switch result { - case .success: - reply(wrapResult(nil)) - case .failure(let error): - reply(wrapError(error)) + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) } } } } else { signInChannel.setMessageHandler(nil) } - let rememberDeviceChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.rememberDevice", binaryMessenger: binaryMessenger) + let rememberDeviceChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.rememberDevice\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { rememberDeviceChannel.setMessageHandler { _, reply in - api.rememberDevice() { result in + api.rememberDevice { result in switch result { - case .success: - reply(wrapResult(nil)) - case .failure(let error): - reply(wrapError(error)) + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) } } } diff --git a/packages/amplify_native_legacy_wrapper/lib/amplify_native_legacy_plugin.g.dart b/packages/amplify_native_legacy_wrapper/lib/amplify_native_legacy_plugin.g.dart index 06dce1ea3c..4990c442e9 100644 --- a/packages/amplify_native_legacy_wrapper/lib/amplify_native_legacy_plugin.g.dart +++ b/packages/amplify_native_legacy_wrapper/lib/amplify_native_legacy_plugin.g.dart @@ -1,9 +1,9 @@ // // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Autogenerated from Pigeon (v11.0.1), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -11,33 +11,67 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is int) { + buffer.putUint8(4); + buffer.putInt64(value); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + default: + return super.readValueOfType(type, buffer); + } + } +} + class LegacyNativePlugin { /// Constructor for [LegacyNativePlugin]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - LegacyNativePlugin({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + LegacyNativePlugin( + {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) + : pigeonVar_binaryMessenger = binaryMessenger, + pigeonVar_messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final BinaryMessenger? pigeonVar_binaryMessenger; - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); - Future configure(String arg_config) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.configure', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_config]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + final String pigeonVar_messageChannelSuffix; + + Future configure(String config) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.configure$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([config]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; @@ -45,44 +79,47 @@ class LegacyNativePlugin { } Future signOut() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.signOut', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.signOut$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send(null) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future signIn(String arg_username, String arg_password) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.signIn', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_username, arg_password]) as List?; - if (replyList == null) { + Future signIn(String username, String password) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.signIn$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([username, password]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; @@ -90,21 +127,23 @@ class LegacyNativePlugin { } Future rememberDevice() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.rememberDevice', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_native_legacy_wrapper.LegacyNativePlugin.rememberDevice$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send(null) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; diff --git a/packages/amplify_native_legacy_wrapper/lib/amplify_native_legacy_wrapper.dart b/packages/amplify_native_legacy_wrapper/lib/amplify_native_legacy_wrapper.dart index 38bacdd158..253e8d38b9 100644 --- a/packages/amplify_native_legacy_wrapper/lib/amplify_native_legacy_wrapper.dart +++ b/packages/amplify_native_legacy_wrapper/lib/amplify_native_legacy_wrapper.dart @@ -1,7 +1,10 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +// ignore_for_file: non_constant_identifier_names + import 'package:amplify_native_legacy_wrapper/amplify_native_legacy_plugin.g.dart'; +import 'package:flutter/services.dart'; /// A wrapper around the Native v1 Amplify plugins and the legacy SDKs. /// @@ -30,4 +33,10 @@ class AmplifyNativeLegacyWrapper implements LegacyNativePlugin { Future rememberDevice() { return _plugin.rememberDevice(); } + + @override + BinaryMessenger? get pigeonVar_binaryMessenger => _plugin.pigeonVar_binaryMessenger; + + @override + String get pigeonVar_messageChannelSuffix => _plugin.pigeonVar_messageChannelSuffix; } diff --git a/packages/amplify_native_legacy_wrapper/pubspec.yaml b/packages/amplify_native_legacy_wrapper/pubspec.yaml index 1727efaa84..65d7dd62db 100644 --- a/packages/amplify_native_legacy_wrapper/pubspec.yaml +++ b/packages/amplify_native_legacy_wrapper/pubspec.yaml @@ -15,7 +15,7 @@ dev_dependencies: amplify_lints: ">=2.0.2 <2.1.0" flutter_test: sdk: flutter - pigeon: ^11.0.0 + pigeon: ^22.6.2 flutter: plugin: diff --git a/packages/analytics/amplify_analytics_pinpoint/android/src/main/java/com/amazonaws/amplify/amplify_analytics_pinpoint/Messages.java b/packages/analytics/amplify_analytics_pinpoint/android/src/main/java/com/amazonaws/amplify/amplify_analytics_pinpoint/Messages.java index b237532d82..d5123cb027 100644 --- a/packages/analytics/amplify_analytics_pinpoint/android/src/main/java/com/amazonaws/amplify/amplify_analytics_pinpoint/Messages.java +++ b/packages/analytics/amplify_analytics_pinpoint/android/src/main/java/com/amazonaws/amplify/amplify_analytics_pinpoint/Messages.java @@ -1,6 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Autogenerated from Pigeon (v11.0.0), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon package com.amazonaws.amplify.amplify_analytics_pinpoint; @@ -20,6 +20,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; /** Generated class from Pigeon. */ @SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression", "serial"}) @@ -44,7 +45,7 @@ public FlutterError(@NonNull String code, @Nullable String message, @Nullable Ob @NonNull protected static ArrayList wrapError(@NonNull Throwable exception) { - ArrayList errorList = new ArrayList(3); + ArrayList errorList = new ArrayList<>(3); if (exception instanceof FlutterError) { FlutterError error = (FlutterError) exception; errorList.add(error.code); @@ -59,35 +60,79 @@ protected static ArrayList wrapError(@NonNull Throwable exception) { return errorList; } + private static class PigeonCodec extends StandardMessageCodec { + public static final PigeonCodec INSTANCE = new PigeonCodec(); + + private PigeonCodec() {} + + @Override + protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { + switch (type) { + default: + return super.readValueOfType(type, buffer); + } + } + + @Override + protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { + { + super.writeValue(stream, value); + } + } + } + + + /** Asynchronous error handling return type for non-nullable API method returns. */ public interface Result { - @SuppressWarnings("UnknownNullness") - void success(T result); + /** Success case callback method for handling returns. */ + void success(@NonNull T result); + + /** Failure case callback method for handling errors. */ + void error(@NonNull Throwable error); + } + /** Asynchronous error handling return type for nullable API method returns. */ + public interface NullableResult { + /** Success case callback method for handling returns. */ + void success(@Nullable T result); + /** Failure case callback method for handling errors. */ + void error(@NonNull Throwable error); + } + /** Asynchronous error handling return type for void API method returns. */ + public interface VoidResult { + /** Success case callback method for handling returns. */ + void success(); + + /** Failure case callback method for handling errors. */ void error(@NonNull Throwable error); } /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ - public interface PigeonLegacyDataProvider { + public interface PinpointLegacyDataProvider { - void getEndpointId(@NonNull String pinpointAppId, @NonNull Result result); + void getEndpointId(@NonNull String pinpointAppId, @NonNull NullableResult result); - /** The codec used by PigeonLegacyDataProvider. */ + /** The codec used by PinpointLegacyDataProvider. */ static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); + return PigeonCodec.INSTANCE; + } + /**Sets up an instance of `PinpointLegacyDataProvider` to handle messages through the `binaryMessenger`. */ + static void setUp(@NonNull BinaryMessenger binaryMessenger, @Nullable PinpointLegacyDataProvider api) { + setUp(binaryMessenger, "", api); } - /**Sets up an instance of `PigeonLegacyDataProvider` to handle messages through the `binaryMessenger`. */ - static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PigeonLegacyDataProvider api) { + static void setUp(@NonNull BinaryMessenger binaryMessenger, @NonNull String messageChannelSuffix, @Nullable PinpointLegacyDataProvider api) { + messageChannelSuffix = messageChannelSuffix.isEmpty() ? "" : "." + messageChannelSuffix; { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.amplify_analytics_pinpoint.PigeonLegacyDataProvider.getEndpointId", getCodec()); + binaryMessenger, "dev.flutter.pigeon.amplify_analytics_pinpoint.PinpointLegacyDataProvider.getEndpointId" + messageChannelSuffix, getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList(); + ArrayList wrapped = new ArrayList<>(); ArrayList args = (ArrayList) message; String pinpointAppIdArg = (String) args.get(0); - Result resultCallback = - new Result() { + NullableResult resultCallback = + new NullableResult() { public void success(String result) { wrapped.add(0, result); reply.reply(wrapped); diff --git a/packages/analytics/amplify_analytics_pinpoint/android/src/main/kotlin/com/amazonaws/amplify/amplify_analytics_pinpoint/AmplifyAnalyticsPinpointPlugin.kt b/packages/analytics/amplify_analytics_pinpoint/android/src/main/kotlin/com/amazonaws/amplify/amplify_analytics_pinpoint/AmplifyAnalyticsPinpointPlugin.kt index d1068b90c2..8edcab6d05 100644 --- a/packages/analytics/amplify_analytics_pinpoint/android/src/main/kotlin/com/amazonaws/amplify/amplify_analytics_pinpoint/AmplifyAnalyticsPinpointPlugin.kt +++ b/packages/analytics/amplify_analytics_pinpoint/android/src/main/kotlin/com/amazonaws/amplify/amplify_analytics_pinpoint/AmplifyAnalyticsPinpointPlugin.kt @@ -7,7 +7,7 @@ import android.content.Context import android.content.SharedPreferences import io.flutter.embedding.engine.plugins.FlutterPlugin -class AmplifyAnalyticsPinpointPlugin: FlutterPlugin, Messages.PigeonLegacyDataProvider { +class AmplifyAnalyticsPinpointPlugin: FlutterPlugin, Messages.PinpointLegacyDataProvider { private var context: Context? = null private var sharedPrefs: SharedPreferences? = null @@ -19,11 +19,11 @@ class AmplifyAnalyticsPinpointPlugin: FlutterPlugin, Messages.PigeonLegacyDataPr override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) { context = binding.applicationContext - Messages.PigeonLegacyDataProvider.setup(binding.binaryMessenger, this) + Messages.PinpointLegacyDataProvider.setup(binding.binaryMessenger, this) } override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { - Messages.PigeonLegacyDataProvider.setup(binding.binaryMessenger, null) + Messages.PinpointLegacyDataProvider.setup(binding.binaryMessenger, null) context = null } diff --git a/packages/analytics/amplify_analytics_pinpoint/lib/src/legacy_native_data_provider/data_provider.android.dart b/packages/analytics/amplify_analytics_pinpoint/lib/src/legacy_native_data_provider/data_provider.android.dart index 3808dd6201..6c49805036 100644 --- a/packages/analytics/amplify_analytics_pinpoint/lib/src/legacy_native_data_provider/data_provider.android.dart +++ b/packages/analytics/amplify_analytics_pinpoint/lib/src/legacy_native_data_provider/data_provider.android.dart @@ -4,16 +4,15 @@ import 'dart:async'; import 'package:amplify_analytics_pinpoint/src/legacy_native_data_provider/pigeon_legacy_data_provider.android.g.dart'; - // ignore: implementation_imports import 'package:amplify_analytics_pinpoint_dart/src/impl/flutter_provider_interfaces/legacy_native_data_provider.dart'; /// {@macro amplify_analytics_pinpoint.flutter_legacy_native_data_provider} class DataProviderAndroid implements LegacyNativeDataProvider { /// {@macro amplify_analytics_pinpoint.flutter_legacy_native_data_provider} - DataProviderAndroid() : _pigeonDataProvider = PigeonLegacyDataProvider(); + DataProviderAndroid() : _pigeonDataProvider = PinpointLegacyDataProvider(); - final PigeonLegacyDataProvider _pigeonDataProvider; + final PinpointLegacyDataProvider _pigeonDataProvider; @override Future getEndpointId(String pinpointAppId) { diff --git a/packages/analytics/amplify_analytics_pinpoint/lib/src/legacy_native_data_provider/pigeon_legacy_data_provider.android.g.dart b/packages/analytics/amplify_analytics_pinpoint/lib/src/legacy_native_data_provider/pigeon_legacy_data_provider.android.g.dart index 8d0fcb92e3..aa21b12551 100644 --- a/packages/analytics/amplify_analytics_pinpoint/lib/src/legacy_native_data_provider/pigeon_legacy_data_provider.android.g.dart +++ b/packages/analytics/amplify_analytics_pinpoint/lib/src/legacy_native_data_provider/pigeon_legacy_data_provider.android.g.dart @@ -1,8 +1,8 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Autogenerated from Pigeon (v11.0.0), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -10,36 +10,70 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; -class PigeonLegacyDataProvider { - /// Constructor for [PigeonLegacyDataProvider]. The [binaryMessenger] named argument is +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is int) { + buffer.putUint8(4); + buffer.putInt64(value); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + default: + return super.readValueOfType(type, buffer); + } + } +} + +class PinpointLegacyDataProvider { + /// Constructor for [PinpointLegacyDataProvider]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - PigeonLegacyDataProvider({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = StandardMessageCodec(); - - Future getEndpointId(String arg_pinpointAppId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_analytics_pinpoint.PigeonLegacyDataProvider.getEndpointId', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_pinpointAppId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + PinpointLegacyDataProvider( + {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) + : pigeonVar_binaryMessenger = binaryMessenger, + pigeonVar_messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final BinaryMessenger? pigeonVar_binaryMessenger; + + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); + + final String pigeonVar_messageChannelSuffix; + + Future getEndpointId(String pinpointAppId) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_analytics_pinpoint.PinpointLegacyDataProvider.getEndpointId$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pinpointAppId]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { - return (replyList[0] as String?); + return (pigeonVar_replyList[0] as String?); } } } diff --git a/packages/analytics/amplify_analytics_pinpoint/pigeons/pigeon_config_android.dart b/packages/analytics/amplify_analytics_pinpoint/pigeons/pigeon_config_android.dart index 52426d6e6c..48162f217a 100644 --- a/packages/analytics/amplify_analytics_pinpoint/pigeons/pigeon_config_android.dart +++ b/packages/analytics/amplify_analytics_pinpoint/pigeons/pigeon_config_android.dart @@ -19,7 +19,7 @@ import 'package:pigeon/pigeon.dart'; ), ) @HostApi() -abstract class PigeonLegacyDataProvider { +abstract class PinpointLegacyDataProvider { @async String? getEndpointId(String pinpointAppId); } diff --git a/packages/analytics/amplify_analytics_pinpoint/pubspec.yaml b/packages/analytics/amplify_analytics_pinpoint/pubspec.yaml index cfd338508a..2ba1ce2f3c 100644 --- a/packages/analytics/amplify_analytics_pinpoint/pubspec.yaml +++ b/packages/analytics/amplify_analytics_pinpoint/pubspec.yaml @@ -35,7 +35,7 @@ dev_dependencies: amplify_lints: ">=3.1.0 <3.2.0" flutter_test: sdk: flutter - pigeon: ^11.0.0 + pigeon: ^22.6.2 flutter: plugin: diff --git a/packages/auth/amplify_auth_cognito/android/src/main/kotlin/com/amazonaws/amplify/amplify_auth_cognito/pigeons/NativeAuthPluginBindingsPigeon.kt b/packages/auth/amplify_auth_cognito/android/src/main/kotlin/com/amazonaws/amplify/amplify_auth_cognito/pigeons/NativeAuthPluginBindingsPigeon.kt index adb9547218..00be62a8d1 100644 --- a/packages/auth/amplify_auth_cognito/android/src/main/kotlin/com/amazonaws/amplify/amplify_auth_cognito/pigeons/NativeAuthPluginBindingsPigeon.kt +++ b/packages/auth/amplify_auth_cognito/android/src/main/kotlin/com/amazonaws/amplify/amplify_auth_cognito/pigeons/NativeAuthPluginBindingsPigeon.kt @@ -1,8 +1,9 @@ -// +// // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Autogenerated from Pigeon (v11.0.1), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon +@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass") package com.amazonaws.amplify.amplify_auth_cognito @@ -19,14 +20,14 @@ private fun wrapResult(result: Any?): List { } private fun wrapError(exception: Throwable): List { - if (exception is FlutterError) { - return listOf( + return if (exception is FlutterError) { + listOf( exception.code, exception.message, exception.details ) } else { - return listOf( + listOf( exception.javaClass.simpleName, exception.toString(), "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception) @@ -34,6 +35,9 @@ private fun wrapError(exception: Throwable): List { } } +private fun createConnectionError(channelName: String): FlutterError { + return FlutterError("channel-error", "Unable to establish connection on channel: '$channelName'.", "")} + /** * Error class for passing custom error details to Flutter via a thrown PlatformException. * @property code The error code. @@ -57,25 +61,24 @@ data class NativeUserContextData ( val deviceOsReleaseVersion: String? = null, val screenHeightPixels: Long? = null, val screenWidthPixels: Long? = null - -) { +) + { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): NativeUserContextData { - val deviceName = list[0] as String? - val thirdPartyDeviceId = list[1] as String? - val deviceFingerprint = list[2] as String? - val applicationName = list[3] as String? - val applicationVersion = list[4] as String? - val deviceLanguage = list[5] as String? - val deviceOsReleaseVersion = list[6] as String? - val screenHeightPixels = list[7].let { if (it is Int) it.toLong() else it as Long? } - val screenWidthPixels = list[8].let { if (it is Int) it.toLong() else it as Long? } + fun fromList(pigeonVar_list: List): NativeUserContextData { + val deviceName = pigeonVar_list[0] as String? + val thirdPartyDeviceId = pigeonVar_list[1] as String? + val deviceFingerprint = pigeonVar_list[2] as String? + val applicationName = pigeonVar_list[3] as String? + val applicationVersion = pigeonVar_list[4] as String? + val deviceLanguage = pigeonVar_list[5] as String? + val deviceOsReleaseVersion = pigeonVar_list[6] as String? + val screenHeightPixels = pigeonVar_list[7] as Long? + val screenWidthPixels = pigeonVar_list[8] as Long? return NativeUserContextData(deviceName, thirdPartyDeviceId, deviceFingerprint, applicationName, applicationVersion, deviceLanguage, deviceOsReleaseVersion, screenHeightPixels, screenWidthPixels) } } fun toList(): List { - return listOf( + return listOf( deviceName, thirdPartyDeviceId, deviceFingerprint, @@ -99,24 +102,23 @@ data class LegacyCredentialStoreData ( val accessToken: String? = null, val refreshToken: String? = null, val idToken: String? = null - -) { +) + { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): LegacyCredentialStoreData { - val identityId = list[0] as String? - val accessKeyId = list[1] as String? - val secretAccessKey = list[2] as String? - val sessionToken = list[3] as String? - val expirationMsSinceEpoch = list[4].let { if (it is Int) it.toLong() else it as Long? } - val accessToken = list[5] as String? - val refreshToken = list[6] as String? - val idToken = list[7] as String? + fun fromList(pigeonVar_list: List): LegacyCredentialStoreData { + val identityId = pigeonVar_list[0] as String? + val accessKeyId = pigeonVar_list[1] as String? + val secretAccessKey = pigeonVar_list[2] as String? + val sessionToken = pigeonVar_list[3] as String? + val expirationMsSinceEpoch = pigeonVar_list[4] as Long? + val accessToken = pigeonVar_list[5] as String? + val refreshToken = pigeonVar_list[6] as String? + val idToken = pigeonVar_list[7] as String? return LegacyCredentialStoreData(identityId, accessKeyId, secretAccessKey, sessionToken, expirationMsSinceEpoch, accessToken, refreshToken, idToken) } } fun toList(): List { - return listOf( + return listOf( identityId, accessKeyId, secretAccessKey, @@ -135,20 +137,19 @@ data class LegacyDeviceDetailsSecret ( val deviceGroupKey: String? = null, val devicePassword: String? = null, val asfDeviceId: String? = null - -) { +) + { companion object { - @Suppress("UNCHECKED_CAST") - fun fromList(list: List): LegacyDeviceDetailsSecret { - val deviceKey = list[0] as String? - val deviceGroupKey = list[1] as String? - val devicePassword = list[2] as String? - val asfDeviceId = list[3] as String? + fun fromList(pigeonVar_list: List): LegacyDeviceDetailsSecret { + val deviceKey = pigeonVar_list[0] as String? + val deviceGroupKey = pigeonVar_list[1] as String? + val devicePassword = pigeonVar_list[2] as String? + val asfDeviceId = pigeonVar_list[3] as String? return LegacyDeviceDetailsSecret(deviceKey, deviceGroupKey, devicePassword, asfDeviceId) } } fun toList(): List { - return listOf( + return listOf( deviceKey, deviceGroupKey, devicePassword, @@ -156,45 +157,22 @@ data class LegacyDeviceDetailsSecret ( ) } } - -/** Generated class from Pigeon that represents Flutter messages that can be called from Kotlin. */ -@Suppress("UNCHECKED_CAST") -class NativeAuthPlugin(private val binaryMessenger: BinaryMessenger) { - companion object { - /** The codec used by NativeAuthPlugin. */ - val codec: MessageCodec by lazy { - StandardMessageCodec() - } - } - /** - * Exchanges the route parameters used to launch the app, i.e. if the app - * was closed and a redirect happened to the custom URI scheme (iOS) or an - * intent was launched with the redirect parameters (Android). - */ - fun exchange(paramsArg: Map, callback: () -> Unit) { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthPlugin.exchange", codec) - channel.send(listOf(paramsArg)) { - callback() - } - } -} -@Suppress("UNCHECKED_CAST") -private object NativeAuthBridgeCodec : StandardMessageCodec() { +private open class NativeAuthPluginBindingsPigeonPigeonCodec : StandardMessageCodec() { override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { return when (type) { - 128.toByte() -> { + 129.toByte() -> { return (readValue(buffer) as? List)?.let { - LegacyCredentialStoreData.fromList(it) + NativeUserContextData.fromList(it) } } - 129.toByte() -> { + 130.toByte() -> { return (readValue(buffer) as? List)?.let { - LegacyDeviceDetailsSecret.fromList(it) + LegacyCredentialStoreData.fromList(it) } } - 130.toByte() -> { + 131.toByte() -> { return (readValue(buffer) as? List)?.let { - NativeUserContextData.fromList(it) + LegacyDeviceDetailsSecret.fromList(it) } } else -> super.readValueOfType(type, buffer) @@ -202,23 +180,55 @@ private object NativeAuthBridgeCodec : StandardMessageCodec() { } override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { when (value) { - is LegacyCredentialStoreData -> { - stream.write(128) - writeValue(stream, value.toList()) - } - is LegacyDeviceDetailsSecret -> { + is NativeUserContextData -> { stream.write(129) writeValue(stream, value.toList()) } - is NativeUserContextData -> { + is LegacyCredentialStoreData -> { stream.write(130) writeValue(stream, value.toList()) } + is LegacyDeviceDetailsSecret -> { + stream.write(131) + writeValue(stream, value.toList()) + } else -> super.writeValue(stream, value) } } } + +/** Generated class from Pigeon that represents Flutter messages that can be called from Kotlin. */ +class NativeAuthPlugin(private val binaryMessenger: BinaryMessenger, private val messageChannelSuffix: String = "") { + companion object { + /** The codec used by NativeAuthPlugin. */ + val codec: MessageCodec by lazy { + NativeAuthPluginBindingsPigeonPigeonCodec() + } + } + /** + * Exchanges the route parameters used to launch the app, i.e. if the app + * was closed and a redirect happened to the custom URI scheme (iOS) or an + * intent was launched with the redirect parameters (Android). + */ + fun exchange(paramsArg: Map, callback: (Result) -> Unit) +{ + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" + val channelName = "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthPlugin.exchange$separatedMessageChannelSuffix" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(paramsArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ interface NativeAuthBridge { /** @@ -250,13 +260,14 @@ interface NativeAuthBridge { companion object { /** The codec used by NativeAuthBridge. */ val codec: MessageCodec by lazy { - NativeAuthBridgeCodec + NativeAuthPluginBindingsPigeonPigeonCodec() } /** Sets up an instance of `NativeAuthBridge` to handle messages through the `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") - fun setUp(binaryMessenger: BinaryMessenger, api: NativeAuthBridge?) { + @JvmOverloads + fun setUp(binaryMessenger: BinaryMessenger, api: NativeAuthBridge?, messageChannelSuffix: String = "") { + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.signInWithUrl", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.signInWithUrl$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List @@ -279,7 +290,7 @@ interface NativeAuthBridge { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.signOutWithUrl", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.signOutWithUrl$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List @@ -301,14 +312,13 @@ interface NativeAuthBridge { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getValidationData", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getValidationData$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { - wrapped = listOf(api.getValidationData()) + val wrapped: List = try { + listOf(api.getValidationData()) } catch (exception: Throwable) { - wrapped = wrapError(exception) + wrapError(exception) } reply.reply(wrapped) } @@ -317,14 +327,13 @@ interface NativeAuthBridge { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getContextData", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getContextData$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { - wrapped = listOf(api.getContextData()) + val wrapped: List = try { + listOf(api.getContextData()) } catch (exception: Throwable) { - wrapped = wrapError(exception) + wrapError(exception) } reply.reply(wrapped) } @@ -333,14 +342,13 @@ interface NativeAuthBridge { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getBundleId", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getBundleId$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { _, reply -> - var wrapped: List - try { - wrapped = listOf(api.getBundleId()) + val wrapped: List = try { + listOf(api.getBundleId()) } catch (exception: Throwable) { - wrapped = wrapError(exception) + wrapError(exception) } reply.reply(wrapped) } @@ -349,7 +357,7 @@ interface NativeAuthBridge { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getLegacyCredentials", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getLegacyCredentials$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List @@ -370,10 +378,10 @@ interface NativeAuthBridge { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.clearLegacyCredentials", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.clearLegacyCredentials$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { _, reply -> - api.clearLegacyCredentials() { result: Result -> + api.clearLegacyCredentials{ result: Result -> val error = result.exceptionOrNull() if (error != null) { reply.reply(wrapError(error)) @@ -387,7 +395,7 @@ interface NativeAuthBridge { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.fetchLegacyDeviceSecrets", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.fetchLegacyDeviceSecrets$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List @@ -408,7 +416,7 @@ interface NativeAuthBridge { } } run { - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.deleteLegacyDeviceSecrets", codec) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.deleteLegacyDeviceSecrets$separatedMessageChannelSuffix", codec) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List diff --git a/packages/auth/amplify_auth_cognito/darwin/Classes/pigeons/messages.g.swift b/packages/auth/amplify_auth_cognito/darwin/Classes/pigeons/messages.g.swift index a029d4fe45..5ad64a8343 100644 --- a/packages/auth/amplify_auth_cognito/darwin/Classes/pigeons/messages.g.swift +++ b/packages/auth/amplify_auth_cognito/darwin/Classes/pigeons/messages.g.swift @@ -1,20 +1,35 @@ -// +// // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Autogenerated from Pigeon (v11.0.1), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation + #if os(iOS) -import Flutter + import Flutter #elseif os(macOS) -import FlutterMacOS + import FlutterMacOS #else -#error("Unsupported platform.") + #error("Unsupported platform.") #endif -private func isNullish(_ value: Any?) -> Bool { - return value is NSNull || value == nil +/// Error class for passing custom error details to Dart side. +final class PigeonError: Error { + let code: String + let message: String? + let details: Any? + + init(code: String, message: String?, details: Any?) { + self.code = code + self.message = message + self.details = details + } + + var localizedDescription: String { + return + "PigeonError(code: \(code), message: \(message ?? ""), details: \(details ?? "")" + } } private func wrapResult(_ result: Any?) -> [Any?] { @@ -22,20 +37,35 @@ private func wrapResult(_ result: Any?) -> [Any?] { } private func wrapError(_ error: Any) -> [Any?] { + if let pigeonError = error as? PigeonError { + return [ + pigeonError.code, + pigeonError.message, + pigeonError.details, + ] + } if let flutterError = error as? FlutterError { return [ flutterError.code, flutterError.message, - flutterError.details + flutterError.details, ] } return [ "\(error)", "\(type(of: error))", - "Stacktrace: \(Thread.callStackSymbols)" + "Stacktrace: \(Thread.callStackSymbols)", ] } +private func createConnectionError(withChannelName channelName: String) -> PigeonError { + return PigeonError(code: "channel-error", message: "Unable to establish connection on channel: '\(channelName)'.", details: "") +} + +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + private func nilOrValue(_ value: Any?) -> T? { if value is NSNull { return nil } return value as! T? @@ -53,16 +83,19 @@ struct NativeUserContextData { var screenHeightPixels: Int64? = nil var screenWidthPixels: Int64? = nil - static func fromList(_ list: [Any?]) -> NativeUserContextData? { - let deviceName: String? = nilOrValue(list[0]) - let thirdPartyDeviceId: String? = nilOrValue(list[1]) - let deviceFingerprint: String? = nilOrValue(list[2]) - let applicationName: String? = nilOrValue(list[3]) - let applicationVersion: String? = nilOrValue(list[4]) - let deviceLanguage: String? = nilOrValue(list[5]) - let deviceOsReleaseVersion: String? = nilOrValue(list[6]) - let screenHeightPixels: Int64? = isNullish(list[7]) ? nil : (list[7] is Int64? ? list[7] as! Int64? : Int64(list[7] as! Int32)) - let screenWidthPixels: Int64? = isNullish(list[8]) ? nil : (list[8] is Int64? ? list[8] as! Int64? : Int64(list[8] as! Int32)) + + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> NativeUserContextData? { + let deviceName: String? = nilOrValue(pigeonVar_list[0]) + let thirdPartyDeviceId: String? = nilOrValue(pigeonVar_list[1]) + let deviceFingerprint: String? = nilOrValue(pigeonVar_list[2]) + let applicationName: String? = nilOrValue(pigeonVar_list[3]) + let applicationVersion: String? = nilOrValue(pigeonVar_list[4]) + let deviceLanguage: String? = nilOrValue(pigeonVar_list[5]) + let deviceOsReleaseVersion: String? = nilOrValue(pigeonVar_list[6]) + let screenHeightPixels: Int64? = nilOrValue(pigeonVar_list[7]) + let screenWidthPixels: Int64? = nilOrValue(pigeonVar_list[8]) return NativeUserContextData( deviceName: deviceName, @@ -102,15 +135,18 @@ struct LegacyCredentialStoreData { var refreshToken: String? = nil var idToken: String? = nil - static func fromList(_ list: [Any?]) -> LegacyCredentialStoreData? { - let identityId: String? = nilOrValue(list[0]) - let accessKeyId: String? = nilOrValue(list[1]) - let secretAccessKey: String? = nilOrValue(list[2]) - let sessionToken: String? = nilOrValue(list[3]) - let expirationMsSinceEpoch: Int64? = isNullish(list[4]) ? nil : (list[4] is Int64? ? list[4] as! Int64? : Int64(list[4] as! Int32)) - let accessToken: String? = nilOrValue(list[5]) - let refreshToken: String? = nilOrValue(list[6]) - let idToken: String? = nilOrValue(list[7]) + + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> LegacyCredentialStoreData? { + let identityId: String? = nilOrValue(pigeonVar_list[0]) + let accessKeyId: String? = nilOrValue(pigeonVar_list[1]) + let secretAccessKey: String? = nilOrValue(pigeonVar_list[2]) + let sessionToken: String? = nilOrValue(pigeonVar_list[3]) + let expirationMsSinceEpoch: Int64? = nilOrValue(pigeonVar_list[4]) + let accessToken: String? = nilOrValue(pigeonVar_list[5]) + let refreshToken: String? = nilOrValue(pigeonVar_list[6]) + let idToken: String? = nilOrValue(pigeonVar_list[7]) return LegacyCredentialStoreData( identityId: identityId, @@ -144,11 +180,14 @@ struct LegacyDeviceDetailsSecret { var devicePassword: String? = nil var asfDeviceId: String? = nil - static func fromList(_ list: [Any?]) -> LegacyDeviceDetailsSecret? { - let deviceKey: String? = nilOrValue(list[0]) - let deviceGroupKey: String? = nilOrValue(list[1]) - let devicePassword: String? = nilOrValue(list[2]) - let asfDeviceId: String? = nilOrValue(list[3]) + + + // swift-format-ignore: AlwaysUseLowerCamelCase + static func fromList(_ pigeonVar_list: [Any?]) -> LegacyDeviceDetailsSecret? { + let deviceKey: String? = nilOrValue(pigeonVar_list[0]) + let deviceGroupKey: String? = nilOrValue(pigeonVar_list[1]) + let devicePassword: String? = nilOrValue(pigeonVar_list[2]) + let asfDeviceId: String? = nilOrValue(pigeonVar_list[3]) return LegacyDeviceDetailsSecret( deviceKey: deviceKey, @@ -167,68 +206,92 @@ struct LegacyDeviceDetailsSecret { } } -/// Generated class from Pigeon that represents Flutter messages that can be called from Swift. -class NativeAuthPlugin { - private let binaryMessenger: FlutterBinaryMessenger - init(binaryMessenger: FlutterBinaryMessenger){ - self.binaryMessenger = binaryMessenger - } - /// Exchanges the route parameters used to launch the app, i.e. if the app - /// was closed and a redirect happened to the custom URI scheme (iOS) or an - /// intent was launched with the redirect parameters (Android). - func exchange(params paramsArg: [String: String], completion: @escaping () -> Void) { - let channel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthPlugin.exchange", binaryMessenger: binaryMessenger) - channel.sendMessage([paramsArg] as [Any?]) { _ in - completion() - } - } -} -private class NativeAuthBridgeCodecReader: FlutterStandardReader { +private class messagesPigeonCodecReader: FlutterStandardReader { override func readValue(ofType type: UInt8) -> Any? { switch type { - case 128: - return LegacyCredentialStoreData.fromList(self.readValue() as! [Any?]) - case 129: - return LegacyDeviceDetailsSecret.fromList(self.readValue() as! [Any?]) - case 130: - return NativeUserContextData.fromList(self.readValue() as! [Any?]) - default: - return super.readValue(ofType: type) + case 129: + return NativeUserContextData.fromList(self.readValue() as! [Any?]) + case 130: + return LegacyCredentialStoreData.fromList(self.readValue() as! [Any?]) + case 131: + return LegacyDeviceDetailsSecret.fromList(self.readValue() as! [Any?]) + default: + return super.readValue(ofType: type) } } } -private class NativeAuthBridgeCodecWriter: FlutterStandardWriter { +private class messagesPigeonCodecWriter: FlutterStandardWriter { override func writeValue(_ value: Any) { - if let value = value as? LegacyCredentialStoreData { - super.writeByte(128) - super.writeValue(value.toList()) - } else if let value = value as? LegacyDeviceDetailsSecret { + if let value = value as? NativeUserContextData { super.writeByte(129) super.writeValue(value.toList()) - } else if let value = value as? NativeUserContextData { + } else if let value = value as? LegacyCredentialStoreData { super.writeByte(130) super.writeValue(value.toList()) + } else if let value = value as? LegacyDeviceDetailsSecret { + super.writeByte(131) + super.writeValue(value.toList()) } else { super.writeValue(value) } } } -private class NativeAuthBridgeCodecReaderWriter: FlutterStandardReaderWriter { +private class messagesPigeonCodecReaderWriter: FlutterStandardReaderWriter { override func reader(with data: Data) -> FlutterStandardReader { - return NativeAuthBridgeCodecReader(data: data) + return messagesPigeonCodecReader(data: data) } override func writer(with data: NSMutableData) -> FlutterStandardWriter { - return NativeAuthBridgeCodecWriter(data: data) + return messagesPigeonCodecWriter(data: data) } } -class NativeAuthBridgeCodec: FlutterStandardMessageCodec { - static let shared = NativeAuthBridgeCodec(readerWriter: NativeAuthBridgeCodecReaderWriter()) +class messagesPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable { + static let shared = messagesPigeonCodec(readerWriter: messagesPigeonCodecReaderWriter()) } + +/// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift. +protocol NativeAuthPluginProtocol { + /// Exchanges the route parameters used to launch the app, i.e. if the app + /// was closed and a redirect happened to the custom URI scheme (iOS) or an + /// intent was launched with the redirect parameters (Android). + func exchange(params paramsArg: [String: String], completion: @escaping (Result) -> Void) +} +class NativeAuthPlugin: NativeAuthPluginProtocol { + private let binaryMessenger: FlutterBinaryMessenger + private let messageChannelSuffix: String + init(binaryMessenger: FlutterBinaryMessenger, messageChannelSuffix: String = "") { + self.binaryMessenger = binaryMessenger + self.messageChannelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" + } + var codec: messagesPigeonCodec { + return messagesPigeonCodec.shared + } + /// Exchanges the route parameters used to launch the app, i.e. if the app + /// was closed and a redirect happened to the custom URI scheme (iOS) or an + /// intent was launched with the redirect parameters (Android). + func exchange(params paramsArg: [String: String], completion: @escaping (Result) -> Void) { + let channelName: String = "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthPlugin.exchange\(messageChannelSuffix)" + let channel = FlutterBasicMessageChannel(name: channelName, binaryMessenger: binaryMessenger, codec: codec) + channel.sendMessage([paramsArg] as [Any?]) { response in + guard let listResponse = response as? [Any?] else { + completion(.failure(createConnectionError(withChannelName: channelName))) + return + } + if listResponse.count > 1 { + let code: String = listResponse[0] as! String + let message: String? = nilOrValue(listResponse[1]) + let details: String? = nilOrValue(listResponse[2]) + completion(.failure(PigeonError(code: code, message: message, details: details))) + } else { + completion(.success(Void())) + } + } + } +} /// Generated protocol from Pigeon that represents a handler of messages from Flutter. protocol NativeAuthBridge { /// Sign in by presenting [url] and waiting for a response to a URL with @@ -256,15 +319,15 @@ protocol NativeAuthBridge { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class NativeAuthBridgeSetup { - /// The codec used by NativeAuthBridge. - static var codec: FlutterStandardMessageCodec { NativeAuthBridgeCodec.shared } + static var codec: FlutterStandardMessageCodec { messagesPigeonCodec.shared } /// Sets up an instance of `NativeAuthBridge` to handle messages through the `binaryMessenger`. - static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NativeAuthBridge?) { + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NativeAuthBridge?, messageChannelSuffix: String = "") { + let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" /// Sign in by presenting [url] and waiting for a response to a URL with /// [callbackUrlScheme]. /// /// If [preferPrivateSession] is `true`, do not persist session cookies. - let signInWithUrlChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.signInWithUrl", binaryMessenger: binaryMessenger, codec: codec) + let signInWithUrlChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.signInWithUrl\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { signInWithUrlChannel.setMessageHandler { message, reply in let args = message as! [Any?] @@ -274,10 +337,10 @@ class NativeAuthBridgeSetup { let browserPackageNameArg: String? = nilOrValue(args[3]) api.signInWithUrl(url: urlArg, callbackUrlScheme: callbackUrlSchemeArg, preferPrivateSession: preferPrivateSessionArg, browserPackageName: browserPackageNameArg) { result in switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) } } } @@ -286,7 +349,7 @@ class NativeAuthBridgeSetup { } /// Sign out by presenting [url] and waiting for a response to a URL with /// [callbackUrlScheme]. - let signOutWithUrlChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.signOutWithUrl", binaryMessenger: binaryMessenger, codec: codec) + let signOutWithUrlChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.signOutWithUrl\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { signOutWithUrlChannel.setMessageHandler { message, reply in let args = message as! [Any?] @@ -296,10 +359,10 @@ class NativeAuthBridgeSetup { let browserPackageNameArg: String? = nilOrValue(args[3]) api.signOutWithUrl(url: urlArg, callbackUrlScheme: callbackUrlSchemeArg, preferPrivateSession: preferPrivateSessionArg, browserPackageName: browserPackageNameArg) { result in switch result { - case .success: - reply(wrapResult(nil)) - case .failure(let error): - reply(wrapError(error)) + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) } } } @@ -307,7 +370,7 @@ class NativeAuthBridgeSetup { signOutWithUrlChannel.setMessageHandler(nil) } /// Retrieves the validation data for the current iOS/Android device. - let getValidationDataChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getValidationData", binaryMessenger: binaryMessenger, codec: codec) + let getValidationDataChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getValidationData\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { getValidationDataChannel.setMessageHandler { _, reply in do { @@ -321,7 +384,7 @@ class NativeAuthBridgeSetup { getValidationDataChannel.setMessageHandler(nil) } /// Retrieves context data as required for advanced security features (ASF). - let getContextDataChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getContextData", binaryMessenger: binaryMessenger, codec: codec) + let getContextDataChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getContextData\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { getContextDataChannel.setMessageHandler { _, reply in do { @@ -334,7 +397,7 @@ class NativeAuthBridgeSetup { } else { getContextDataChannel.setMessageHandler(nil) } - let getBundleIdChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getBundleId", binaryMessenger: binaryMessenger, codec: codec) + let getBundleIdChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getBundleId\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { getBundleIdChannel.setMessageHandler { _, reply in do { @@ -348,7 +411,7 @@ class NativeAuthBridgeSetup { getBundleIdChannel.setMessageHandler(nil) } /// Fetch legacy credentials stored by native SDKs. - let getLegacyCredentialsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getLegacyCredentials", binaryMessenger: binaryMessenger, codec: codec) + let getLegacyCredentialsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getLegacyCredentials\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { getLegacyCredentialsChannel.setMessageHandler { message, reply in let args = message as! [Any?] @@ -356,10 +419,10 @@ class NativeAuthBridgeSetup { let appClientIdArg: String? = nilOrValue(args[1]) api.getLegacyCredentials(identityPoolId: identityPoolIdArg, appClientId: appClientIdArg) { result in switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) } } } @@ -367,15 +430,15 @@ class NativeAuthBridgeSetup { getLegacyCredentialsChannel.setMessageHandler(nil) } /// Clears the legacy credential store data. - let clearLegacyCredentialsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.clearLegacyCredentials", binaryMessenger: binaryMessenger, codec: codec) + let clearLegacyCredentialsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.clearLegacyCredentials\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { clearLegacyCredentialsChannel.setMessageHandler { _, reply in - api.clearLegacyCredentials() { result in + api.clearLegacyCredentials { result in switch result { - case .success: - reply(wrapResult(nil)) - case .failure(let error): - reply(wrapError(error)) + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) } } } @@ -383,7 +446,7 @@ class NativeAuthBridgeSetup { clearLegacyCredentialsChannel.setMessageHandler(nil) } /// Fetch legacy device secrets stored by native SDKs. - let fetchLegacyDeviceSecretsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.fetchLegacyDeviceSecrets", binaryMessenger: binaryMessenger, codec: codec) + let fetchLegacyDeviceSecretsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.fetchLegacyDeviceSecrets\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { fetchLegacyDeviceSecretsChannel.setMessageHandler { message, reply in let args = message as! [Any?] @@ -391,10 +454,10 @@ class NativeAuthBridgeSetup { let userPoolIdArg = args[1] as! String api.fetchLegacyDeviceSecrets(username: usernameArg, userPoolId: userPoolIdArg) { result in switch result { - case .success(let res): - reply(wrapResult(res)) - case .failure(let error): - reply(wrapError(error)) + case .success(let res): + reply(wrapResult(res)) + case .failure(let error): + reply(wrapError(error)) } } } @@ -402,7 +465,7 @@ class NativeAuthBridgeSetup { fetchLegacyDeviceSecretsChannel.setMessageHandler(nil) } /// Clears the legacy device secrets. - let deleteLegacyDeviceSecretsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.deleteLegacyDeviceSecrets", binaryMessenger: binaryMessenger, codec: codec) + let deleteLegacyDeviceSecretsChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.deleteLegacyDeviceSecrets\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { deleteLegacyDeviceSecretsChannel.setMessageHandler { message, reply in let args = message as! [Any?] @@ -410,10 +473,10 @@ class NativeAuthBridgeSetup { let userPoolIdArg = args[1] as! String api.deleteLegacyDeviceSecrets(username: usernameArg, userPoolId: userPoolIdArg) { result in switch result { - case .success: - reply(wrapResult(nil)) - case .failure(let error): - reply(wrapError(error)) + case .success: + reply(wrapResult(nil)) + case .failure(let error): + reply(wrapError(error)) } } } diff --git a/packages/auth/amplify_auth_cognito/example/integration_test/native_auth_bridge_test.dart b/packages/auth/amplify_auth_cognito/example/integration_test/native_auth_bridge_test.dart index 7ff9a0ca6c..5bee21a3e3 100644 --- a/packages/auth/amplify_auth_cognito/example/integration_test/native_auth_bridge_test.dart +++ b/packages/auth/amplify_auth_cognito/example/integration_test/native_auth_bridge_test.dart @@ -114,16 +114,16 @@ typedef SignInOutFn = Future Function( class MockNativeAuthBridge extends Fake implements NativeAuthBridge { MockNativeAuthBridge({ - SignInOutFn>? signInWithUrl, + SignInOutFn>? signInWithUrl, SignInOutFn? signOutWithUrl, }) : _signInWithUrl = signInWithUrl, _signOutWithUrl = signOutWithUrl; - final SignInOutFn>? _signInWithUrl; + final SignInOutFn>? _signInWithUrl; final SignInOutFn? _signOutWithUrl; @override - Future> signInWithUrl( + Future> signInWithUrl( String argUrl, String argCallbackurlscheme, bool argPreferprivatesession, diff --git a/packages/auth/amplify_auth_cognito/example/macos/Flutter/GeneratedPluginRegistrant.swift b/packages/auth/amplify_auth_cognito/example/macos/Flutter/GeneratedPluginRegistrant.swift index 0845788d3d..723ec8543e 100644 --- a/packages/auth/amplify_auth_cognito/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/packages/auth/amplify_auth_cognito/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -12,7 +12,6 @@ import device_info_plus import package_info_plus import path_provider_foundation import url_launcher_macos -import webview_flutter_wkwebview func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { AmplifyAuthCognitoPlugin.register(with: registry.registrar(forPlugin: "AmplifyAuthCognitoPlugin")) @@ -22,5 +21,4 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) - FLTWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "FLTWebViewFlutterPlugin")) } diff --git a/packages/auth/amplify_auth_cognito/lib/src/auth_plugin_impl.dart b/packages/auth/amplify_auth_cognito/lib/src/auth_plugin_impl.dart index 7b9889f309..15cb606344 100644 --- a/packages/auth/amplify_auth_cognito/lib/src/auth_plugin_impl.dart +++ b/packages/auth/amplify_auth_cognito/lib/src/auth_plugin_impl.dart @@ -60,7 +60,7 @@ class AmplifyAuthCognito extends AmplifyAuthCognitoDart with AWSDebuggable { // Configure this plugin to act as a native iOS/Android plugin. final nativePlugin = _NativeAmplifyAuthCognito(stateMachine); - NativeAuthPlugin.setup(nativePlugin); + NativeAuthPlugin.setUp(nativePlugin); final nativeBridge = NativeAuthBridge(); stateMachine diff --git a/packages/auth/amplify_auth_cognito/lib/src/native_auth_plugin.g.dart b/packages/auth/amplify_auth_cognito/lib/src/native_auth_plugin.g.dart index 0cde16746c..9cd7791034 100644 --- a/packages/auth/amplify_auth_cognito/lib/src/native_auth_plugin.g.dart +++ b/packages/auth/amplify_auth_cognito/lib/src/native_auth_plugin.g.dart @@ -1,9 +1,9 @@ // // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Autogenerated from Pigeon (v11.0.1), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -11,6 +11,24 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + +List wrapResponse( + {Object? result, PlatformException? error, bool empty = false}) { + if (empty) { + return []; + } + if (error == null) { + return [result]; + } + return [error.code, error.message, error.details]; +} + class NativeUserContextData { NativeUserContextData({ this.deviceName, @@ -164,52 +182,22 @@ class LegacyDeviceDetailsSecret { } } -abstract class NativeAuthPlugin { - static const MessageCodec codec = StandardMessageCodec(); - - /// Exchanges the route parameters used to launch the app, i.e. if the app - /// was closed and a redirect happened to the custom URI scheme (iOS) or an - /// intent was launched with the redirect parameters (Android). - void exchange(Map params); - - static void setup(NativeAuthPlugin? api, {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthPlugin.exchange', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.amplify_auth_cognito.NativeAuthPlugin.exchange was null.'); - final List args = (message as List?)!; - final Map? arg_params = - (args[0] as Map?)?.cast(); - assert(arg_params != null, - 'Argument for dev.flutter.pigeon.amplify_auth_cognito.NativeAuthPlugin.exchange was null, expected non-null Map.'); - api.exchange(arg_params!); - return; - }); - } - } - } -} - -class _NativeAuthBridgeCodec extends StandardMessageCodec { - const _NativeAuthBridgeCodec(); +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is LegacyCredentialStoreData) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is LegacyDeviceDetailsSecret) { + if (value is int) { + buffer.putUint8(4); + buffer.putInt64(value); + } else if (value is NativeUserContextData) { buffer.putUint8(129); writeValue(buffer, value.encode()); - } else if (value is NativeUserContextData) { + } else if (value is LegacyCredentialStoreData) { buffer.putUint8(130); writeValue(buffer, value.encode()); + } else if (value is LegacyDeviceDetailsSecret) { + buffer.putUint8(131); + writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); } @@ -218,92 +206,150 @@ class _NativeAuthBridgeCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: - return LegacyCredentialStoreData.decode(readValue(buffer)!); case 129: - return LegacyDeviceDetailsSecret.decode(readValue(buffer)!); - case 130: return NativeUserContextData.decode(readValue(buffer)!); + case 130: + return LegacyCredentialStoreData.decode(readValue(buffer)!); + case 131: + return LegacyDeviceDetailsSecret.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); } } } +abstract class NativeAuthPlugin { + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); + + /// Exchanges the route parameters used to launch the app, i.e. if the app + /// was closed and a redirect happened to the custom URI scheme (iOS) or an + /// intent was launched with the redirect parameters (Android). + void exchange(Map params); + + static void setUp( + NativeAuthPlugin? api, { + BinaryMessenger? binaryMessenger, + String messageChannelSuffix = '', + }) { + messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthPlugin.exchange$messageChannelSuffix', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (api == null) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.amplify_auth_cognito.NativeAuthPlugin.exchange was null.'); + final List args = (message as List?)!; + final Map? arg_params = + (args[0] as Map?)?.cast(); + assert(arg_params != null, + 'Argument for dev.flutter.pigeon.amplify_auth_cognito.NativeAuthPlugin.exchange was null, expected non-null Map.'); + try { + api.exchange(arg_params!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } +} + class NativeAuthBridge { /// Constructor for [NativeAuthBridge]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - NativeAuthBridge({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + NativeAuthBridge( + {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) + : pigeonVar_binaryMessenger = binaryMessenger, + pigeonVar_messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final BinaryMessenger? pigeonVar_binaryMessenger; - static const MessageCodec codec = _NativeAuthBridgeCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); + + final String pigeonVar_messageChannelSuffix; /// Sign in by presenting [url] and waiting for a response to a URL with /// [callbackUrlScheme]. /// /// If [preferPrivateSession] is `true`, do not persist session cookies. - Future> signInWithUrl( - String arg_url, - String arg_callbackUrlScheme, - bool arg_preferPrivateSession, - String? arg_browserPackageName) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.signInWithUrl', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send([ - arg_url, - arg_callbackUrlScheme, - arg_preferPrivateSession, - arg_browserPackageName + Future> signInWithUrl( + String url, + String callbackUrlScheme, + bool preferPrivateSession, + String? browserPackageName) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.signInWithUrl$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([ + url, + callbackUrlScheme, + preferPrivateSession, + browserPackageName ]) as List?; - if (replyList == null) { + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else if (replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as Map?)!.cast(); + return (pigeonVar_replyList[0] as Map?)! + .cast(); } } /// Sign out by presenting [url] and waiting for a response to a URL with /// [callbackUrlScheme]. - Future signOutWithUrl(String arg_url, String arg_callbackUrlScheme, - bool arg_preferPrivateSession, String? arg_browserPackageName) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.signOutWithUrl', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send([ - arg_url, - arg_callbackUrlScheme, - arg_preferPrivateSession, - arg_browserPackageName + Future signOutWithUrl(String url, String callbackUrlScheme, + bool preferPrivateSession, String? browserPackageName) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.signOutWithUrl$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([ + url, + callbackUrlScheme, + preferPrivateSession, + browserPackageName ]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; @@ -311,135 +357,145 @@ class NativeAuthBridge { } /// Retrieves the validation data for the current iOS/Android device. - Future> getValidationData() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getValidationData', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + Future> getValidationData() async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getValidationData$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send(null) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as Map?)!.cast(); + return (pigeonVar_replyList[0] as Map?)! + .cast(); } } /// Retrieves context data as required for advanced security features (ASF). Future getContextData() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getContextData', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getContextData$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send(null) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as NativeUserContextData?)!; + return (pigeonVar_replyList[0] as NativeUserContextData?)!; } } Future getBundleId() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getBundleId', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getBundleId$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send(null) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as String?)!; + return (pigeonVar_replyList[0] as String?)!; } } /// Fetch legacy credentials stored by native SDKs. Future getLegacyCredentials( - String? arg_identityPoolId, String? arg_appClientId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getLegacyCredentials', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_identityPoolId, arg_appClientId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + String? identityPoolId, String? appClientId) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.getLegacyCredentials$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([identityPoolId, appClientId]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as LegacyCredentialStoreData?)!; + return (pigeonVar_replyList[0] as LegacyCredentialStoreData?)!; } } /// Clears the legacy credential store data. Future clearLegacyCredentials() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.clearLegacyCredentials', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.clearLegacyCredentials$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send(null) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; @@ -448,48 +504,50 @@ class NativeAuthBridge { /// Fetch legacy device secrets stored by native SDKs. Future fetchLegacyDeviceSecrets( - String arg_username, String arg_userPoolId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.fetchLegacyDeviceSecrets', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_username, arg_userPoolId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + String username, String userPoolId) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.fetchLegacyDeviceSecrets$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([username, userPoolId]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { - return (replyList[0] as LegacyDeviceDetailsSecret?); + return (pigeonVar_replyList[0] as LegacyDeviceDetailsSecret?); } } /// Clears the legacy device secrets. Future deleteLegacyDeviceSecrets( - String arg_username, String arg_userPoolId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.deleteLegacyDeviceSecrets', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_username, arg_userPoolId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + String username, String userPoolId) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_auth_cognito.NativeAuthBridge.deleteLegacyDeviceSecrets$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([username, userPoolId]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; diff --git a/packages/auth/amplify_auth_cognito/pubspec.yaml b/packages/auth/amplify_auth_cognito/pubspec.yaml index 56f739c698..6a0a6948d7 100644 --- a/packages/auth/amplify_auth_cognito/pubspec.yaml +++ b/packages/auth/amplify_auth_cognito/pubspec.yaml @@ -38,7 +38,7 @@ dev_dependencies: amplify_lints: ">=3.1.0 <3.2.0" flutter_test: sdk: flutter - pigeon: ^11.0.0 + pigeon: ^22.6.2 flutter: plugin: diff --git a/packages/auth/amplify_auth_cognito/test/hosted_ui_platform_flutter_test.dart b/packages/auth/amplify_auth_cognito/test/hosted_ui_platform_flutter_test.dart index 92546d2163..3ee187f4f9 100644 --- a/packages/auth/amplify_auth_cognito/test/hosted_ui_platform_flutter_test.dart +++ b/packages/auth/amplify_auth_cognito/test/hosted_ui_platform_flutter_test.dart @@ -79,7 +79,7 @@ void main() { final class ThrowingNativeBridge extends Fake implements NativeAuthBridge { @override - Future> signInWithUrl( + Future> signInWithUrl( String arg_url, String arg_callbackUrlScheme, bool arg_preferPrivateSession, diff --git a/packages/notifications/push/amplify_push_notifications/android/src/main/kotlin/com/amazonaws/amplify/amplify_push_notifications/PushNotificationsHostApiBindings.java b/packages/notifications/push/amplify_push_notifications/android/src/main/kotlin/com/amazonaws/amplify/amplify_push_notifications/PushNotificationsHostApiBindings.java index e39bfea8bb..7404beee51 100644 --- a/packages/notifications/push/amplify_push_notifications/android/src/main/kotlin/com/amazonaws/amplify/amplify_push_notifications/PushNotificationsHostApiBindings.java +++ b/packages/notifications/push/amplify_push_notifications/android/src/main/kotlin/com/amazonaws/amplify/amplify_push_notifications/PushNotificationsHostApiBindings.java @@ -1,11 +1,14 @@ -// +// // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Autogenerated from Pigeon (v11.0.0), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon package com.amazonaws.amplify.amplify_push_notifications; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.CLASS; + import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -14,6 +17,8 @@ import io.flutter.plugin.common.MessageCodec; import io.flutter.plugin.common.StandardMessageCodec; import java.io.ByteArrayOutputStream; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; @@ -21,6 +26,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; /** Generated class from Pigeon. */ @SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression", "serial"}) @@ -45,7 +51,7 @@ public FlutterError(@NonNull String code, @Nullable String message, @Nullable Ob @NonNull protected static ArrayList wrapError(@NonNull Throwable exception) { - ArrayList errorList = new ArrayList(3); + ArrayList errorList = new ArrayList<>(3); if (exception instanceof FlutterError) { FlutterError error = (FlutterError) exception; errorList.add(error.code); @@ -60,6 +66,15 @@ protected static ArrayList wrapError(@NonNull Throwable exception) { return errorList; } + @NonNull + protected static FlutterError createConnectionError(@NonNull String channelName) { + return new FlutterError("channel-error", "Unable to establish connection on channel: " + channelName + ".", ""); + } + + @Target(METHOD) + @Retention(CLASS) + @interface CanIgnoreReturnValue {} + public enum PermissionStatus { SHOULD_REQUEST(0), SHOULD_EXPLAIN_THEN_REQUEST(1), @@ -68,7 +83,7 @@ public enum PermissionStatus { final int index; - private PermissionStatus(final int index) { + PermissionStatus(final int index) { this.index = index; } } @@ -117,10 +132,24 @@ public void setBadge(@NonNull Boolean setterArg) { /** Constructor is non-public to enforce null safety; use Builder. */ PermissionsOptions() {} + @Override + public boolean equals(Object o) { + if (this == o) { return true; } + if (o == null || getClass() != o.getClass()) { return false; } + PermissionsOptions that = (PermissionsOptions) o; + return alert.equals(that.alert) && sound.equals(that.sound) && badge.equals(that.badge); + } + + @Override + public int hashCode() { + return Objects.hash(alert, sound, badge); + } + public static final class Builder { private @Nullable Boolean alert; + @CanIgnoreReturnValue public @NonNull Builder setAlert(@NonNull Boolean setterArg) { this.alert = setterArg; return this; @@ -128,6 +157,7 @@ public static final class Builder { private @Nullable Boolean sound; + @CanIgnoreReturnValue public @NonNull Builder setSound(@NonNull Boolean setterArg) { this.sound = setterArg; return this; @@ -135,6 +165,7 @@ public static final class Builder { private @Nullable Boolean badge; + @CanIgnoreReturnValue public @NonNull Builder setBadge(@NonNull Boolean setterArg) { this.badge = setterArg; return this; @@ -151,20 +182,20 @@ public static final class Builder { @NonNull ArrayList toList() { - ArrayList toListResult = new ArrayList(3); + ArrayList toListResult = new ArrayList<>(3); toListResult.add(alert); toListResult.add(sound); toListResult.add(badge); return toListResult; } - static @NonNull PermissionsOptions fromList(@NonNull ArrayList list) { + static @NonNull PermissionsOptions fromList(@NonNull ArrayList pigeonVar_list) { PermissionsOptions pigeonResult = new PermissionsOptions(); - Object alert = list.get(0); + Object alert = pigeonVar_list.get(0); pigeonResult.setAlert((Boolean) alert); - Object sound = list.get(1); + Object sound = pigeonVar_list.get(1); pigeonResult.setSound((Boolean) sound); - Object badge = list.get(2); + Object badge = pigeonVar_list.get(2); pigeonResult.setBadge((Boolean) badge); return pigeonResult; } @@ -188,10 +219,24 @@ public void setStatus(@NonNull PermissionStatus setterArg) { /** Constructor is non-public to enforce null safety; use Builder. */ GetPermissionStatusResult() {} + @Override + public boolean equals(Object o) { + if (this == o) { return true; } + if (o == null || getClass() != o.getClass()) { return false; } + GetPermissionStatusResult that = (GetPermissionStatusResult) o; + return status.equals(that.status); + } + + @Override + public int hashCode() { + return Objects.hash(status); + } + public static final class Builder { private @Nullable PermissionStatus status; + @CanIgnoreReturnValue public @NonNull Builder setStatus(@NonNull PermissionStatus setterArg) { this.status = setterArg; return this; @@ -206,38 +251,35 @@ public static final class Builder { @NonNull ArrayList toList() { - ArrayList toListResult = new ArrayList(1); - toListResult.add(status == null ? null : status.index); + ArrayList toListResult = new ArrayList<>(1); + toListResult.add(status); return toListResult; } - static @NonNull GetPermissionStatusResult fromList(@NonNull ArrayList list) { + static @NonNull GetPermissionStatusResult fromList(@NonNull ArrayList pigeonVar_list) { GetPermissionStatusResult pigeonResult = new GetPermissionStatusResult(); - Object status = list.get(0); - pigeonResult.setStatus(PermissionStatus.values()[(int) status]); + Object status = pigeonVar_list.get(0); + pigeonResult.setStatus((PermissionStatus) status); return pigeonResult; } } - public interface Result { - @SuppressWarnings("UnknownNullness") - void success(T result); - - void error(@NonNull Throwable error); - } - - private static class PushNotificationsFlutterApiCodec extends StandardMessageCodec { - public static final PushNotificationsFlutterApiCodec INSTANCE = new PushNotificationsFlutterApiCodec(); + private static class PigeonCodec extends StandardMessageCodec { + public static final PigeonCodec INSTANCE = new PigeonCodec(); - private PushNotificationsFlutterApiCodec() {} + private PigeonCodec() {} @Override protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { switch (type) { - case (byte) 128: - return GetPermissionStatusResult.fromList((ArrayList) readValue(buffer)); - case (byte) 129: + case (byte) 129: { + Object value = readValue(buffer); + return value == null ? null : PermissionStatus.values()[((Long) value).intValue()]; + } + case (byte) 130: return PermissionsOptions.fromList((ArrayList) readValue(buffer)); + case (byte) 131: + return GetPermissionStatusResult.fromList((ArrayList) readValue(buffer)); default: return super.readValueOfType(type, buffer); } @@ -245,84 +287,107 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { @Override protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { - if (value instanceof GetPermissionStatusResult) { - stream.write(128); - writeValue(stream, ((GetPermissionStatusResult) value).toList()); - } else if (value instanceof PermissionsOptions) { + if (value instanceof PermissionStatus) { stream.write(129); + writeValue(stream, value == null ? null : ((PermissionStatus) value).index); + } else if (value instanceof PermissionsOptions) { + stream.write(130); writeValue(stream, ((PermissionsOptions) value).toList()); + } else if (value instanceof GetPermissionStatusResult) { + stream.write(131); + writeValue(stream, ((GetPermissionStatusResult) value).toList()); } else { super.writeValue(stream, value); } } } + + /** Asynchronous error handling return type for non-nullable API method returns. */ + public interface Result { + /** Success case callback method for handling returns. */ + void success(@NonNull T result); + + /** Failure case callback method for handling errors. */ + void error(@NonNull Throwable error); + } + /** Asynchronous error handling return type for nullable API method returns. */ + public interface NullableResult { + /** Success case callback method for handling returns. */ + void success(@Nullable T result); + + /** Failure case callback method for handling errors. */ + void error(@NonNull Throwable error); + } + /** Asynchronous error handling return type for void API method returns. */ + public interface VoidResult { + /** Success case callback method for handling returns. */ + void success(); + + /** Failure case callback method for handling errors. */ + void error(@NonNull Throwable error); + } /** Generated class from Pigeon that represents Flutter messages that can be called from Java. */ public static class PushNotificationsFlutterApi { private final @NonNull BinaryMessenger binaryMessenger; + private final String messageChannelSuffix; public PushNotificationsFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { + this(argBinaryMessenger, ""); + } + public PushNotificationsFlutterApi(@NonNull BinaryMessenger argBinaryMessenger, @NonNull String messageChannelSuffix) { this.binaryMessenger = argBinaryMessenger; + this.messageChannelSuffix = messageChannelSuffix.isEmpty() ? "" : "." + messageChannelSuffix; } - /** Public interface for sending reply. */ - @SuppressWarnings("UnknownNullness") - public interface Reply { - void reply(T reply); - } - /** The codec used by PushNotificationsFlutterApi. */ + /** + * Public interface for sending reply. + * The codec used by PushNotificationsFlutterApi. + */ static @NonNull MessageCodec getCodec() { - return PushNotificationsFlutterApiCodec.INSTANCE; + return PigeonCodec.INSTANCE; } - public void onNotificationReceivedInBackground(@NonNull Map withPayloadArg, @NonNull Reply callback) { + public void onNotificationReceivedInBackground(@NonNull Map withPayloadArg, @NonNull VoidResult result) { + final String channelName = "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsFlutterApi.onNotificationReceivedInBackground" + messageChannelSuffix; BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsFlutterApi.onNotificationReceivedInBackground", getCodec()); + binaryMessenger, channelName, getCodec()); channel.send( - new ArrayList(Collections.singletonList(withPayloadArg)), - channelReply -> callback.reply(null)); + new ArrayList<>(Collections.singletonList(withPayloadArg)), + channelReply -> { + if (channelReply instanceof List) { + List listReply = (List) channelReply; + if (listReply.size() > 1) { + result.error(new FlutterError((String) listReply.get(0), (String) listReply.get(1), listReply.get(2))); + } else { + result.success(); + } + } else { + result.error(createConnectionError(channelName)); + } + }); } - public void nullifyLaunchNotification(@NonNull Reply callback) { + public void nullifyLaunchNotification(@NonNull VoidResult result) { + final String channelName = "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsFlutterApi.nullifyLaunchNotification" + messageChannelSuffix; BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsFlutterApi.nullifyLaunchNotification", getCodec()); + binaryMessenger, channelName, getCodec()); channel.send( null, - channelReply -> callback.reply(null)); - } - } - - private static class PushNotificationsHostApiCodec extends StandardMessageCodec { - public static final PushNotificationsHostApiCodec INSTANCE = new PushNotificationsHostApiCodec(); - - private PushNotificationsHostApiCodec() {} - - @Override - protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { - switch (type) { - case (byte) 128: - return GetPermissionStatusResult.fromList((ArrayList) readValue(buffer)); - case (byte) 129: - return PermissionsOptions.fromList((ArrayList) readValue(buffer)); - default: - return super.readValueOfType(type, buffer); - } - } - - @Override - protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { - if (value instanceof GetPermissionStatusResult) { - stream.write(128); - writeValue(stream, ((GetPermissionStatusResult) value).toList()); - } else if (value instanceof PermissionsOptions) { - stream.write(129); - writeValue(stream, ((PermissionsOptions) value).toList()); - } else { - super.writeValue(stream, value); - } + channelReply -> { + if (channelReply instanceof List) { + List listReply = (List) channelReply; + if (listReply.size() > 1) { + result.error(new FlutterError((String) listReply.get(0), (String) listReply.get(1), listReply.get(2))); + } else { + result.success(); + } + } else { + result.error(createConnectionError(channelName)); + } + }); } } - /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface PushNotificationsHostApi { @@ -344,25 +409,28 @@ public interface PushNotificationsHostApi { /** The codec used by PushNotificationsHostApi. */ static @NonNull MessageCodec getCodec() { - return PushNotificationsHostApiCodec.INSTANCE; + return PigeonCodec.INSTANCE; } /**Sets up an instance of `PushNotificationsHostApi` to handle messages through the `binaryMessenger`. */ - static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PushNotificationsHostApi api) { + static void setUp(@NonNull BinaryMessenger binaryMessenger, @Nullable PushNotificationsHostApi api) { + setUp(binaryMessenger, "", api); + } + static void setUp(@NonNull BinaryMessenger binaryMessenger, @NonNull String messageChannelSuffix, @Nullable PushNotificationsHostApi api) { + messageChannelSuffix = messageChannelSuffix.isEmpty() ? "" : "." + messageChannelSuffix; { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.requestInitialToken", getCodec()); + binaryMessenger, "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.requestInitialToken" + messageChannelSuffix, getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList(); + ArrayList wrapped = new ArrayList<>(); try { api.requestInitialToken(); wrapped.add(0, null); } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; + wrapped = wrapError(exception); } reply.reply(wrapped); }); @@ -373,11 +441,11 @@ static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable PushNotifi { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getPermissionStatus", getCodec()); + binaryMessenger, "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getPermissionStatus" + messageChannelSuffix, getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList(); + ArrayList wrapped = new ArrayList<>(); Result resultCallback = new Result() { public void success(GetPermissionStatusResult result) { @@ -400,11 +468,11 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.requestPermissions", getCodec()); + binaryMessenger, "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.requestPermissions" + messageChannelSuffix, getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList(); + ArrayList wrapped = new ArrayList<>(); ArrayList args = (ArrayList) message; PermissionsOptions withPermissionOptionsArg = (PermissionsOptions) args.get(0); Result resultCallback = @@ -429,18 +497,17 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getLaunchNotification", getCodec()); + binaryMessenger, "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getLaunchNotification" + messageChannelSuffix, getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList(); + ArrayList wrapped = new ArrayList<>(); try { Map output = api.getLaunchNotification(); wrapped.add(0, output); } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; + wrapped = wrapError(exception); } reply.reply(wrapped); }); @@ -451,18 +518,17 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getBadgeCount", getCodec()); + binaryMessenger, "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getBadgeCount" + messageChannelSuffix, getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList(); + ArrayList wrapped = new ArrayList<>(); try { Long output = api.getBadgeCount(); wrapped.add(0, output); } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; + wrapped = wrapError(exception); } reply.reply(wrapped); }); @@ -473,20 +539,19 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.setBadgeCount", getCodec()); + binaryMessenger, "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.setBadgeCount" + messageChannelSuffix, getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList(); + ArrayList wrapped = new ArrayList<>(); ArrayList args = (ArrayList) message; - Number withBadgeCountArg = (Number) args.get(0); + Long withBadgeCountArg = (Long) args.get(0); try { - api.setBadgeCount((withBadgeCountArg == null) ? null : withBadgeCountArg.longValue()); + api.setBadgeCount(withBadgeCountArg); wrapped.add(0, null); } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; + wrapped = wrapError(exception); } reply.reply(wrapped); }); @@ -497,20 +562,19 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.registerCallbackFunction", getCodec()); + binaryMessenger, "dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.registerCallbackFunction" + messageChannelSuffix, getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList(); + ArrayList wrapped = new ArrayList<>(); ArrayList args = (ArrayList) message; - Number callbackHandleArg = (Number) args.get(0); + Long callbackHandleArg = (Long) args.get(0); try { - api.registerCallbackFunction((callbackHandleArg == null) ? null : callbackHandleArg.longValue()); + api.registerCallbackFunction(callbackHandleArg); wrapped.add(0, null); } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; + wrapped = wrapError(exception); } reply.reply(wrapped); }); diff --git a/packages/notifications/push/amplify_push_notifications/ios/Classes/PushNotificationsNativePlugin.h b/packages/notifications/push/amplify_push_notifications/ios/Classes/PushNotificationsNativePlugin.h index 20fb8b270b..599480018a 100644 --- a/packages/notifications/push/amplify_push_notifications/ios/Classes/PushNotificationsNativePlugin.h +++ b/packages/notifications/push/amplify_push_notifications/ios/Classes/PushNotificationsNativePlugin.h @@ -1,7 +1,7 @@ -// +// // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Autogenerated from Pigeon (v11.0.0), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon #import @@ -32,12 +32,12 @@ typedef NS_ENUM(NSUInteger, PermissionStatus) { @interface PermissionsOptions : NSObject /// `init` unavailable to enforce nonnull fields, see the `make` class method. - (instancetype)init NS_UNAVAILABLE; -+ (instancetype)makeWithAlert:(NSNumber *)alert - sound:(NSNumber *)sound - badge:(NSNumber *)badge; -@property(nonatomic, strong) NSNumber * alert; -@property(nonatomic, strong) NSNumber * sound; -@property(nonatomic, strong) NSNumber * badge; ++ (instancetype)makeWithAlert:(BOOL )alert + sound:(BOOL )sound + badge:(BOOL )badge; +@property(nonatomic, assign) BOOL alert; +@property(nonatomic, assign) BOOL sound; +@property(nonatomic, assign) BOOL badge; @end @interface GetPermissionStatusResult : NSObject @@ -47,17 +47,16 @@ typedef NS_ENUM(NSUInteger, PermissionStatus) { @property(nonatomic, assign) PermissionStatus status; @end -/// The codec used by PushNotificationsFlutterApi. -NSObject *PushNotificationsFlutterApiGetCodec(void); +/// The codec used by all APIs. +NSObject *nullGetPushNotificationsNativePluginCodec(void); @interface PushNotificationsFlutterApi : NSObject - (instancetype)initWithBinaryMessenger:(id)binaryMessenger; +- (instancetype)initWithBinaryMessenger:(id)binaryMessenger messageChannelSuffix:(nullable NSString *)messageChannelSuffix; - (void)onNotificationReceivedInBackgroundWithPayload:(NSDictionary *)withPayload completion:(void (^)(FlutterError *_Nullable))completion; - (void)nullifyLaunchNotificationWithCompletion:(void (^)(FlutterError *_Nullable))completion; @end -/// The codec used by PushNotificationsHostApi. -NSObject *PushNotificationsHostApiGetCodec(void); @protocol PushNotificationsHostApi - (void)requestInitialTokenWithError:(FlutterError *_Nullable *_Nonnull)error; @@ -66,10 +65,12 @@ NSObject *PushNotificationsHostApiGetCodec(void); - (nullable NSDictionary *)getLaunchNotificationWithError:(FlutterError *_Nullable *_Nonnull)error; /// @return `nil` only when `error != nil`. - (nullable NSNumber *)getBadgeCountWithError:(FlutterError *_Nullable *_Nonnull)error; -- (void)setBadgeCountWithBadgeCount:(NSNumber *)withBadgeCount error:(FlutterError *_Nullable *_Nonnull)error; -- (void)registerCallbackFunctionCallbackHandle:(NSNumber *)callbackHandle error:(FlutterError *_Nullable *_Nonnull)error; +- (void)setBadgeCountWithBadgeCount:(NSInteger)withBadgeCount error:(FlutterError *_Nullable *_Nonnull)error; +- (void)registerCallbackFunctionCallbackHandle:(NSInteger)callbackHandle error:(FlutterError *_Nullable *_Nonnull)error; @end -extern void PushNotificationsHostApiSetup(id binaryMessenger, NSObject *_Nullable api); +extern void SetUpPushNotificationsHostApi(id binaryMessenger, NSObject *_Nullable api); + +extern void SetUpPushNotificationsHostApiWithSuffix(id binaryMessenger, NSObject *_Nullable api, NSString *messageChannelSuffix); NS_ASSUME_NONNULL_END diff --git a/packages/notifications/push/amplify_push_notifications/ios/Classes/PushNotificationsNativePlugin.m b/packages/notifications/push/amplify_push_notifications/ios/Classes/PushNotificationsNativePlugin.m index 7222a7f689..a518a7a119 100644 --- a/packages/notifications/push/amplify_push_notifications/ios/Classes/PushNotificationsNativePlugin.m +++ b/packages/notifications/push/amplify_push_notifications/ios/Classes/PushNotificationsNativePlugin.m @@ -1,7 +1,7 @@ -// +// // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Autogenerated from Pigeon (v11.0.0), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "PushNotificationsNativePlugin.h" @@ -16,17 +16,7 @@ #error File requires ARC to be enabled. #endif -@implementation PermissionStatusBox -- (instancetype)initWithValue:(PermissionStatus)value { - self = [super init]; - if (self) { - _value = value; - } - return self; -} -@end - -static NSArray *wrapResult(id result, FlutterError *error) { +static NSArray *wrapResult(id result, FlutterError *error) { if (error) { return @[ error.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null] @@ -34,51 +24,63 @@ - (instancetype)initWithValue:(PermissionStatus)value { } return @[ result ?: [NSNull null] ]; } -static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { + +static FlutterError *createConnectionError(NSString *channelName) { + return [FlutterError errorWithCode:@"channel-error" message:[NSString stringWithFormat:@"%@/%@/%@", @"Unable to establish connection on channel: '", channelName, @"'."] details:@""]; +} + +static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) { id result = array[key]; return (result == [NSNull null]) ? nil : result; } +@implementation PermissionStatusBox +- (instancetype)initWithValue:(PermissionStatus)value { + self = [super init]; + if (self) { + _value = value; + } + return self; +} +@end + @interface PermissionsOptions () -+ (PermissionsOptions *)fromList:(NSArray *)list; -+ (nullable PermissionsOptions *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; ++ (PermissionsOptions *)fromList:(NSArray *)list; ++ (nullable PermissionsOptions *)nullableFromList:(NSArray *)list; +- (NSArray *)toList; @end @interface GetPermissionStatusResult () -+ (GetPermissionStatusResult *)fromList:(NSArray *)list; -+ (nullable GetPermissionStatusResult *)nullableFromList:(NSArray *)list; -- (NSArray *)toList; ++ (GetPermissionStatusResult *)fromList:(NSArray *)list; ++ (nullable GetPermissionStatusResult *)nullableFromList:(NSArray *)list; +- (NSArray *)toList; @end @implementation PermissionsOptions -+ (instancetype)makeWithAlert:(NSNumber *)alert - sound:(NSNumber *)sound - badge:(NSNumber *)badge { ++ (instancetype)makeWithAlert:(BOOL )alert + sound:(BOOL )sound + badge:(BOOL )badge { PermissionsOptions* pigeonResult = [[PermissionsOptions alloc] init]; pigeonResult.alert = alert; pigeonResult.sound = sound; pigeonResult.badge = badge; return pigeonResult; } -+ (PermissionsOptions *)fromList:(NSArray *)list { ++ (PermissionsOptions *)fromList:(NSArray *)list { PermissionsOptions *pigeonResult = [[PermissionsOptions alloc] init]; - pigeonResult.alert = GetNullableObjectAtIndex(list, 0); - NSAssert(pigeonResult.alert != nil, @""); - pigeonResult.sound = GetNullableObjectAtIndex(list, 1); - NSAssert(pigeonResult.sound != nil, @""); - pigeonResult.badge = GetNullableObjectAtIndex(list, 2); - NSAssert(pigeonResult.badge != nil, @""); + pigeonResult.alert = [GetNullableObjectAtIndex(list, 0) boolValue]; + pigeonResult.sound = [GetNullableObjectAtIndex(list, 1) boolValue]; + pigeonResult.badge = [GetNullableObjectAtIndex(list, 2) boolValue]; return pigeonResult; } -+ (nullable PermissionsOptions *)nullableFromList:(NSArray *)list { ++ (nullable PermissionsOptions *)nullableFromList:(NSArray *)list { return (list) ? [PermissionsOptions fromList:list] : nil; } -- (NSArray *)toList { +- (NSArray *)toList { return @[ - (self.alert ?: [NSNull null]), - (self.sound ?: [NSNull null]), - (self.badge ?: [NSNull null]), + @(self.alert), + @(self.sound), + @(self.badge), ]; } @end @@ -89,45 +91,54 @@ + (instancetype)makeWithStatus:(PermissionStatus)status { pigeonResult.status = status; return pigeonResult; } -+ (GetPermissionStatusResult *)fromList:(NSArray *)list { ++ (GetPermissionStatusResult *)fromList:(NSArray *)list { GetPermissionStatusResult *pigeonResult = [[GetPermissionStatusResult alloc] init]; - pigeonResult.status = [GetNullableObjectAtIndex(list, 0) integerValue]; + PermissionStatusBox *boxedPermissionStatus = GetNullableObjectAtIndex(list, 0); + pigeonResult.status = boxedPermissionStatus.value; return pigeonResult; } -+ (nullable GetPermissionStatusResult *)nullableFromList:(NSArray *)list { ++ (nullable GetPermissionStatusResult *)nullableFromList:(NSArray *)list { return (list) ? [GetPermissionStatusResult fromList:list] : nil; } -- (NSArray *)toList { +- (NSArray *)toList { return @[ - @(self.status), + [[PermissionStatusBox alloc] initWithValue:self.status], ]; } @end -@interface PushNotificationsFlutterApiCodecReader : FlutterStandardReader +@interface nullPushNotificationsNativePluginPigeonCodecReader : FlutterStandardReader @end -@implementation PushNotificationsFlutterApiCodecReader +@implementation nullPushNotificationsNativePluginPigeonCodecReader - (nullable id)readValueOfType:(UInt8)type { switch (type) { - case 128: - return [GetPermissionStatusResult fromList:[self readValue]]; - case 129: + case 129: { + NSNumber *enumAsNumber = [self readValue]; + return enumAsNumber == nil ? nil : [[PermissionStatusBox alloc] initWithValue:[enumAsNumber integerValue]]; + } + case 130: return [PermissionsOptions fromList:[self readValue]]; + case 131: + return [GetPermissionStatusResult fromList:[self readValue]]; default: return [super readValueOfType:type]; } } @end -@interface PushNotificationsFlutterApiCodecWriter : FlutterStandardWriter +@interface nullPushNotificationsNativePluginPigeonCodecWriter : FlutterStandardWriter @end -@implementation PushNotificationsFlutterApiCodecWriter +@implementation nullPushNotificationsNativePluginPigeonCodecWriter - (void)writeValue:(id)value { - if ([value isKindOfClass:[GetPermissionStatusResult class]]) { - [self writeByte:128]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[PermissionsOptions class]]) { + if ([value isKindOfClass:[PermissionStatusBox class]]) { + PermissionStatusBox *box = (PermissionStatusBox *)value; [self writeByte:129]; + [self writeValue:(value == nil ? [NSNull null] : [NSNumber numberWithInteger:box.value])]; + } else if ([value isKindOfClass:[PermissionsOptions class]]) { + [self writeByte:130]; + [self writeValue:[value toList]]; + } else if ([value isKindOfClass:[GetPermissionStatusResult class]]) { + [self writeByte:131]; [self writeValue:[value toList]]; } else { [super writeValue:value]; @@ -135,121 +146,96 @@ - (void)writeValue:(id)value { } @end -@interface PushNotificationsFlutterApiCodecReaderWriter : FlutterStandardReaderWriter +@interface nullPushNotificationsNativePluginPigeonCodecReaderWriter : FlutterStandardReaderWriter @end -@implementation PushNotificationsFlutterApiCodecReaderWriter +@implementation nullPushNotificationsNativePluginPigeonCodecReaderWriter - (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[PushNotificationsFlutterApiCodecWriter alloc] initWithData:data]; + return [[nullPushNotificationsNativePluginPigeonCodecWriter alloc] initWithData:data]; } - (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[PushNotificationsFlutterApiCodecReader alloc] initWithData:data]; + return [[nullPushNotificationsNativePluginPigeonCodecReader alloc] initWithData:data]; } @end -NSObject *PushNotificationsFlutterApiGetCodec(void) { +NSObject *nullGetPushNotificationsNativePluginCodec(void) { static FlutterStandardMessageCodec *sSharedObject = nil; static dispatch_once_t sPred = 0; dispatch_once(&sPred, ^{ - PushNotificationsFlutterApiCodecReaderWriter *readerWriter = [[PushNotificationsFlutterApiCodecReaderWriter alloc] init]; + nullPushNotificationsNativePluginPigeonCodecReaderWriter *readerWriter = [[nullPushNotificationsNativePluginPigeonCodecReaderWriter alloc] init]; sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; }); return sSharedObject; } - @interface PushNotificationsFlutterApi () @property(nonatomic, strong) NSObject *binaryMessenger; +@property(nonatomic, strong) NSString *messageChannelSuffix; @end @implementation PushNotificationsFlutterApi - (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger { - self = [super init]; + return [self initWithBinaryMessenger:binaryMessenger messageChannelSuffix:@""]; +} +- (instancetype)initWithBinaryMessenger:(NSObject *)binaryMessenger messageChannelSuffix:(nullable NSString*)messageChannelSuffix{ + self = [self init]; if (self) { _binaryMessenger = binaryMessenger; + _messageChannelSuffix = [messageChannelSuffix length] == 0 ? @"" : [NSString stringWithFormat: @".%@", messageChannelSuffix]; } return self; } - (void)onNotificationReceivedInBackgroundWithPayload:(NSDictionary *)arg_withPayload completion:(void (^)(FlutterError *_Nullable))completion { + NSString *channelName = [NSString stringWithFormat:@"%@%@", @"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsFlutterApi.onNotificationReceivedInBackground", _messageChannelSuffix]; FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:@"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsFlutterApi.onNotificationReceivedInBackground" + messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:PushNotificationsFlutterApiGetCodec()]; - [channel sendMessage:@[arg_withPayload ?: [NSNull null]] reply:^(id reply) { - completion(nil); + codec:nullGetPushNotificationsNativePluginCodec()]; + [channel sendMessage:@[arg_withPayload ?: [NSNull null]] reply:^(NSArray *reply) { + if (reply != nil) { + if (reply.count > 1) { + completion([FlutterError errorWithCode:reply[0] message:reply[1] details:reply[2]]); + } else { + completion(nil); + } + } else { + completion(createConnectionError(channelName)); + } }]; } - (void)nullifyLaunchNotificationWithCompletion:(void (^)(FlutterError *_Nullable))completion { + NSString *channelName = [NSString stringWithFormat:@"%@%@", @"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsFlutterApi.nullifyLaunchNotification", _messageChannelSuffix]; FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:@"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsFlutterApi.nullifyLaunchNotification" + messageChannelWithName:channelName binaryMessenger:self.binaryMessenger - codec:PushNotificationsFlutterApiGetCodec()]; - [channel sendMessage:nil reply:^(id reply) { - completion(nil); + codec:nullGetPushNotificationsNativePluginCodec()]; + [channel sendMessage:nil reply:^(NSArray *reply) { + if (reply != nil) { + if (reply.count > 1) { + completion([FlutterError errorWithCode:reply[0] message:reply[1] details:reply[2]]); + } else { + completion(nil); + } + } else { + completion(createConnectionError(channelName)); + } }]; } @end -@interface PushNotificationsHostApiCodecReader : FlutterStandardReader -@end -@implementation PushNotificationsHostApiCodecReader -- (nullable id)readValueOfType:(UInt8)type { - switch (type) { - case 128: - return [GetPermissionStatusResult fromList:[self readValue]]; - case 129: - return [PermissionsOptions fromList:[self readValue]]; - default: - return [super readValueOfType:type]; - } -} -@end - -@interface PushNotificationsHostApiCodecWriter : FlutterStandardWriter -@end -@implementation PushNotificationsHostApiCodecWriter -- (void)writeValue:(id)value { - if ([value isKindOfClass:[GetPermissionStatusResult class]]) { - [self writeByte:128]; - [self writeValue:[value toList]]; - } else if ([value isKindOfClass:[PermissionsOptions class]]) { - [self writeByte:129]; - [self writeValue:[value toList]]; - } else { - [super writeValue:value]; - } -} -@end - -@interface PushNotificationsHostApiCodecReaderWriter : FlutterStandardReaderWriter -@end -@implementation PushNotificationsHostApiCodecReaderWriter -- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[PushNotificationsHostApiCodecWriter alloc] initWithData:data]; -} -- (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[PushNotificationsHostApiCodecReader alloc] initWithData:data]; -} -@end - -NSObject *PushNotificationsHostApiGetCodec(void) { - static FlutterStandardMessageCodec *sSharedObject = nil; - static dispatch_once_t sPred = 0; - dispatch_once(&sPred, ^{ - PushNotificationsHostApiCodecReaderWriter *readerWriter = [[PushNotificationsHostApiCodecReaderWriter alloc] init]; - sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; - }); - return sSharedObject; +void SetUpPushNotificationsHostApi(id binaryMessenger, NSObject *api) { + SetUpPushNotificationsHostApiWithSuffix(binaryMessenger, api, @""); } -void PushNotificationsHostApiSetup(id binaryMessenger, NSObject *api) { +void SetUpPushNotificationsHostApiWithSuffix(id binaryMessenger, NSObject *api, NSString *messageChannelSuffix) { + messageChannelSuffix = messageChannelSuffix.length > 0 ? [NSString stringWithFormat: @".%@", messageChannelSuffix] : @""; { FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.requestInitialToken" + initWithName:[NSString stringWithFormat:@"%@%@", @"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.requestInitialToken", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:PushNotificationsHostApiGetCodec()]; + codec:nullGetPushNotificationsNativePluginCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(requestInitialTokenWithError:)], @"PushNotificationsHostApi api (%@) doesn't respond to @selector(requestInitialTokenWithError:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { @@ -264,9 +250,9 @@ void PushNotificationsHostApiSetup(id binaryMessenger, N { FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getPermissionStatus" + initWithName:[NSString stringWithFormat:@"%@%@", @"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getPermissionStatus", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:PushNotificationsHostApiGetCodec()]; + codec:nullGetPushNotificationsNativePluginCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(getPermissionStatusWithCompletion:)], @"PushNotificationsHostApi api (%@) doesn't respond to @selector(getPermissionStatusWithCompletion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { @@ -281,13 +267,13 @@ void PushNotificationsHostApiSetup(id binaryMessenger, N { FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.requestPermissions" + initWithName:[NSString stringWithFormat:@"%@%@", @"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.requestPermissions", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:PushNotificationsHostApiGetCodec()]; + codec:nullGetPushNotificationsNativePluginCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(requestPermissionsWithPermissionOptions:completion:)], @"PushNotificationsHostApi api (%@) doesn't respond to @selector(requestPermissionsWithPermissionOptions:completion:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; + NSArray *args = message; PermissionsOptions *arg_withPermissionOptions = GetNullableObjectAtIndex(args, 0); [api requestPermissionsWithPermissionOptions:arg_withPermissionOptions completion:^(NSNumber *_Nullable output, FlutterError *_Nullable error) { callback(wrapResult(output, error)); @@ -300,9 +286,9 @@ void PushNotificationsHostApiSetup(id binaryMessenger, N { FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getLaunchNotification" + initWithName:[NSString stringWithFormat:@"%@%@", @"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getLaunchNotification", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:PushNotificationsHostApiGetCodec()]; + codec:nullGetPushNotificationsNativePluginCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(getLaunchNotificationWithError:)], @"PushNotificationsHostApi api (%@) doesn't respond to @selector(getLaunchNotificationWithError:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { @@ -317,9 +303,9 @@ void PushNotificationsHostApiSetup(id binaryMessenger, N { FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getBadgeCount" + initWithName:[NSString stringWithFormat:@"%@%@", @"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getBadgeCount", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:PushNotificationsHostApiGetCodec()]; + codec:nullGetPushNotificationsNativePluginCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(getBadgeCountWithError:)], @"PushNotificationsHostApi api (%@) doesn't respond to @selector(getBadgeCountWithError:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { @@ -334,14 +320,14 @@ void PushNotificationsHostApiSetup(id binaryMessenger, N { FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.setBadgeCount" + initWithName:[NSString stringWithFormat:@"%@%@", @"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.setBadgeCount", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:PushNotificationsHostApiGetCodec()]; + codec:nullGetPushNotificationsNativePluginCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(setBadgeCountWithBadgeCount:error:)], @"PushNotificationsHostApi api (%@) doesn't respond to @selector(setBadgeCountWithBadgeCount:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSNumber *arg_withBadgeCount = GetNullableObjectAtIndex(args, 0); + NSArray *args = message; + NSInteger arg_withBadgeCount = [GetNullableObjectAtIndex(args, 0) integerValue]; FlutterError *error; [api setBadgeCountWithBadgeCount:arg_withBadgeCount error:&error]; callback(wrapResult(nil, error)); @@ -353,14 +339,14 @@ void PushNotificationsHostApiSetup(id binaryMessenger, N { FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] - initWithName:@"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.registerCallbackFunction" + initWithName:[NSString stringWithFormat:@"%@%@", @"dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.registerCallbackFunction", messageChannelSuffix] binaryMessenger:binaryMessenger - codec:PushNotificationsHostApiGetCodec()]; + codec:nullGetPushNotificationsNativePluginCodec()]; if (api) { NSCAssert([api respondsToSelector:@selector(registerCallbackFunctionCallbackHandle:error:)], @"PushNotificationsHostApi api (%@) doesn't respond to @selector(registerCallbackFunctionCallbackHandle:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { - NSArray *args = message; - NSNumber *arg_callbackHandle = GetNullableObjectAtIndex(args, 0); + NSArray *args = message; + NSInteger arg_callbackHandle = [GetNullableObjectAtIndex(args, 0) integerValue]; FlutterError *error; [api registerCallbackFunctionCallbackHandle:arg_callbackHandle error:&error]; callback(wrapResult(nil, error)); diff --git a/packages/notifications/push/amplify_push_notifications/lib/src/native_push_notifications_plugin.g.dart b/packages/notifications/push/amplify_push_notifications/lib/src/native_push_notifications_plugin.g.dart index 9893eed5a2..6b416d1b3a 100644 --- a/packages/notifications/push/amplify_push_notifications/lib/src/native_push_notifications_plugin.g.dart +++ b/packages/notifications/push/amplify_push_notifications/lib/src/native_push_notifications_plugin.g.dart @@ -1,9 +1,9 @@ // // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Autogenerated from Pigeon (v11.0.0), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -11,6 +11,24 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + +List wrapResponse( + {Object? result, PlatformException? error, bool empty = false}) { + if (empty) { + return []; + } + if (error == null) { + return [result]; + } + return [error.code, error.message, error.details]; +} + enum PermissionStatus { shouldRequest, shouldExplainThenRequest, @@ -58,27 +76,33 @@ class GetPermissionStatusResult { Object encode() { return [ - status.index, + status, ]; } static GetPermissionStatusResult decode(Object result) { result as List; return GetPermissionStatusResult( - status: PermissionStatus.values[result[0]! as int], + status: result[0]! as PermissionStatus, ); } } -class _PushNotificationsFlutterApiCodec extends StandardMessageCodec { - const _PushNotificationsFlutterApiCodec(); +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { - if (value is GetPermissionStatusResult) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is PermissionsOptions) { + if (value is int) { + buffer.putUint8(4); + buffer.putInt64(value); + } else if (value is PermissionStatus) { buffer.putUint8(129); + writeValue(buffer, value.index); + } else if (value is PermissionsOptions) { + buffer.putUint8(130); + writeValue(buffer, value.encode()); + } else if (value is GetPermissionStatusResult) { + buffer.putUint8(131); writeValue(buffer, value.encode()); } else { super.writeValue(buffer, value); @@ -88,10 +112,13 @@ class _PushNotificationsFlutterApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: - return GetPermissionStatusResult.decode(readValue(buffer)!); case 129: + final int? value = readValue(buffer) as int?; + return value == null ? null : PermissionStatus.values[value]; + case 130: return PermissionsOptions.decode(readValue(buffer)!); + case 131: + return GetPermissionStatusResult.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); } @@ -99,25 +126,31 @@ class _PushNotificationsFlutterApiCodec extends StandardMessageCodec { } abstract class PushNotificationsFlutterApi { - static const MessageCodec codec = - _PushNotificationsFlutterApiCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); Future onNotificationReceivedInBackground( Map withPayload); void nullifyLaunchNotification(); - static void setup(PushNotificationsFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setUp( + PushNotificationsFlutterApi? api, { + BinaryMessenger? binaryMessenger, + String messageChannelSuffix = '', + }) { + messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsFlutterApi.onNotificationReceivedInBackground', - codec, + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsFlutterApi.onNotificationReceivedInBackground$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + pigeonVar_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { + pigeonVar_channel.setMessageHandler((Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.amplify_push_notifications.PushNotificationsFlutterApi.onNotificationReceivedInBackground was null.'); final List args = (message as List?)!; @@ -125,83 +158,77 @@ abstract class PushNotificationsFlutterApi { (args[0] as Map?)?.cast(); assert(arg_withPayload != null, 'Argument for dev.flutter.pigeon.amplify_push_notifications.PushNotificationsFlutterApi.onNotificationReceivedInBackground was null, expected non-null Map.'); - await api.onNotificationReceivedInBackground(arg_withPayload!); - return; + try { + await api.onNotificationReceivedInBackground(arg_withPayload!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } }); } } { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsFlutterApi.nullifyLaunchNotification', - codec, + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsFlutterApi.nullifyLaunchNotification$messageChannelSuffix', + pigeonChannelCodec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMessageHandler(null); + pigeonVar_channel.setMessageHandler(null); } else { - channel.setMessageHandler((Object? message) async { - // ignore message - api.nullifyLaunchNotification(); - return; + pigeonVar_channel.setMessageHandler((Object? message) async { + try { + api.nullifyLaunchNotification(); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } }); } } } } -class _PushNotificationsHostApiCodec extends StandardMessageCodec { - const _PushNotificationsHostApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is GetPermissionStatusResult) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is PermissionsOptions) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return GetPermissionStatusResult.decode(readValue(buffer)!); - case 129: - return PermissionsOptions.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - class PushNotificationsHostApi { /// Constructor for [PushNotificationsHostApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - PushNotificationsHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + PushNotificationsHostApi( + {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) + : pigeonVar_binaryMessenger = binaryMessenger, + pigeonVar_messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final BinaryMessenger? pigeonVar_binaryMessenger; + + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); - static const MessageCodec codec = _PushNotificationsHostApiCodec(); + final String pigeonVar_messageChannelSuffix; Future requestInitialToken() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.requestInitialToken', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.requestInitialToken$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send(null) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; @@ -209,150 +236,160 @@ class PushNotificationsHostApi { } Future getPermissionStatus() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getPermissionStatus', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getPermissionStatus$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send(null) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as GetPermissionStatusResult?)!; + return (pigeonVar_replyList[0] as GetPermissionStatusResult?)!; } } Future requestPermissions( - PermissionsOptions arg_withPermissionOptions) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.requestPermissions', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_withPermissionOptions]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + PermissionsOptions withPermissionOptions) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.requestPermissions$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([withPermissionOptions]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as bool?)!; + return (pigeonVar_replyList[0] as bool?)!; } } Future?> getLaunchNotification() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getLaunchNotification', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getLaunchNotification$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send(null) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { - return (replyList[0] as Map?)?.cast(); + return (pigeonVar_replyList[0] as Map?) + ?.cast(); } } Future getBadgeCount() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getBadgeCount', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.getBadgeCount$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send(null) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as int?)!; + return (pigeonVar_replyList[0] as int?)!; } } - Future setBadgeCount(int arg_withBadgeCount) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.setBadgeCount', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_withBadgeCount]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + Future setBadgeCount(int withBadgeCount) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.setBadgeCount$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([withBadgeCount]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future registerCallbackFunction(int arg_callbackHandle) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.registerCallbackFunction', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_callbackHandle]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + Future registerCallbackFunction(int callbackHandle) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_push_notifications.PushNotificationsHostApi.registerCallbackFunction$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([callbackHandle]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; diff --git a/packages/notifications/push/amplify_push_notifications/lib/src/push_notifications_flutter_api.dart b/packages/notifications/push/amplify_push_notifications/lib/src/push_notifications_flutter_api.dart index 0bd7a970cb..c58dba4a5e 100644 --- a/packages/notifications/push/amplify_push_notifications/lib/src/push_notifications_flutter_api.dart +++ b/packages/notifications/push/amplify_push_notifications/lib/src/push_notifications_flutter_api.dart @@ -21,14 +21,14 @@ class AmplifyPushNotificationsFlutterApi implements PushNotificationsFlutterApi { /// {@macro amplify_push_notifications.amplify_push_notifications_flutter_api} AmplifyPushNotificationsFlutterApi._constructor() { - PushNotificationsFlutterApi.setup(this); + PushNotificationsFlutterApi.setUp(this); } /// {@template amplify_push_notifications.amplify_push_notifications_flutter_api.reset} /// Ability to reset the singleton only used for resetting between tests. /// {@endtemplate} static void reset() { - PushNotificationsFlutterApi.setup(null); + PushNotificationsFlutterApi.setUp(null); _instance = AmplifyPushNotificationsFlutterApi._constructor(); } diff --git a/packages/notifications/push/amplify_push_notifications/pubspec.yaml b/packages/notifications/push/amplify_push_notifications/pubspec.yaml index 46ae170af5..ae3259ced6 100644 --- a/packages/notifications/push/amplify_push_notifications/pubspec.yaml +++ b/packages/notifications/push/amplify_push_notifications/pubspec.yaml @@ -29,7 +29,7 @@ dev_dependencies: flutter_test: sdk: flutter mockito: ^5.0.0 - pigeon: ^11.0.0 + pigeon: ^22.6.2 test: ^1.22.1 flutter: diff --git a/packages/secure_storage/amplify_secure_storage/android/src/main/kotlin/com/amazonaws/amplify/amplify_secure_storage/pigeons/AmplifySecureStoragePigeon.kt b/packages/secure_storage/amplify_secure_storage/android/src/main/kotlin/com/amazonaws/amplify/amplify_secure_storage/pigeons/AmplifySecureStoragePigeon.kt index 7905f901cc..74c5cbd050 100644 --- a/packages/secure_storage/amplify_secure_storage/android/src/main/kotlin/com/amazonaws/amplify/amplify_secure_storage/pigeons/AmplifySecureStoragePigeon.kt +++ b/packages/secure_storage/amplify_secure_storage/android/src/main/kotlin/com/amazonaws/amplify/amplify_secure_storage/pigeons/AmplifySecureStoragePigeon.kt @@ -1,8 +1,9 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// -// Autogenerated from Pigeon (v11.0.0), do not edit directly. +// +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon +@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass") package com.amazonaws.amplify.amplify_secure_storage.pigeons @@ -19,14 +20,14 @@ private fun wrapResult(result: Any?): List { } private fun wrapError(exception: Throwable): List { - if (exception is FlutterError) { - return listOf( + return if (exception is FlutterError) { + listOf( exception.code, exception.message, exception.details ) } else { - return listOf( + listOf( exception.javaClass.simpleName, exception.toString(), "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception) @@ -45,6 +46,15 @@ class FlutterError ( override val message: String? = null, val details: Any? = null ) : Throwable() +private open class AmplifySecureStoragePigeonPigeonCodec : StandardMessageCodec() { + override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { + return super.readValueOfType(type, buffer) + } + override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { + super.writeValue(stream, value) + } +} + /** * A pigeon for interacting with the native AmplifySecureStorage implementation @@ -61,14 +71,15 @@ interface AmplifySecureStoragePigeon { companion object { /** The codec used by AmplifySecureStoragePigeon. */ val codec: MessageCodec by lazy { - StandardMessageCodec() + AmplifySecureStoragePigeonPigeonCodec() } /** Sets up an instance of `AmplifySecureStoragePigeon` to handle messages through the `binaryMessenger`. */ - @Suppress("UNCHECKED_CAST") - fun setUp(binaryMessenger: BinaryMessenger, api: AmplifySecureStoragePigeon?) { + @JvmOverloads + fun setUp(binaryMessenger: BinaryMessenger, api: AmplifySecureStoragePigeon?, messageChannelSuffix: String = "") { + val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else "" run { val taskQueue = binaryMessenger.makeBackgroundTaskQueue() - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_secure_storage.AmplifySecureStoragePigeon.read", codec, taskQueue) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_secure_storage.AmplifySecureStoragePigeon.read$separatedMessageChannelSuffix", codec, taskQueue) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List @@ -90,7 +101,7 @@ interface AmplifySecureStoragePigeon { } run { val taskQueue = binaryMessenger.makeBackgroundTaskQueue() - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_secure_storage.AmplifySecureStoragePigeon.write", codec, taskQueue) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_secure_storage.AmplifySecureStoragePigeon.write$separatedMessageChannelSuffix", codec, taskQueue) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List @@ -112,7 +123,7 @@ interface AmplifySecureStoragePigeon { } run { val taskQueue = binaryMessenger.makeBackgroundTaskQueue() - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_secure_storage.AmplifySecureStoragePigeon.delete", codec, taskQueue) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_secure_storage.AmplifySecureStoragePigeon.delete$separatedMessageChannelSuffix", codec, taskQueue) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List @@ -133,7 +144,7 @@ interface AmplifySecureStoragePigeon { } run { val taskQueue = binaryMessenger.makeBackgroundTaskQueue() - val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_secure_storage.AmplifySecureStoragePigeon.removeAll", codec, taskQueue) + val channel = BasicMessageChannel(binaryMessenger, "dev.flutter.pigeon.amplify_secure_storage.AmplifySecureStoragePigeon.removeAll$separatedMessageChannelSuffix", codec, taskQueue) if (api != null) { channel.setMessageHandler { message, reply -> val args = message as List diff --git a/packages/secure_storage/amplify_secure_storage/ios/Classes/pigeons/NSUserDefaultsPigeon.swift b/packages/secure_storage/amplify_secure_storage/ios/Classes/pigeons/NSUserDefaultsPigeon.swift index f546fbe25d..d6cfe5e204 100644 --- a/packages/secure_storage/amplify_secure_storage/ios/Classes/pigeons/NSUserDefaultsPigeon.swift +++ b/packages/secure_storage/amplify_secure_storage/ios/Classes/pigeons/NSUserDefaultsPigeon.swift @@ -1,20 +1,35 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// -// Autogenerated from Pigeon (v11.0.0), do not edit directly. +// +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation + #if os(iOS) -import Flutter + import Flutter #elseif os(macOS) -import FlutterMacOS + import FlutterMacOS #else -#error("Unsupported platform.") + #error("Unsupported platform.") #endif -private func isNullish(_ value: Any?) -> Bool { - return value is NSNull || value == nil +/// Error class for passing custom error details to Dart side. +final class PigeonError: Error { + let code: String + let message: String? + let details: Any? + + init(code: String, message: String?, details: Any?) { + self.code = code + self.message = message + self.details = details + } + + var localizedDescription: String { + return + "PigeonError(code: \(code), message: \(message ?? ""), details: \(details ?? "")" + } } private func wrapResult(_ result: Any?) -> [Any?] { @@ -22,24 +37,56 @@ private func wrapResult(_ result: Any?) -> [Any?] { } private func wrapError(_ error: Any) -> [Any?] { + if let pigeonError = error as? PigeonError { + return [ + pigeonError.code, + pigeonError.message, + pigeonError.details, + ] + } if let flutterError = error as? FlutterError { return [ flutterError.code, flutterError.message, - flutterError.details + flutterError.details, ] } return [ "\(error)", "\(type(of: error))", - "Stacktrace: \(Thread.callStackSymbols)" + "Stacktrace: \(Thread.callStackSymbols)", ] } +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + private func nilOrValue(_ value: Any?) -> T? { if value is NSNull { return nil } return value as! T? } + +private class NSUserDefaultsPigeonPigeonCodecReader: FlutterStandardReader { +} + +private class NSUserDefaultsPigeonPigeonCodecWriter: FlutterStandardWriter { +} + +private class NSUserDefaultsPigeonPigeonCodecReaderWriter: FlutterStandardReaderWriter { + override func reader(with data: Data) -> FlutterStandardReader { + return NSUserDefaultsPigeonPigeonCodecReader(data: data) + } + + override func writer(with data: NSMutableData) -> FlutterStandardWriter { + return NSUserDefaultsPigeonPigeonCodecWriter(data: data) + } +} + +class NSUserDefaultsPigeonPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable { + static let shared = NSUserDefaultsPigeonPigeonCodec(readerWriter: NSUserDefaultsPigeonPigeonCodecReaderWriter()) +} + /// A pigeon for interacting with the NSUserDefaults API on iOS and macOS. /// /// Generated protocol from Pigeon that represents a handler of messages from Flutter. @@ -50,10 +97,11 @@ protocol NSUserDefaultsPigeon { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class NSUserDefaultsPigeonSetup { - /// The codec used by NSUserDefaultsPigeon. + static var codec: FlutterStandardMessageCodec { NSUserDefaultsPigeonPigeonCodec.shared } /// Sets up an instance of `NSUserDefaultsPigeon` to handle messages through the `binaryMessenger`. - static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NSUserDefaultsPigeon?) { - let setBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_secure_storage.NSUserDefaultsPigeon.setBool", binaryMessenger: binaryMessenger) + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NSUserDefaultsPigeon?, messageChannelSuffix: String = "") { + let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" + let setBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_secure_storage.NSUserDefaultsPigeon.setBool\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { setBoolChannel.setMessageHandler { message, reply in let args = message as! [Any?] @@ -69,7 +117,7 @@ class NSUserDefaultsPigeonSetup { } else { setBoolChannel.setMessageHandler(nil) } - let boolForChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_secure_storage.NSUserDefaultsPigeon.boolFor", binaryMessenger: binaryMessenger) + let boolForChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_secure_storage.NSUserDefaultsPigeon.boolFor\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { boolForChannel.setMessageHandler { message, reply in let args = message as! [Any?] diff --git a/packages/secure_storage/amplify_secure_storage/lib/src/pigeons/amplify_secure_storage_pigeon.g.dart b/packages/secure_storage/amplify_secure_storage/lib/src/pigeons/amplify_secure_storage_pigeon.g.dart index 6d632294bf..ab1fa4ef77 100644 --- a/packages/secure_storage/amplify_secure_storage/lib/src/pigeons/amplify_secure_storage_pigeon.g.dart +++ b/packages/secure_storage/amplify_secure_storage/lib/src/pigeons/amplify_secure_storage_pigeon.g.dart @@ -1,9 +1,9 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 // -// Autogenerated from Pigeon (v11.0.0), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -11,105 +11,141 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is int) { + buffer.putUint8(4); + buffer.putInt64(value); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + default: + return super.readValueOfType(type, buffer); + } + } +} + /// A pigeon for interacting with the native AmplifySecureStorage implementation /// on Android. class AmplifySecureStoragePigeon { /// Constructor for [AmplifySecureStoragePigeon]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - AmplifySecureStoragePigeon({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + AmplifySecureStoragePigeon( + {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) + : pigeonVar_binaryMessenger = binaryMessenger, + pigeonVar_messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final BinaryMessenger? pigeonVar_binaryMessenger; - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); - Future read(String arg_namespace, String arg_key) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_secure_storage.AmplifySecureStoragePigeon.read', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_namespace, arg_key]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + final String pigeonVar_messageChannelSuffix; + + Future read(String namespace, String key) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_secure_storage.AmplifySecureStoragePigeon.read$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([namespace, key]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { - return (replyList[0] as String?); + return (pigeonVar_replyList[0] as String?); } } - Future write( - String arg_namespace, String arg_key, String? arg_value) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_secure_storage.AmplifySecureStoragePigeon.write', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_namespace, arg_key, arg_value]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + Future write(String namespace, String key, String? value) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_secure_storage.AmplifySecureStoragePigeon.write$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([namespace, key, value]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future delete(String arg_namespace, String arg_key) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_secure_storage.AmplifySecureStoragePigeon.delete', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_namespace, arg_key]) as List?; - if (replyList == null) { + Future delete(String namespace, String key) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_secure_storage.AmplifySecureStoragePigeon.delete$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([namespace, key]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future removeAll(String arg_namespace) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_secure_storage.AmplifySecureStoragePigeon.removeAll', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_namespace]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + Future removeAll(String namespace) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_secure_storage.AmplifySecureStoragePigeon.removeAll$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([namespace]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; diff --git a/packages/secure_storage/amplify_secure_storage/lib/src/pigeons/ns_user_defaults_pigeon.g.dart b/packages/secure_storage/amplify_secure_storage/lib/src/pigeons/ns_user_defaults_pigeon.g.dart index 94f386adf1..c0493f9b47 100644 --- a/packages/secure_storage/amplify_secure_storage/lib/src/pigeons/ns_user_defaults_pigeon.g.dart +++ b/packages/secure_storage/amplify_secure_storage/lib/src/pigeons/ns_user_defaults_pigeon.g.dart @@ -1,9 +1,9 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 // -// Autogenerated from Pigeon (v11.0.0), do not edit directly. +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -11,65 +11,100 @@ import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is int) { + buffer.putUint8(4); + buffer.putInt64(value); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + default: + return super.readValueOfType(type, buffer); + } + } +} + /// A pigeon for interacting with the NSUserDefaults API on iOS and macOS. class NSUserDefaultsPigeon { /// Constructor for [NSUserDefaultsPigeon]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - NSUserDefaultsPigeon({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; + NSUserDefaultsPigeon( + {BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''}) + : pigeonVar_binaryMessenger = binaryMessenger, + pigeonVar_messageChannelSuffix = + messageChannelSuffix.isNotEmpty ? '.$messageChannelSuffix' : ''; + final BinaryMessenger? pigeonVar_binaryMessenger; - static const MessageCodec codec = StandardMessageCodec(); + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); - Future setBool(String arg_key, bool arg_value) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_secure_storage.NSUserDefaultsPigeon.setBool', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_key, arg_value]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + final String pigeonVar_messageChannelSuffix; + + Future setBool(String key, bool value) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_secure_storage.NSUserDefaultsPigeon.setBool$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([key, value]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); } else { return; } } - Future boolFor(String arg_key) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.amplify_secure_storage.NSUserDefaultsPigeon.boolFor', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_key]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { + Future boolFor(String key) async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.amplify_secure_storage.NSUserDefaultsPigeon.boolFor$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([key]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], ); - } else if (replyList[0] == null) { + } else if (pigeonVar_replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyList[0] as bool?)!; + return (pigeonVar_replyList[0] as bool?)!; } } } diff --git a/packages/secure_storage/amplify_secure_storage/macos/Classes/pigeons/NSUserDefaultsPigeon.swift b/packages/secure_storage/amplify_secure_storage/macos/Classes/pigeons/NSUserDefaultsPigeon.swift index f546fbe25d..d6cfe5e204 100644 --- a/packages/secure_storage/amplify_secure_storage/macos/Classes/pigeons/NSUserDefaultsPigeon.swift +++ b/packages/secure_storage/amplify_secure_storage/macos/Classes/pigeons/NSUserDefaultsPigeon.swift @@ -1,20 +1,35 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// -// Autogenerated from Pigeon (v11.0.0), do not edit directly. +// +// Autogenerated from Pigeon (v22.6.2), do not edit directly. // See also: https://pub.dev/packages/pigeon import Foundation + #if os(iOS) -import Flutter + import Flutter #elseif os(macOS) -import FlutterMacOS + import FlutterMacOS #else -#error("Unsupported platform.") + #error("Unsupported platform.") #endif -private func isNullish(_ value: Any?) -> Bool { - return value is NSNull || value == nil +/// Error class for passing custom error details to Dart side. +final class PigeonError: Error { + let code: String + let message: String? + let details: Any? + + init(code: String, message: String?, details: Any?) { + self.code = code + self.message = message + self.details = details + } + + var localizedDescription: String { + return + "PigeonError(code: \(code), message: \(message ?? ""), details: \(details ?? "")" + } } private func wrapResult(_ result: Any?) -> [Any?] { @@ -22,24 +37,56 @@ private func wrapResult(_ result: Any?) -> [Any?] { } private func wrapError(_ error: Any) -> [Any?] { + if let pigeonError = error as? PigeonError { + return [ + pigeonError.code, + pigeonError.message, + pigeonError.details, + ] + } if let flutterError = error as? FlutterError { return [ flutterError.code, flutterError.message, - flutterError.details + flutterError.details, ] } return [ "\(error)", "\(type(of: error))", - "Stacktrace: \(Thread.callStackSymbols)" + "Stacktrace: \(Thread.callStackSymbols)", ] } +private func isNullish(_ value: Any?) -> Bool { + return value is NSNull || value == nil +} + private func nilOrValue(_ value: Any?) -> T? { if value is NSNull { return nil } return value as! T? } + +private class NSUserDefaultsPigeonPigeonCodecReader: FlutterStandardReader { +} + +private class NSUserDefaultsPigeonPigeonCodecWriter: FlutterStandardWriter { +} + +private class NSUserDefaultsPigeonPigeonCodecReaderWriter: FlutterStandardReaderWriter { + override func reader(with data: Data) -> FlutterStandardReader { + return NSUserDefaultsPigeonPigeonCodecReader(data: data) + } + + override func writer(with data: NSMutableData) -> FlutterStandardWriter { + return NSUserDefaultsPigeonPigeonCodecWriter(data: data) + } +} + +class NSUserDefaultsPigeonPigeonCodec: FlutterStandardMessageCodec, @unchecked Sendable { + static let shared = NSUserDefaultsPigeonPigeonCodec(readerWriter: NSUserDefaultsPigeonPigeonCodecReaderWriter()) +} + /// A pigeon for interacting with the NSUserDefaults API on iOS and macOS. /// /// Generated protocol from Pigeon that represents a handler of messages from Flutter. @@ -50,10 +97,11 @@ protocol NSUserDefaultsPigeon { /// Generated setup class from Pigeon to handle messages through the `binaryMessenger`. class NSUserDefaultsPigeonSetup { - /// The codec used by NSUserDefaultsPigeon. + static var codec: FlutterStandardMessageCodec { NSUserDefaultsPigeonPigeonCodec.shared } /// Sets up an instance of `NSUserDefaultsPigeon` to handle messages through the `binaryMessenger`. - static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NSUserDefaultsPigeon?) { - let setBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_secure_storage.NSUserDefaultsPigeon.setBool", binaryMessenger: binaryMessenger) + static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NSUserDefaultsPigeon?, messageChannelSuffix: String = "") { + let channelSuffix = messageChannelSuffix.count > 0 ? ".\(messageChannelSuffix)" : "" + let setBoolChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_secure_storage.NSUserDefaultsPigeon.setBool\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { setBoolChannel.setMessageHandler { message, reply in let args = message as! [Any?] @@ -69,7 +117,7 @@ class NSUserDefaultsPigeonSetup { } else { setBoolChannel.setMessageHandler(nil) } - let boolForChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_secure_storage.NSUserDefaultsPigeon.boolFor", binaryMessenger: binaryMessenger) + let boolForChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.amplify_secure_storage.NSUserDefaultsPigeon.boolFor\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec) if let api = api { boolForChannel.setMessageHandler { message, reply in let args = message as! [Any?] diff --git a/packages/secure_storage/amplify_secure_storage/pubspec.yaml b/packages/secure_storage/amplify_secure_storage/pubspec.yaml index 1d9b76ecb3..ee694165c1 100644 --- a/packages/secure_storage/amplify_secure_storage/pubspec.yaml +++ b/packages/secure_storage/amplify_secure_storage/pubspec.yaml @@ -26,7 +26,7 @@ dev_dependencies: amplify_lints: ">=3.1.0 <3.2.0" flutter_test: sdk: flutter - pigeon: ^11.0.0 + pigeon: ^22.6.2 flutter: plugin: diff --git a/packages/storage/amplify_storage_s3_dart/pubspec.yaml b/packages/storage/amplify_storage_s3_dart/pubspec.yaml index 275c2b3318..dd8b78c78c 100644 --- a/packages/storage/amplify_storage_s3_dart/pubspec.yaml +++ b/packages/storage/amplify_storage_s3_dart/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: aws_signature_v4: ">=0.6.3 <0.7.0" built_collection: ^5.0.0 built_value: ^8.6.0 - drift: ">=2.18.0 <2.19.0" + drift: ">=2.22.0 <2.23.0" fixnum: ^1.0.0 json_annotation: ">=4.9.0 <4.10.0" meta: ^1.7.0 @@ -29,7 +29,7 @@ dev_dependencies: build_runner: ^2.4.9 build_verify: ^3.0.0 built_value_generator: 8.8.1 - drift_dev: ">=2.18.0 <2.19.0" + drift_dev: ">=2.22.0 <2.23.0" json_serializable: 6.8.0 mocktail: ^1.0.0 test: ^1.22.1 diff --git a/pubspec.yaml b/pubspec.yaml index 298afd11e2..018b561b32 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -38,7 +38,7 @@ dependencies: mime: ">=1.0.0 <3.0.0" oauth2: ^2.0.2 package_info_plus: ^8.0.0 - pigeon: ^11.0.0 + pigeon: ^22.6.2 sqlite3: ">=2.0.0 <2.4.7" source_gen: ^1.3.2 stack_trace: ^1.10.0