diff --git a/splitio/example/ios/Podfile.lock b/splitio/example/ios/Podfile.lock index e004592..c23d777 100644 --- a/splitio/example/ios/Podfile.lock +++ b/splitio/example/ios/Podfile.lock @@ -1,9 +1,9 @@ PODS: - Flutter (1.0.0) - - Split (3.3.2) - - splitio_ios (0.8.0): + - Split (3.6.0) + - splitio_ios (0.9.0): - Flutter - - Split (~> 3.3.2) + - Split (~> 3.6.0) DEPENDENCIES: - Flutter (from `Flutter`) @@ -20,9 +20,9 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/splitio_ios/ios" SPEC CHECKSUMS: - Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 - Split: 0d4962a6c15180e1857c1a3753e1ae9c91a6150b - splitio_ios: 438ad21d0dfe467670f8b9508773b77b16a71d6b + Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467 + Split: 1e2176aacd6421029bea41413401389d86e3d50a + splitio_ios: ad4f484a6c478bf7285e417ea8252371f66b54ff PODFILE CHECKSUM: 4e8f8b2be68aeea4c0d5beb6ff1e79fface1d048 diff --git a/splitio/lib/splitio.dart b/splitio/lib/splitio.dart index a037b11..27cd8fe 100644 --- a/splitio/lib/splitio.dart +++ b/splitio/lib/splitio.dart @@ -12,6 +12,8 @@ export 'package:splitio_platform_interface/split_view.dart'; export 'package:splitio_platform_interface/split_certificate_pinning_configuration.dart'; export 'package:splitio_platform_interface/split_evaluation_options.dart'; export 'package:splitio_platform_interface/split_rollout_cache_configuration.dart'; +export 'package:splitio_platform_interface/split_fallback_treatment.dart'; +export 'package:splitio_platform_interface/split_fallback_treatments_configuration.dart'; typedef ClientReadinessCallback = void Function(SplitClient splitClient); diff --git a/splitio/pubspec.yaml b/splitio/pubspec.yaml index a762f9f..79e7a0a 100644 --- a/splitio/pubspec.yaml +++ b/splitio/pubspec.yaml @@ -21,10 +21,14 @@ flutter: dependencies: flutter: sdk: flutter - splitio_android: ^1.0.0 - splitio_ios: ^1.0.0 - splitio_web: ^1.0.0 - splitio_platform_interface: ^2.0.0 + splitio_android: # ^1.0.0 + path: ../splitio_android + splitio_ios: # ^1.0.0 + path: ../splitio_ios + splitio_web: # ^1.0.0 + path: ../splitio_web + splitio_platform_interface: # ^2.0.0 + path: ../splitio_platform_interface dev_dependencies: flutter_test: sdk: flutter diff --git a/splitio_android/android/build.gradle b/splitio_android/android/build.gradle index 0cd5200..723d466 100644 --- a/splitio_android/android/build.gradle +++ b/splitio_android/android/build.gradle @@ -38,7 +38,7 @@ android { } dependencies { - implementation 'io.split.client:android-client:5.3.1' + implementation 'io.split.client:android-client:5.4.2' testImplementation 'junit:junit:4.13.2' testImplementation 'org.mockito:mockito-core:3.12.4' diff --git a/splitio_android/android/src/main/java/io/split/splitio/SplitClientConfigHelper.java b/splitio_android/android/src/main/java/io/split/splitio/SplitClientConfigHelper.java index 2df8e0d..da35b35 100644 --- a/splitio_android/android/src/main/java/io/split/splitio/SplitClientConfigHelper.java +++ b/splitio_android/android/src/main/java/io/split/splitio/SplitClientConfigHelper.java @@ -19,6 +19,8 @@ import io.split.android.client.network.CertificatePinningConfiguration; import io.split.android.client.shared.UserConsent; import io.split.android.client.utils.logger.SplitLogLevel; +import io.split.android.client.fallback.FallbackTreatmentsConfiguration; +import io.split.android.client.fallback.FallbackTreatment; class SplitClientConfigHelper { @@ -55,6 +57,11 @@ class SplitClientConfigHelper { private static final String ROLLOUT_CACHE_CONFIGURATION = "rolloutCacheConfiguration"; private static final String ROLLOUT_CACHE_CONFIGURATION_EXPIRATION = "expirationDays"; private static final String ROLLOUT_CACHE_CONFIGURATION_CLEAR_ON_INIT = "clearOnInit"; + private static final String FALLBACK_TREATMENTS = "fallbackTreatments"; + private static final String FALLBACK_TREATMENTS_GLOBAL = "global"; + private static final String FALLBACK_TREATMENTS_BY_FLAG = "byFlag"; + private static final String FALLBACK_TREATMENT_VALUE = "treatment"; + private static final String FALLBACK_TREATMENT_CONFIG = "config"; /** * Creates a {@link SplitClientConfig} object from a map. @@ -262,6 +269,29 @@ static SplitClientConfig fromMap(@NonNull Map configurationMap, } } + Map fallbackTreatments = getObjectMap(configurationMap, FALLBACK_TREATMENTS); + if (fallbackTreatments != null) { + Map global = getObjectMap(fallbackTreatments, FALLBACK_TREATMENTS_GLOBAL); + Map byFlag = getObjectMap(fallbackTreatments, FALLBACK_TREATMENTS_BY_FLAG); + if (global != null || byFlag != null) { + FallbackTreatmentsConfiguration.Builder fallbackTreatmentsBuilder = FallbackTreatmentsConfiguration.builder(); + if (global != null) { + fallbackTreatmentsBuilder.global(new FallbackTreatment(getString(global, FALLBACK_TREATMENT_VALUE), getString(global, FALLBACK_TREATMENT_CONFIG))); + } + if (byFlag != null) { + Map byFlagMap = new HashMap<>(); + for (Map.Entry entry : byFlag.entrySet()) { + Map byFlagFallbackTreatment = getObjectMap(byFlag, entry.getKey()); + if (byFlagFallbackTreatment != null) { + byFlagMap.put(entry.getKey(), new FallbackTreatment(getString(byFlagFallbackTreatment, FALLBACK_TREATMENT_VALUE), getString(byFlagFallbackTreatment, FALLBACK_TREATMENT_CONFIG))); + } + } + fallbackTreatmentsBuilder.byFlag(byFlagMap); + } + builder.fallbackTreatments(fallbackTreatmentsBuilder.build()); + } + } + return builder.serviceEndpoints(serviceEndpointsBuilder.build()).build(); } diff --git a/splitio_android/android/src/test/java/io/split/splitio/SplitClientConfigHelperTest.java b/splitio_android/android/src/test/java/io/split/splitio/SplitClientConfigHelperTest.java index 23a5215..ebd20f6 100644 --- a/splitio_android/android/src/test/java/io/split/splitio/SplitClientConfigHelperTest.java +++ b/splitio_android/android/src/test/java/io/split/splitio/SplitClientConfigHelperTest.java @@ -27,6 +27,8 @@ import io.split.android.client.utils.logger.LogPrinter; import io.split.android.client.utils.logger.Logger; import io.split.android.client.utils.logger.SplitLogLevel; +import io.split.android.client.fallback.FallbackTreatmentsConfiguration; +import io.split.android.client.fallback.FallbackTreatment; public class SplitClientConfigHelperTest { @@ -235,4 +237,33 @@ public void rolloutCacheConfigurationValuesAreMappedCorrectly() { assertEquals(5, splitClientConfig.rolloutCacheConfiguration().getExpirationDays()); assertTrue(splitClientConfig.rolloutCacheConfiguration().isClearOnInit()); } + + @Test + public void fallbackTreatmentsValuesAreMappedCorrectly() { + Map globalFallbackTreatment = new HashMap<>(); + globalFallbackTreatment.put("treatment", "global-control"); + globalFallbackTreatment.put("config", "global-config"); + + Map feature1FallbackTreatment = new HashMap<>(); + feature1FallbackTreatment.put("treatment", "feature1-control"); + feature1FallbackTreatment.put("config", null); + + Map byFlagFallbackTreatments = new HashMap<>(); + byFlagFallbackTreatments.put("feature1", feature1FallbackTreatment); + + Map fallbackTreatmentsValues = new HashMap<>(); + fallbackTreatmentsValues.put("global", globalFallbackTreatment); + fallbackTreatmentsValues.put("byFlag", byFlagFallbackTreatments); + + Map configValues = new HashMap<>(); + configValues.put("fallbackTreatments", fallbackTreatmentsValues); + + SplitClientConfig splitClientConfig = SplitClientConfigHelper + .fromMap(configValues, mock(ImpressionListener.class)); + + FallbackTreatmentsConfiguration fallbackTreatmentsConfiguration = splitClientConfig.fallbackTreatments(); + + assertEquals(new FallbackTreatment("global-control", "global-config"), fallbackTreatmentsConfiguration.getGlobal()); + assertEquals(Map.of("feature1", new FallbackTreatment("feature1-control", null)), fallbackTreatmentsConfiguration.getByFlag()); + } } diff --git a/splitio_android/pubspec.yaml b/splitio_android/pubspec.yaml index fc2bbbe..6935678 100644 --- a/splitio_android/pubspec.yaml +++ b/splitio_android/pubspec.yaml @@ -19,7 +19,8 @@ flutter: dependencies: flutter: sdk: flutter - splitio_platform_interface: ^2.0.0 + splitio_platform_interface: # ^2.0.0 + path: ../splitio_platform_interface dev_dependencies: flutter_test: diff --git a/splitio_ios/example/ios/Podfile.lock b/splitio_ios/example/ios/Podfile.lock index ea8a88c..5b23eda 100644 --- a/splitio_ios/example/ios/Podfile.lock +++ b/splitio_ios/example/ios/Podfile.lock @@ -1,9 +1,9 @@ PODS: - Flutter (1.0.0) - - Split (3.3.2) - - splitio_ios (0.8.0): + - Split (3.6.0) + - splitio_ios (0.9.0): - Flutter - - Split (~> 3.3.2) + - Split (~> 3.6.0) DEPENDENCIES: - Flutter (from `Flutter`) @@ -20,10 +20,10 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/splitio_ios/ios" SPEC CHECKSUMS: - Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 - Split: 0d4962a6c15180e1857c1a3753e1ae9c91a6150b - splitio_ios: 438ad21d0dfe467670f8b9508773b77b16a71d6b + Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467 + Split: 1e2176aacd6421029bea41413401389d86e3d50a + splitio_ios: ad4f484a6c478bf7285e417ea8252371f66b54ff -PODFILE CHECKSUM: aed42fc5c94ade572556b7ed357c5c57f1bd83a2 +PODFILE CHECKSUM: ba5baa820782b9e142d3ba97a6b84de9feaaceda COCOAPODS: 1.16.2 diff --git a/splitio_ios/example/ios/SplitTests/SplitClientConfigHelperTests.swift b/splitio_ios/example/ios/SplitTests/SplitClientConfigHelperTests.swift index 2c29a06..8475535 100644 --- a/splitio_ios/example/ios/SplitTests/SplitClientConfigHelperTests.swift +++ b/splitio_ios/example/ios/SplitTests/SplitClientConfigHelperTests.swift @@ -154,4 +154,29 @@ class SplitClientConfigHelperTests: XCTestCase { XCTAssertEqual(5, actualConfig.expirationDays) XCTAssertTrue(actualConfig.clearOnInit) } + + func testFallbackTreatmentsConfigurationValuesAreMappedCorrectly() { + let configValues = [ + "fallbackTreatments": [ + "global": [ + "treatment": "on", + "config": "{\"key\": \"value\"}" + ], + "byFlag": [ + "feature1": [ + "treatment": "off", + "config": nil + ] + ] + ] + ] + + let splitClientConfig: SplitClientConfig = SplitClientConfigHelper.fromMap(configurationMap: configValues, impressionListener: nil) + let actualConfig = splitClientConfig.fallbackTreatments + + XCTAssertEqual("on", actualConfig.global?.treatment) + XCTAssertEqual("{\"key\": \"value\"}", actualConfig.global?.config) + XCTAssertEqual("off", actualConfig.byFlag["feature1"]?.treatment) + XCTAssertNil(actualConfig.byFlag["feature1"]?.config) + } } diff --git a/splitio_ios/ios/Classes/SplitClientConfigHelper.swift b/splitio_ios/ios/Classes/SplitClientConfigHelper.swift index abe76d0..63c8d22 100644 --- a/splitio_ios/ios/Classes/SplitClientConfigHelper.swift +++ b/splitio_ios/ios/Classes/SplitClientConfigHelper.swift @@ -36,6 +36,11 @@ class SplitClientConfigHelper { static private let ROLLOUT_CACHE_CONFIGURATION = "rolloutCacheConfiguration" static private let ROLLOUT_CACHE_CONFIGURATION_EXPIRATION = "expirationDays" static private let ROLLOUT_CACHE_CONFIGURATION_CLEAR_ON_INIT = "clearOnInit" + static private let FALLBACK_TREATMENTS = "fallbackTreatments"; + static private let FALLBACK_TREATMENTS_GLOBAL = "global"; + static private let FALLBACK_TREATMENTS_BY_FLAG = "byFlag"; + static private let FALLBACK_TREATMENT_VALUE = "treatment"; + static private let FALLBACK_TREATMENT_CONFIG = "config"; static func fromMap(configurationMap: [String: Any?], impressionListener: SplitImpressionListener?) -> SplitClientConfig { let config = SplitClientConfig() @@ -253,6 +258,30 @@ class SplitClientConfigHelper { config.rolloutCacheConfiguration = rolloutCacheConfigurationBuilder.build() } + if let fallbackTreatmentConfig = configurationMap[FALLBACK_TREATMENTS] as? [String: Any?] { + let fallbackTreatmentConfiguration = FallbackTreatmentsConfig.builder() + + if let globalTreatment = fallbackTreatmentConfig[FALLBACK_TREATMENTS_GLOBAL] as? [String: Any?] { + fallbackTreatmentConfiguration.global(FallbackTreatment( + treatment: globalTreatment[FALLBACK_TREATMENT_VALUE] as! String, + config: globalTreatment[FALLBACK_TREATMENT_CONFIG] as? String + )) + } + + if let byFlagTreatments = fallbackTreatmentConfig[FALLBACK_TREATMENTS_BY_FLAG] as? [String: [String: Any?]] { + var byFlag: [String: FallbackTreatment] = [:] + for (key, value) in byFlagTreatments { + byFlag[key] = FallbackTreatment( + treatment: value[FALLBACK_TREATMENT_VALUE] as! String, + config: value[FALLBACK_TREATMENT_CONFIG] as? String + ) + } + fallbackTreatmentConfiguration.byFlag(byFlag) + } + + config.fallbackTreatments = fallbackTreatmentConfiguration.build() + } + return config } diff --git a/splitio_ios/ios/splitio_ios.podspec b/splitio_ios/ios/splitio_ios.podspec index bb24308..cdbf4e7 100644 --- a/splitio_ios/ios/splitio_ios.podspec +++ b/splitio_ios/ios/splitio_ios.podspec @@ -4,7 +4,7 @@ # Pod::Spec.new do |s| s.name = 'splitio_ios' - s.version = '0.8.0' + s.version = '0.9.0' s.summary = 'split.io official Flutter plugin.' s.description = <<-DESC split.io official Flutter plugin. @@ -15,7 +15,7 @@ split.io official Flutter plugin. s.source = { :path => '.' } s.source_files = 'Classes/**/*' s.dependency 'Flutter' - s.dependency 'Split', '~> 3.3.2' + s.dependency 'Split', '~> 3.6.0' s.platform = :ios, '9.0' # Flutter.framework does not contain a i386 slice. diff --git a/splitio_ios/pubspec.yaml b/splitio_ios/pubspec.yaml index 8c6637b..1d4c6cf 100644 --- a/splitio_ios/pubspec.yaml +++ b/splitio_ios/pubspec.yaml @@ -18,7 +18,8 @@ flutter: dependencies: flutter: sdk: flutter - splitio_platform_interface: ^2.0.0 + splitio_platform_interface: # ^2.0.0 + path: ../splitio_platform_interface dev_dependencies: flutter_test: diff --git a/splitio_web/pubspec.yaml b/splitio_web/pubspec.yaml index 72e04bb..ae86de9 100644 --- a/splitio_web/pubspec.yaml +++ b/splitio_web/pubspec.yaml @@ -20,7 +20,8 @@ flutter: dependencies: flutter: sdk: flutter - splitio_platform_interface: ^2.0.0 + splitio_platform_interface: # ^2.0.0 + path: ../splitio_platform_interface flutter_web_plugins: sdk: flutter web: ">=0.5.0 <2.0.0"