diff --git a/lib/index.d.ts b/lib/index.d.ts index 4a143322..e4e222b6 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1511,7 +1511,7 @@ declare module 'react-native-firebase' { * The default duration is 43200 seconds (12 hours). * To force a cache refresh call the method with a duration of 0. */ - fetch(duration?: number): Promise; + fetch(duration?: number): Promise; /** * Fetches the remote config data from Firebase, defined in the dashboard. @@ -1536,6 +1536,11 @@ declare module 'react-native-firebase' { */ getKeysByPrefix(prefix?: string): Promise>; + /** + * Sets config defaults for parameter keys and values in the default namespace config. + */ + setDefault(defaults: Object): void; + /** * Sets the default values from a resource: * - Android: Id for the XML resource, which should be in your application's res/xml folder. diff --git a/lib/modules/config/index.js b/lib/modules/config/index.js index 05511262..aa5e8a42 100644 --- a/lib/modules/config/index.js +++ b/lib/modules/config/index.js @@ -22,6 +22,11 @@ type NativeValue = { export const MODULE_NAME = 'RNFirebaseRemoteConfig'; export const NAMESPACE = 'config'; +type ConfigSnapshot = { + source: string, + val(): any, +}; + /** * @class Config */ @@ -44,7 +49,7 @@ export default class RemoteConfig extends ModuleBase { * @returns {*} * @private */ - _nativeValueToJS(nativeValue: NativeValue) { + _nativeValueToJS(nativeValue: NativeValue): ConfigSnapshot { return { source: nativeValue.source, val() { @@ -89,7 +94,7 @@ export default class RemoteConfig extends ModuleBase { * Call activateFetched to make fetched data available in app * @returns {*|Promise.}: */ - fetch(expiration?: number) { + fetch(expiration?: number): Promise { if (expiration !== undefined) { getLogger(this).debug( `Fetching remote config data with expiration ${expiration.toString()}` @@ -106,7 +111,7 @@ export default class RemoteConfig extends ModuleBase { * resolves if there was a Fetched Config, and it was activated, * rejects if no Fetched Config was found, or the Fetched Config was already activated. */ - activateFetched() { + activateFetched(): Promise { getLogger(this).debug('Activating remote config'); return getNativeModule(this).activateFetched(); } @@ -124,7 +129,7 @@ export default class RemoteConfig extends ModuleBase { * "source" : OneOf(remoteConfigSourceRemote|remoteConfigSourceDefault|remoteConfigSourceStatic) * } */ - getValue(key: string) { + getValue(key: string): Promise { return getNativeModule(this) .getValue(key || '') .then(this._nativeValueToJS); @@ -144,7 +149,7 @@ export default class RemoteConfig extends ModuleBase { * "source" : OneOf(remoteConfigSourceRemote|remoteConfigSourceDefault|remoteConfigSourceStatic) * } */ - getValues(keys: Array) { + getValues(keys: Array): Promise<{ [string]: ConfigSnapshot }> { return getNativeModule(this) .getValues(keys || []) .then(nativeValues => { @@ -161,7 +166,7 @@ export default class RemoteConfig extends ModuleBase { * @param prefix: The key prefix to look for. If prefix is nil or empty, returns all the keys. * @returns {*|Promise.>} */ - getKeysByPrefix(prefix?: string) { + getKeysByPrefix(prefix?: string): Promise { return getNativeModule(this).getKeysByPrefix(prefix); } @@ -169,7 +174,7 @@ export default class RemoteConfig extends ModuleBase { * Sets config defaults for parameter keys and values in the default namespace config. * @param defaults: A dictionary mapping a String key to a Object values. */ - setDefaults(defaults: Object) { + setDefaults(defaults: Object): void { getNativeModule(this).setDefaults(defaults); } @@ -177,7 +182,7 @@ export default class RemoteConfig extends ModuleBase { * Sets default configs from plist for default namespace; * @param resource: The plist file name or resource ID */ - setDefaultsFromResource(resource: string | number) { + setDefaultsFromResource(resource: string | number): void { getNativeModule(this).setDefaultsFromResource(resource); } }