From 70742257d7df8d8af127ee2e19d55ce75aefeffa Mon Sep 17 00:00:00 2001 From: Elijah Quartey Date: Mon, 27 Jun 2022 11:43:25 -0500 Subject: [PATCH] chore(api): API Pigeon update (#1813) --- .../lib/src/native_api_plugin.dart | 2 +- .../pigeons/native_api_plugin.dart | 1 + packages/api/amplify_api/pubspec.yaml | 8 +----- .../amplify/amplify_api/AmplifyApi.kt | 7 +++++- .../amplify_api/NativeApiPluginBindings.java | 25 +++++++++++++++---- .../ios/Classes/NativeApiPlugin.h | 4 +-- .../ios/Classes/NativeApiPlugin.m | 10 ++++---- .../ios/Classes/SwiftAmplifyApiPlugin.swift | 9 ++++--- .../ios/amplify_api_ios.podspec | 6 +++-- 9 files changed, 45 insertions(+), 27 deletions(-) diff --git a/packages/api/amplify_api/lib/src/native_api_plugin.dart b/packages/api/amplify_api/lib/src/native_api_plugin.dart index e7c5af4d04..3ff74bd774 100644 --- a/packages/api/amplify_api/lib/src/native_api_plugin.dart +++ b/packages/api/amplify_api/lib/src/native_api_plugin.dart @@ -12,7 +12,7 @@ // express or implied. See the License for the specific language governing // permissions and limitations under the License. // -// Autogenerated from Pigeon (v3.1.5), do not edit directly. +// Autogenerated from Pigeon (v3.2.0), 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 // @dart = 2.12 diff --git a/packages/api/amplify_api/pigeons/native_api_plugin.dart b/packages/api/amplify_api/pigeons/native_api_plugin.dart index a36f7397f9..0e54029724 100644 --- a/packages/api/amplify_api/pigeons/native_api_plugin.dart +++ b/packages/api/amplify_api/pigeons/native_api_plugin.dart @@ -39,5 +39,6 @@ import 'package:pigeon/pigeon.dart'; @HostApi() abstract class NativeApiBridge { + @async void addPlugin(List authProvidersList); } diff --git a/packages/api/amplify_api/pubspec.yaml b/packages/api/amplify_api/pubspec.yaml index b65a92bfec..2bc42e55cb 100644 --- a/packages/api/amplify_api/pubspec.yaml +++ b/packages/api/amplify_api/pubspec.yaml @@ -21,12 +21,6 @@ dependencies: meta: ^1.7.0 plugin_platform_interface: ^2.0.0 -dependency_overrides: - # TODO(dnys1): Remove when pigeon is bumped - # https://github.com/flutter/flutter/issues/105090 - analyzer: ^3.0.0 - - dev_dependencies: amplify_lints: path: ../../amplify_lints @@ -36,7 +30,7 @@ dev_dependencies: flutter_test: sdk: flutter mockito: ^5.0.0 - pigeon: ^3.1.5 + pigeon: ^3.1.6 # The following section is specific to Flutter. flutter: diff --git a/packages/api/amplify_api_android/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/AmplifyApi.kt b/packages/api/amplify_api_android/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/AmplifyApi.kt index 0205877bf7..e49a66932a 100644 --- a/packages/api/amplify_api_android/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/AmplifyApi.kt +++ b/packages/api/amplify_api_android/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/AmplifyApi.kt @@ -159,7 +159,10 @@ class AmplifyApi : FlutterPlugin, MethodCallHandler, NativeApiPluginBindings.Nat ) } - override fun addPlugin(authProvidersList: MutableList) { + override fun addPlugin( + authProvidersList: MutableList, + result: NativeApiPluginBindings.Result + ) { try { val authProviders = authProvidersList.map { AuthorizationType.valueOf(it) } if (flutterAuthProviders == null) { @@ -173,8 +176,10 @@ class AmplifyApi : FlutterPlugin, MethodCallHandler, NativeApiPluginBindings.Nat .build() ) logger.info("Added API plugin") + result.success(null) } catch (e: Exception) { logger.error(e.message) + result.error(e) } } } diff --git a/packages/api/amplify_api_android/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/NativeApiPluginBindings.java b/packages/api/amplify_api_android/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/NativeApiPluginBindings.java index d8d07f4add..70c59352c8 100644 --- a/packages/api/amplify_api_android/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/NativeApiPluginBindings.java +++ b/packages/api/amplify_api_android/android/src/main/kotlin/com/amazonaws/amplify/amplify_api/NativeApiPluginBindings.java @@ -12,7 +12,7 @@ // express or implied. See the License for the specific language governing // permissions and limitations under the License. // -// Autogenerated from Pigeon (v3.1.5), do not edit directly. +// Autogenerated from Pigeon (v3.2.0), do not edit directly. // See also: https://pub.dev/packages/pigeon package com.amazonaws.amplify.amplify_api; @@ -35,6 +35,11 @@ /** Generated class from Pigeon. */ @SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"}) public class NativeApiPluginBindings { + + public interface Result { + void success(T result); + void error(Throwable error); + } private static class NativeApiBridgeCodec extends StandardMessageCodec { public static final NativeApiBridgeCodec INSTANCE = new NativeApiBridgeCodec(); private NativeApiBridgeCodec() {} @@ -42,7 +47,7 @@ private NativeApiBridgeCodec() {} /** Generated interface from Pigeon that represents a handler of messages from Flutter.*/ public interface NativeApiBridge { - void addPlugin(@NonNull List authProvidersList); + void addPlugin(@NonNull List authProvidersList, Result result); /** The codec used by NativeApiBridge. */ static MessageCodec getCodec() { @@ -63,13 +68,23 @@ static void setup(BinaryMessenger binaryMessenger, NativeApiBridge api) { if (authProvidersListArg == null) { throw new NullPointerException("authProvidersListArg unexpectedly null."); } - api.addPlugin(authProvidersListArg); - wrapped.put("result", null); + Result resultCallback = new Result() { + public void success(Void result) { + wrapped.put("result", null); + reply.reply(wrapped); + } + public void error(Throwable error) { + wrapped.put("error", wrapError(error)); + reply.reply(wrapped); + } + }; + + api.addPlugin(authProvidersListArg, resultCallback); } catch (Error | RuntimeException exception) { wrapped.put("error", wrapError(exception)); + reply.reply(wrapped); } - reply.reply(wrapped); }); } else { channel.setMessageHandler(null); diff --git a/packages/api/amplify_api_ios/ios/Classes/NativeApiPlugin.h b/packages/api/amplify_api_ios/ios/Classes/NativeApiPlugin.h index 7b3bad24ed..cf89fcb539 100644 --- a/packages/api/amplify_api_ios/ios/Classes/NativeApiPlugin.h +++ b/packages/api/amplify_api_ios/ios/Classes/NativeApiPlugin.h @@ -12,7 +12,7 @@ // express or implied. See the License for the specific language governing // permissions and limitations under the License. // -// Autogenerated from Pigeon (v3.1.5), do not edit directly. +// Autogenerated from Pigeon (v3.2.0), do not edit directly. // See also: https://pub.dev/packages/pigeon #import @protocol FlutterBinaryMessenger; @@ -27,7 +27,7 @@ NS_ASSUME_NONNULL_BEGIN NSObject *NativeApiBridgeGetCodec(void); @protocol NativeApiBridge -- (void)addPluginAuthProvidersList:(NSArray *)authProvidersList error:(FlutterError *_Nullable *_Nonnull)error; +- (void)addPluginAuthProvidersList:(NSArray *)authProvidersList completion:(void(^)(FlutterError *_Nullable))completion; @end extern void NativeApiBridgeSetup(id binaryMessenger, NSObject *_Nullable api); diff --git a/packages/api/amplify_api_ios/ios/Classes/NativeApiPlugin.m b/packages/api/amplify_api_ios/ios/Classes/NativeApiPlugin.m index c936591be5..bae599aa4b 100644 --- a/packages/api/amplify_api_ios/ios/Classes/NativeApiPlugin.m +++ b/packages/api/amplify_api_ios/ios/Classes/NativeApiPlugin.m @@ -12,7 +12,7 @@ // express or implied. See the License for the specific language governing // permissions and limitations under the License. // -// Autogenerated from Pigeon (v3.1.5), do not edit directly. +// Autogenerated from Pigeon (v3.2.0), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "NativeApiPlugin.h" #import @@ -86,13 +86,13 @@ void NativeApiBridgeSetup(id binaryMessenger, NSObject *arg_authProvidersList = GetNullableObjectAtIndex(args, 0); - FlutterError *error; - [api addPluginAuthProvidersList:arg_authProvidersList error:&error]; - callback(wrapResult(nil, error)); + [api addPluginAuthProvidersList:arg_authProvidersList completion:^(FlutterError *_Nullable error) { + callback(wrapResult(nil, error)); + }]; }]; } else { diff --git a/packages/api/amplify_api_ios/ios/Classes/SwiftAmplifyApiPlugin.swift b/packages/api/amplify_api_ios/ios/Classes/SwiftAmplifyApiPlugin.swift index 63ce5c373c..01c14b8e0c 100644 --- a/packages/api/amplify_api_ios/ios/Classes/SwiftAmplifyApiPlugin.swift +++ b/packages/api/amplify_api_ios/ios/Classes/SwiftAmplifyApiPlugin.swift @@ -70,7 +70,7 @@ public class SwiftAmplifyApiPlugin: NSObject, FlutterPlugin, NativeApiBridge { } } - public func addPluginAuthProvidersList(_ authProvidersList: [String], error: AutoreleasingUnsafeMutablePointer) { + public func addPluginAuthProvidersList(_ authProvidersList: [String]) async -> FlutterError? { do { let authProviders = authProvidersList.compactMap { AWSAuthorizationType(rawValue: $0) @@ -79,8 +79,9 @@ public class SwiftAmplifyApiPlugin: NSObject, FlutterPlugin, NativeApiBridge { plugin: AWSAPIPlugin( sessionFactory: FlutterURLSessionBehaviorFactory(), apiAuthProviderFactory: FlutterAuthProviders(authProviders))) + return nil } catch let apiError as APIError { - error.pointee = FlutterError( + return FlutterError( code: "APIException", message: apiError.localizedDescription, details: [ @@ -94,7 +95,7 @@ public class SwiftAmplifyApiPlugin: NSObject, FlutterPlugin, NativeApiBridge { if case .amplifyAlreadyConfigured = configError { errorCode = "AmplifyAlreadyConfiguredException" } - error.pointee = FlutterError( + return FlutterError( code: errorCode, message: configError.localizedDescription, details: [ @@ -104,7 +105,7 @@ public class SwiftAmplifyApiPlugin: NSObject, FlutterPlugin, NativeApiBridge { ] ) } catch let e { - error.pointee = FlutterError( + return FlutterError( code: "UNKNOWN", message: e.localizedDescription, details: nil diff --git a/packages/api/amplify_api_ios/ios/amplify_api_ios.podspec b/packages/api/amplify_api_ios/ios/amplify_api_ios.podspec index 276c97012b..f5a6147bff 100644 --- a/packages/api/amplify_api_ios/ios/amplify_api_ios.podspec +++ b/packages/api/amplify_api_ios/ios/amplify_api_ios.podspec @@ -18,8 +18,10 @@ The API module for Amplify Flutter. s.dependency 'Amplify', '1.23.0' s.dependency 'AmplifyPlugins/AWSAPIPlugin', '1.23.0' s.dependency 'amplify_flutter_ios' - s.platform = :ios, '11.0' - s.swift_version = '5.0' + + # These are needed to support async/await with pigeon + s.platform = :ios, '13.0' + s.swift_version = '5.5' # Use a custom module map with a manually written umbrella header. #