diff --git a/packages/remote-config/android/src/main/java/io/invertase/firebase/config/UniversalFirebaseConfigModule.java b/packages/remote-config/android/src/main/java/io/invertase/firebase/config/UniversalFirebaseConfigModule.java index 62648bbf78..ca209d646d 100644 --- a/packages/remote-config/android/src/main/java/io/invertase/firebase/config/UniversalFirebaseConfigModule.java +++ b/packages/remote-config/android/src/main/java/io/invertase/firebase/config/UniversalFirebaseConfigModule.java @@ -69,6 +69,10 @@ Task setConfigSettings(Bundle configSettings) { return Tasks.call(getExecutor(), () -> { FirebaseRemoteConfigSettings.Builder configSettingsBuilder = new FirebaseRemoteConfigSettings.Builder(); configSettingsBuilder.setDeveloperModeEnabled(configSettings.getBoolean("isDeveloperModeEnabled")); + if (configSettings.containsKey("minimumFetchInterval")) { + double fetchInterval = configSettings.getDouble("minimumFetchInterval"); + configSettingsBuilder.setMinimumFetchIntervalInSeconds((long)fetchInterval); + } FirebaseRemoteConfig.getInstance().setConfigSettings(configSettingsBuilder.build()); return null; }); @@ -174,6 +178,7 @@ public Map getConstantsForApp(String appName) { appConstants.put("lastFetchTime", remoteConfigInfo.getFetchTimeMillis()); appConstants.put("isDeveloperModeEnabled", remoteConfigSettings.isDeveloperModeEnabled()); appConstants.put("lastFetchStatus", lastFetchStatusToString(remoteConfigInfo.getLastFetchStatus())); + appConstants.put("minimumFetchInterval", remoteConfigSettings.getMinimumFetchIntervalInSeconds()); return appConstants; } diff --git a/packages/remote-config/e2e/config.e2e.js b/packages/remote-config/e2e/config.e2e.js index a400111c49..bee74f21a6 100644 --- a/packages/remote-config/e2e/config.e2e.js +++ b/packages/remote-config/e2e/config.e2e.js @@ -120,6 +120,14 @@ describe('remoteConfig()', () => { firebase.remoteConfig().isDeveloperModeEnabled.should.equal(false); }); + it('minimumFetchInterval sets correctly', async () => { + await firebase + .remoteConfig() + .setConfigSettings({ isDeveloperModeEnabled: true, minimumFetchInterval: 300 }); + + firebase.remoteConfig().minimumFetchInterval.should.be.equal(300); + }); + it('it throws if no args', async () => { try { await firebase.remoteConfig().setConfigSettings(); @@ -151,6 +159,18 @@ describe('remoteConfig()', () => { return Promise.resolve(); } }); + + it('throws if minimumFetchInterval is not a number', async () => { + try { + await firebase + .remoteConfig() + .setConfigSettings({ isDeveloperModeEnabled: true, minimumFetchInterval: 'potato' }); + return Promise.reject(new Error('Did not throw')); + } catch (error) { + error.message.should.containEql("'settings.minimumFetchInterval' must be a number value"); + return Promise.resolve(); + } + }); }); describe('getAll()', () => { diff --git a/packages/remote-config/ios/RNFBConfig/RNFBConfigModule.m b/packages/remote-config/ios/RNFBConfig/RNFBConfigModule.m index 54347c8bea..d958a1e890 100644 --- a/packages/remote-config/ios/RNFBConfig/RNFBConfigModule.m +++ b/packages/remote-config/ios/RNFBConfig/RNFBConfigModule.m @@ -141,6 +141,11 @@ + (BOOL)requiresMainQueueSetup { ) { FIRRemoteConfigSettings *remoteConfigSettings = [[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:[configSettings[@"isDeveloperModeEnabled"] boolValue]]; + + if ([configSettings objectForKey:@"minimumFetchInterval"]) { + remoteConfigSettings.minimumFetchInterval = [configSettings[@"minimumFetchInterval"] doubleValue]; + } + [FIRRemoteConfig remoteConfig].configSettings = remoteConfigSettings; resolve([self resultWithConstants:[NSNull null]]); } @@ -184,6 +189,7 @@ - (NSDictionary *)getConstantsForApp { NSDate *lastFetchTime = remoteConfig.lastFetchTime; BOOL isDeveloperModeEnabled = [RCTConvert BOOL:@([remoteConfig configSettings].isDeveloperModeEnabled)]; NSString *lastFetchStatus = convertFIRRemoteConfigFetchStatusToNSString(remoteConfig.lastFetchStatus); + double minimumFetchInterval = [RCTConvert double:@([remoteConfig configSettings].minimumFetchInterval)]; NSMutableDictionary *values = [NSMutableDictionary new]; NSSet *keys = [[FIRRemoteConfig remoteConfig] keysWithPrefix:nil]; @@ -205,6 +211,7 @@ - (NSDictionary *)getConstantsForApp { @"lastFetchStatus": lastFetchStatus, @"isDeveloperModeEnabled": @(isDeveloperModeEnabled), @"lastFetchTime": @(round([lastFetchTime timeIntervalSince1970] * 1000.0)), + @"minimumFetchInterval": @(minimumFetchInterval) }; } diff --git a/packages/remote-config/lib/index.d.ts b/packages/remote-config/lib/index.d.ts index 4e002e9df5..bb122a1019 100644 --- a/packages/remote-config/lib/index.d.ts +++ b/packages/remote-config/lib/index.d.ts @@ -242,6 +242,10 @@ export namespace FirebaseRemoteConfigTypes { * experience. */ isDeveloperModeEnabled: boolean; + /** + * The time that remote config should cache flags for. + */ + minimumFetchInterval?: number; } /** diff --git a/packages/remote-config/lib/index.js b/packages/remote-config/lib/index.js index 9ff6fac55a..0ae0887d35 100644 --- a/packages/remote-config/lib/index.js +++ b/packages/remote-config/lib/index.js @@ -119,6 +119,10 @@ class FirebaseConfigModule extends FirebaseModule { return this._isDeveloperModeEnabled; } + get minimumFetchInterval() { + return this._minimumFetchInterval; + } + setConfigSettings(settings = {}) { if (!isObject(settings) || !hasOwnProperty(settings, 'isDeveloperModeEnabled')) { throw new Error( @@ -132,6 +136,15 @@ class FirebaseConfigModule extends FirebaseModule { ); } + if ( + hasOwnProperty(settings, 'minimumFetchInterval') && + !isNumber(settings.minimumFetchInterval) + ) { + throw new Error( + "firebase.remoteConfig().setConfigSettings(): 'settings.minimumFetchInterval' must be a number value.", + ); + } + return this._promiseWithConstants(this.native.setConfigSettings(settings)); } @@ -197,6 +210,7 @@ class FirebaseConfigModule extends FirebaseModule { this._lastFetchStatus = constants.lastFetchStatus; this._values = convertNativeConfigValues(constants.values); this._isDeveloperModeEnabled = constants.isDeveloperModeEnabled; + this._minimumFetchInterval = constants.minimumFetchInterval; } _promiseWithConstants(promise) { diff --git a/packages/remote-config/lib/index.js.flow b/packages/remote-config/lib/index.js.flow index 366047229c..e0d2e82393 100644 --- a/packages/remote-config/lib/index.js.flow +++ b/packages/remote-config/lib/index.js.flow @@ -204,6 +204,10 @@ export interface ConfigSettings { * experience. */ isDeveloperModeEnabled: boolean; + /** + * The time that remote config should cache flags for. + */ + minimumFetchInterval?: number; } /**