Skip to content

Commit 5ded361

Browse files
Merge pull request #179 from splitio/FME-12349-fallback-treatments-web
Add fallback treatments support (splitio_web)
2 parents f27d273 + 9ec5682 commit 5ded361

File tree

3 files changed

+63
-33
lines changed

3 files changed

+63
-33
lines changed

splitio_web/lib/splitio_web.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,12 @@ class SplitioWeb extends SplitioPlatform {
321321

322322
config.impressionListener = impressionListener;
323323
}
324+
325+
if (configuration.configurationMap['fallbackTreatments'] != null) {
326+
final fallbackTreatments = configuration.configurationMap['fallbackTreatments'] as Map<String, dynamic>;
327+
// FallbackTreatmentsConfiguration has a compatible structure with JSFallbackTreatmentsConfiguration
328+
config.fallbackTreatments = fallbackTreatments.jsify() as JSFallbackTreatmentsConfiguration;
329+
}
324330
}
325331

326332
return config;

splitio_web/lib/src/js_interop.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ extension type JSConfigurationStorage._(JSObject _) implements JSObject {
9090
external JSBoolean? clearOnInit;
9191
}
9292

93+
@JS()
94+
extension type JSFallbackTreatmentsConfiguration._(JSObject _) implements JSObject {
95+
external JSTreatmentWithConfig? global;
96+
external JSObject? byFlag;
97+
}
98+
9399
@JS()
94100
extension type JSConfiguration._(JSObject _) implements JSObject {
95101
external JSConfigurationCore core;
@@ -102,6 +108,7 @@ extension type JSConfiguration._(JSObject _) implements JSObject {
102108
external JSImpressionListener? impressionListener;
103109
external JSAny? debug;
104110
external JSAny? storage;
111+
external JSFallbackTreatmentsConfiguration? fallbackTreatments;
105112
}
106113

107114
@JS()

splitio_web/test/splitio_web_test.dart

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import 'package:splitio_web/src/js_interop.dart';
77
import 'package:splitio_platform_interface/split_certificate_pinning_configuration.dart';
88
import 'package:splitio_platform_interface/split_sync_config.dart';
99
import 'package:splitio_platform_interface/split_rollout_cache_configuration.dart';
10+
import 'package:splitio_platform_interface/split_fallback_treatment.dart';
11+
import 'package:splitio_platform_interface/split_fallback_treatments_configuration.dart';
1012
import 'utils/js_interop_test_utils.dart';
1113

1214
extension on web.Window {
@@ -685,39 +687,47 @@ void main() {
685687
matchingKey: 'matching-key',
686688
bucketingKey: 'bucketing-key',
687689
sdkConfiguration: SplitConfiguration(
688-
featuresRefreshRate: 1,
689-
segmentsRefreshRate: 2,
690-
impressionsRefreshRate: 3,
691-
telemetryRefreshRate: 4,
692-
eventsQueueSize: 5,
693-
impressionsQueueSize: 6,
694-
eventFlushInterval: 7,
695-
eventsPerPush: 8, // unsupported in Web
696-
trafficType: 'user',
697-
// ignore: deprecated_member_use
698-
enableDebug: false, // deprecated, logLevel has precedence
699-
streamingEnabled: false,
700-
persistentAttributesEnabled: true, // unsupported in Web
701-
impressionListener: true,
702-
sdkEndpoint: 'https://sdk.domain/api',
703-
eventsEndpoint: 'https://events.domain/api',
704-
authServiceEndpoint: 'https://auth.domain/api/v2',
705-
streamingServiceEndpoint: 'https://streaming.domain/sse',
706-
telemetryServiceEndpoint: 'https://telemetry.domain/api/v1',
707-
syncConfig: SyncConfig(
708-
names: ['flag_1', 'flag_2'], prefixes: ['prefix_1']),
709-
impressionsMode: ImpressionsMode.none,
710-
syncEnabled: true,
711-
userConsent: UserConsent.granted,
712-
encryptionEnabled: true, // unsupported in Web
713-
logLevel: SplitLogLevel.info,
714-
readyTimeout: 1,
715-
certificatePinningConfiguration: CertificatePinningConfiguration()
716-
.addPin('host', 'pin'), // unsupported in Web
717-
rolloutCacheConfiguration: RolloutCacheConfiguration(
718-
expirationDays: 100,
719-
clearOnInit: true,
720-
)));
690+
featuresRefreshRate: 1,
691+
segmentsRefreshRate: 2,
692+
impressionsRefreshRate: 3,
693+
telemetryRefreshRate: 4,
694+
eventsQueueSize: 5,
695+
impressionsQueueSize: 6,
696+
eventFlushInterval: 7,
697+
eventsPerPush: 8, // unsupported in Web
698+
trafficType: 'user',
699+
// ignore: deprecated_member_use
700+
enableDebug: false, // deprecated, logLevel has precedence
701+
streamingEnabled: false,
702+
persistentAttributesEnabled: true, // unsupported in Web
703+
impressionListener: true,
704+
sdkEndpoint: 'https://sdk.domain/api',
705+
eventsEndpoint: 'https://events.domain/api',
706+
authServiceEndpoint: 'https://auth.domain/api/v2',
707+
streamingServiceEndpoint: 'https://streaming.domain/sse',
708+
telemetryServiceEndpoint: 'https://telemetry.domain/api/v1',
709+
syncConfig:
710+
SyncConfig(names: ['flag_1', 'flag_2'], prefixes: ['prefix_1']),
711+
impressionsMode: ImpressionsMode.none,
712+
syncEnabled: true,
713+
userConsent: UserConsent.granted,
714+
encryptionEnabled: true, // unsupported in Web
715+
logLevel: SplitLogLevel.info,
716+
readyTimeout: 1,
717+
certificatePinningConfiguration: CertificatePinningConfiguration()
718+
.addPin('host', 'pin'), // unsupported in Web
719+
rolloutCacheConfiguration: RolloutCacheConfiguration(
720+
expirationDays: 100,
721+
clearOnInit: true,
722+
),
723+
fallbackTreatments: FallbackTreatmentsConfiguration(
724+
global: const FallbackTreatment('global-treatment'),
725+
byFlag: {
726+
'flag_1': const FallbackTreatment('fallback_1', 'config_1'),
727+
'flag_2': const FallbackTreatment('fallback_2', null)
728+
},
729+
),
730+
));
721731

722732
expect(mock.calls[mock.calls.length - 5].methodName, 'SplitFactory');
723733
final actual =
@@ -776,6 +786,13 @@ void main() {
776786
'impressionListener': {
777787
'logImpression': (actual as Map)['impressionListener']
778788
['logImpression']
789+
},
790+
'fallbackTreatments': {
791+
'global': {'treatment': 'global-treatment', 'config': null},
792+
'byFlag': {
793+
'flag_1': {'treatment': 'fallback_1', 'config': 'config_1'},
794+
'flag_2': {'treatment': 'fallback_2', 'config': null}
795+
}
779796
}
780797
}));
781798

0 commit comments

Comments
 (0)