From 7eb0419aba5e20898461761a3495cdf649bed905 Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Mon, 25 Nov 2024 09:10:01 -0500 Subject: [PATCH] fix: Resolve linting issues --- .../MparticleFlutterSdkPlugin.kt | 115 +++++++--- example/pubspec.lock | 209 ------------------ pubspec.lock | 194 ---------------- 3 files changed, 85 insertions(+), 433 deletions(-) delete mode 100644 example/pubspec.lock delete mode 100644 pubspec.lock diff --git a/android/src/main/kotlin/com/mparticle/mparticle_flutter_sdk/MparticleFlutterSdkPlugin.kt b/android/src/main/kotlin/com/mparticle/mparticle_flutter_sdk/MparticleFlutterSdkPlugin.kt index 1597a77..71fd3fa 100644 --- a/android/src/main/kotlin/com/mparticle/mparticle_flutter_sdk/MparticleFlutterSdkPlugin.kt +++ b/android/src/main/kotlin/com/mparticle/mparticle_flutter_sdk/MparticleFlutterSdkPlugin.kt @@ -103,10 +103,10 @@ class MparticleFlutterSdkPlugin: FlutterPlugin, MethodCallHandler { result.success(sanitizeMapToString(ConvertToUserIdentities(identities))) } ?: result.success("") "getFirstSeen" -> this.getUser(call, result).let { user -> - result.success(user?.getFirstSeenTime().toString() ?: "") + result.success(user?.getFirstSeenTime().toString()) } "getLastSeen" -> this.getUser(call, result).let { user -> - result.success(user?.getLastSeenTime().toString() ?: "") + result.success(user?.getLastSeenTime().toString()) } "removeUserAttribute" -> this.getUser(call, result).let { user -> val key: String? = call.argument("attributeKey") @@ -282,20 +282,43 @@ class MparticleFlutterSdkPlugin: FlutterPlugin, MethodCallHandler { private fun logCommerceEvent(call: MethodCall, result: Result) { try { val map = call.argument>("commerceEvent") ?: mapOf() - val promotions: MutableList? = - (map["promotions"] as List?>?)?.map { it?.toPromotion() } - ?.filterNotNull() - ?.toMutableList() - val products: MutableList? = - (map["products"] as List?>?)?.map { it?.toProduct() } - ?.filterNotNull() - ?.toMutableList() + val promotions = + (map["promotions"] as? List<*>) + ?.filterIsInstance>() + ?.map { it.toPromotion() } + ?.filterNotNull() + ?.toMutableList() + + val products = + (map["products"] as? List<*>) + ?.filterIsInstance>() + ?.map { it.toProduct() } + ?.filterNotNull() + ?.toMutableList() + val impressions: MutableList? = - (map["impressions"] as List?>?)?.map { it?.toImpression() } - ?.filterNotNull() - ?.toMutableList() + (map["impressions"] as? List<*>) + ?.filterIsInstance>() + ?.map { it.toImpression() } + ?.filterNotNull() + ?.toMutableList() + + val transactionAttributesRaw = map["transactionAttributes"] + val transactionAttributes: TransactionAttributes? = - (map["transactionAttributes"] as Map?)?.toTransactionAttributes() + if (transactionAttributesRaw is Map<*, *>) { + @Suppress("UNCHECKED_CAST") // Suppress within the validated context + try { + (transactionAttributesRaw as? Map)?.toTransactionAttributes() + } catch (e: Exception) { + println("Error converting transactionAttributes: ${e.message}") + null + } + } else { + println("transactionAttributes is not a Map: $transactionAttributesRaw") + null + } + val nonInteractive = map["nonInteractive"]?.toString()?.toBoolean() val shouldUploadEvent = map["shouldUploadEvent"]?.toString()?.toBoolean() val productListSource = map["productListSource"]?.toString() @@ -306,8 +329,18 @@ class MparticleFlutterSdkPlugin: FlutterPlugin, MethodCallHandler { val screenName = map["screenName"]?.toString() val checkoutStep = map["checkoutStep"]?.toString()?.toInt() val checkoutOptions = map["checkoutOptions"]?.toString() - val customAttributes: HashMap? = map["customAttributes"] as HashMap? - val customFlags: HashMap? = map["customFlags"] as HashMap? + val customAttributes: HashMap? = + (map["customAttributes"] as? Map<*, *>) + ?.mapNotNull { (key, value) -> + if (key is String && (value is String?)) key to value else null + } + ?.toMap(HashMap()) + + val customFlags: HashMap? = + (map["customFlags"] as? Map<*, *>) + ?.mapNotNull { (key, value) -> if (key is String) key to value else null } + ?.toMap(HashMap()) + val commerceEvent = when { !productActionType.isNullOrEmpty() && !products.isNullOrEmpty() -> CommerceEvent.Builder(productActionType.toString(), products.removeAt(0)) !promotionActionType.isNullOrEmpty()&& !promotions.isNullOrEmpty() -> CommerceEvent.Builder(promotionActionType.toString(), promotions.removeAt(0)) @@ -387,6 +420,7 @@ class MparticleFlutterSdkPlugin: FlutterPlugin, MethodCallHandler { } } + @Suppress("UNUSED_PARAMETER") private fun getOptOut(call: MethodCall, result: Result) { try { val optOut = MParticle.getInstance()?.getOptOut() @@ -412,6 +446,7 @@ class MparticleFlutterSdkPlugin: FlutterPlugin, MethodCallHandler { } } + @Suppress("UNUSED_PARAMETER") private fun upload(call: MethodCall, result: Result) { try { MParticle.getInstance().let { instance -> @@ -531,6 +566,7 @@ class MparticleFlutterSdkPlugin: FlutterPlugin, MethodCallHandler { } } + @Suppress("UNUSED_PARAMETER") private fun getCurrentUser(call: MethodCall, result: Result): MParticleUser? { try { MParticle.getInstance().let { instance -> @@ -692,7 +728,13 @@ class MparticleFlutterSdkPlugin: FlutterPlugin, MethodCallHandler { val brand = get("brand")?.toString() val position = get("position")?.toString()?.toInt() val couponCode = get("couponCode")?.toString() - val attributes = get("attributes") as Map? + val attributes: Map? = + (get("attributes") as? Map<*, *>) + ?.mapNotNull { (key, value) -> + if (key is String && value is String) key to value else null + } + ?.toMap() + return if (name == null || sku == null || price == null) { throw IllegalArgumentException("""Product requires "name", "sku" and "price" values""") } else { @@ -723,7 +765,15 @@ class MparticleFlutterSdkPlugin: FlutterPlugin, MethodCallHandler { @Throws(IllegalArgumentException::class) fun Map.toImpression(): Impression { val impressionListName = get("impressionListName")?.toString() - val products = (get("products") as? ArrayList<*>)?.map { (it as? Map)?.toProduct() ?: throw java.lang.IllegalArgumentException(""""products" entry: $it is malformed """) } + + val products: List? = + (get("products") as? List<*>)?.mapNotNull { entry -> + (entry as? Map<*, *>) + ?.mapNotNull { (key, value) -> if (key is String) key to value else null } + ?.toMap() + ?.toProduct() + } + return if (impressionListName == null || products == null || products.isEmpty()) { throw IllegalArgumentException("""Impression requires an "impressionListName" and at least on "product" """) } else { @@ -750,20 +800,25 @@ class MparticleFlutterSdkPlugin: FlutterPlugin, MethodCallHandler { .put("timestamp", timestamp) fun MethodCall.toCCPAConsent(result: Result): CCPAConsent? { - return try { - argument("consented")?.let { - CCPAConsent.builder(it) - .document(argument("document")) - .hardwareId(argument("hardwareId")) - .location(argument("location")) - .timestamp(argument("timestamp")) - .build() - } ?: null?.apply { result.error(TAG, "Missing \"consented\" value for arguments: ${arguments}", null) } - } catch (ex: Exception) { - result.error(TAG, ex.message, null) - null + return try { + argument("consented")?.let { + CCPAConsent.builder(it) + .document(argument("document")) + .hardwareId(argument("hardwareId")) + .location(argument("location")) + .timestamp(argument("timestamp")) + .build() } + ?: run { + result.error(TAG, "Missing \"consented\" value for arguments: $arguments", null) + null + } + } catch (ex: Exception) { + result.error(TAG, ex.message, null) + null } +} + fun MethodCall.toGDPRConsent(result: Result): Pair? { return try { diff --git a/example/pubspec.lock b/example/pubspec.lock deleted file mode 100644 index f01874f..0000000 --- a/example/pubspec.lock +++ /dev/null @@ -1,209 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - async: - dependency: transitive - description: - name: async - sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" - url: "https://pub.dev" - source: hosted - version: "2.11.0" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" - url: "https://pub.dev" - source: hosted - version: "2.1.1" - characters: - dependency: transitive - description: - name: characters - sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" - url: "https://pub.dev" - source: hosted - version: "1.3.0" - clock: - dependency: transitive - description: - name: clock - sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf - url: "https://pub.dev" - source: hosted - version: "1.1.1" - collection: - dependency: transitive - description: - name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a - url: "https://pub.dev" - source: hosted - version: "1.18.0" - cupertino_icons: - dependency: "direct main" - description: - name: cupertino_icons - sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d - url: "https://pub.dev" - source: hosted - version: "1.0.6" - fake_async: - dependency: transitive - description: - name: fake_async - sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" - url: "https://pub.dev" - source: hosted - version: "1.3.1" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" - flutter_web_plugins: - dependency: transitive - description: flutter - source: sdk - version: "0.0.0" - leak_tracker: - dependency: transitive - description: - name: leak_tracker - sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" - url: "https://pub.dev" - source: hosted - version: "10.0.0" - leak_tracker_flutter_testing: - dependency: transitive - description: - name: leak_tracker_flutter_testing - sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 - url: "https://pub.dev" - source: hosted - version: "2.0.1" - leak_tracker_testing: - dependency: transitive - description: - name: leak_tracker_testing - sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 - url: "https://pub.dev" - source: hosted - version: "2.0.1" - matcher: - dependency: transitive - description: - name: matcher - sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb - url: "https://pub.dev" - source: hosted - version: "0.12.16+1" - material_color_utilities: - dependency: transitive - description: - name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" - url: "https://pub.dev" - source: hosted - version: "0.8.0" - meta: - dependency: transitive - description: - name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 - url: "https://pub.dev" - source: hosted - version: "1.11.0" - mparticle_flutter_sdk: - dependency: "direct main" - description: - path: ".." - relative: true - source: path - version: "1.0.4" - path: - dependency: transitive - description: - name: path - sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" - url: "https://pub.dev" - source: hosted - version: "1.9.0" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - source_span: - dependency: transitive - description: - name: source_span - sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" - url: "https://pub.dev" - source: hosted - version: "1.10.0" - stack_trace: - dependency: transitive - description: - name: stack_trace - sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" - url: "https://pub.dev" - source: hosted - version: "1.11.1" - stream_channel: - dependency: transitive - description: - name: stream_channel - sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 - url: "https://pub.dev" - source: hosted - version: "2.1.2" - string_scanner: - dependency: transitive - description: - name: string_scanner - sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" - url: "https://pub.dev" - source: hosted - version: "1.2.0" - term_glyph: - dependency: transitive - description: - name: term_glyph - sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 - url: "https://pub.dev" - source: hosted - version: "1.2.1" - test_api: - dependency: transitive - description: - name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" - url: "https://pub.dev" - source: hosted - version: "0.6.1" - vector_math: - dependency: transitive - description: - name: vector_math - sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" - url: "https://pub.dev" - source: hosted - version: "2.1.4" - vm_service: - dependency: transitive - description: - name: vm_service - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 - url: "https://pub.dev" - source: hosted - version: "13.0.0" -sdks: - dart: ">=3.2.0-0 <4.0.0" - flutter: ">=3.10.0" diff --git a/pubspec.lock b/pubspec.lock deleted file mode 100644 index feb96f5..0000000 --- a/pubspec.lock +++ /dev/null @@ -1,194 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - async: - dependency: transitive - description: - name: async - sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" - url: "https://pub.dev" - source: hosted - version: "2.11.0" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" - url: "https://pub.dev" - source: hosted - version: "2.1.1" - characters: - dependency: transitive - description: - name: characters - sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" - url: "https://pub.dev" - source: hosted - version: "1.3.0" - clock: - dependency: transitive - description: - name: clock - sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf - url: "https://pub.dev" - source: hosted - version: "1.1.1" - collection: - dependency: transitive - description: - name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a - url: "https://pub.dev" - source: hosted - version: "1.18.0" - fake_async: - dependency: transitive - description: - name: fake_async - sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" - url: "https://pub.dev" - source: hosted - version: "1.3.1" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" - flutter_web_plugins: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - leak_tracker: - dependency: transitive - description: - name: leak_tracker - sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" - url: "https://pub.dev" - source: hosted - version: "10.0.0" - leak_tracker_flutter_testing: - dependency: transitive - description: - name: leak_tracker_flutter_testing - sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 - url: "https://pub.dev" - source: hosted - version: "2.0.1" - leak_tracker_testing: - dependency: transitive - description: - name: leak_tracker_testing - sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 - url: "https://pub.dev" - source: hosted - version: "2.0.1" - matcher: - dependency: transitive - description: - name: matcher - sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb - url: "https://pub.dev" - source: hosted - version: "0.12.16+1" - material_color_utilities: - dependency: transitive - description: - name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" - url: "https://pub.dev" - source: hosted - version: "0.8.0" - meta: - dependency: transitive - description: - name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 - url: "https://pub.dev" - source: hosted - version: "1.11.0" - path: - dependency: transitive - description: - name: path - sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" - url: "https://pub.dev" - source: hosted - version: "1.9.0" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - source_span: - dependency: transitive - description: - name: source_span - sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" - url: "https://pub.dev" - source: hosted - version: "1.10.0" - stack_trace: - dependency: transitive - description: - name: stack_trace - sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" - url: "https://pub.dev" - source: hosted - version: "1.11.1" - stream_channel: - dependency: transitive - description: - name: stream_channel - sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 - url: "https://pub.dev" - source: hosted - version: "2.1.2" - string_scanner: - dependency: transitive - description: - name: string_scanner - sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" - url: "https://pub.dev" - source: hosted - version: "1.2.0" - term_glyph: - dependency: transitive - description: - name: term_glyph - sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 - url: "https://pub.dev" - source: hosted - version: "1.2.1" - test_api: - dependency: transitive - description: - name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" - url: "https://pub.dev" - source: hosted - version: "0.6.1" - vector_math: - dependency: transitive - description: - name: vector_math - sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" - url: "https://pub.dev" - source: hosted - version: "2.1.4" - vm_service: - dependency: transitive - description: - name: vm_service - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 - url: "https://pub.dev" - source: hosted - version: "13.0.0" -sdks: - dart: ">=3.2.0-0 <4.0.0" - flutter: ">=3.10.0"