diff --git a/packages/remote-config/__tests__/remote-config.test.ts b/packages/remote-config/__tests__/remote-config.test.ts index 7833701b3a..da29f7dc25 100644 --- a/packages/remote-config/__tests__/remote-config.test.ts +++ b/packages/remote-config/__tests__/remote-config.test.ts @@ -16,7 +16,30 @@ */ import { describe, expect, it } from '@jest/globals'; -import { firebase } from '../lib'; +import { + firebase, + getRemoteConfig, + activate, + ensureInitialized, + fetchAndActivate, + fetchConfig, + getAll, + getBoolean, + getNumber, + getString, + getValue, + setLogLevel, + isSupported, + fetchTimeMillis, + settings, + lastFetchStatus, + reset, + setConfigSettings, + fetch, + setDefaults, + setDefaultsFromResource, + onConfigUpdated, +} from '../lib'; describe('remoteConfig()', function () { describe('namespace', function () { @@ -108,4 +131,90 @@ describe('remoteConfig()', function () { expect(config).toEqual({}); }); }); + + describe('modular', function () { + it('`getRemoteConfig` function is properly exposed to end user', function () { + expect(getRemoteConfig).toBeDefined(); + }); + + it('`activate` function is properly exposed to end user', function () { + expect(activate).toBeDefined(); + }); + + it('`ensureInitialized` function is properly exposed to end user', function () { + expect(ensureInitialized).toBeDefined(); + }); + + it('`fetchAndActivate` function is properly exposed to end user', function () { + expect(fetchAndActivate).toBeDefined(); + }); + + it('`fetchConfig` function is properly exposed to end user', function () { + expect(fetchConfig).toBeDefined(); + }); + + it('`getAll` function is properly exposed to end user', function () { + expect(getAll).toBeDefined(); + }); + + it('`getBoolean` function is properly exposed to end user', function () { + expect(getBoolean).toBeDefined(); + }); + + it('`getNumber` function is properly exposed to end user', function () { + expect(getNumber).toBeDefined(); + }); + + it('`getString` function is properly exposed to end user', function () { + expect(getString).toBeDefined(); + }); + + it('`getValue` function is properly exposed to end user', function () { + expect(getValue).toBeDefined(); + }); + + it('`setLogLevel` function is properly exposed to end user', function () { + expect(setLogLevel).toBeDefined(); + }); + + it('`isSupported` function is properly exposed to end user', function () { + expect(isSupported).toBeDefined(); + }); + + it('`fetchTimeMillis` function is properly exposed to end user', function () { + expect(fetchTimeMillis).toBeDefined(); + }); + + it('`settings` function is properly exposed to end user', function () { + expect(settings).toBeDefined(); + }); + + it('`lastFetchStatus` function is properly exposed to end user', function () { + expect(lastFetchStatus).toBeDefined(); + }); + + it('`reset` function is properly exposed to end user', function () { + expect(reset).toBeDefined(); + }); + + it('`setConfigSettings` function is properly exposed to end user', function () { + expect(setConfigSettings).toBeDefined(); + }); + + it('`fetch` function is properly exposed to end user', function () { + expect(fetch).toBeDefined(); + }); + + it('`setDefaults` function is properly exposed to end user', function () { + expect(setDefaults).toBeDefined(); + }); + + it('`setDefaultsFromResource` function is properly exposed to end user', function () { + expect(setDefaultsFromResource).toBeDefined(); + }); + + it('`onConfigUpdated` function is properly exposed to end user', function () { + expect(onConfigUpdated).toBeDefined(); + }); + }); }); diff --git a/packages/remote-config/lib/index.d.ts b/packages/remote-config/lib/index.d.ts index 0427776d0e..fddd3eb430 100644 --- a/packages/remote-config/lib/index.d.ts +++ b/packages/remote-config/lib/index.d.ts @@ -567,6 +567,8 @@ type OnConfigUpdatedListenerCallback = ( export default defaultExport; +export * from './modular'; + /** * Attach namespace to `firebase.` and `FirebaseApp.`. */ diff --git a/packages/remote-config/lib/index.js b/packages/remote-config/lib/index.js index 1505711e03..f049d6f19c 100644 --- a/packages/remote-config/lib/index.js +++ b/packages/remote-config/lib/index.js @@ -33,30 +33,6 @@ import { setReactNativeModule } from '@react-native-firebase/app/lib/internal/na import fallBackModule from './web/RNFBConfigModule'; import version from './version'; -export { - getRemoteConfig, - activate, - ensureInitialized, - fetchAndActivate, - fetchConfig, - getAll, - getBoolean, - getNumber, - getString, - getValue, - setLogLevel, - isSupported, - fetchTimeMillis, - settings, - lastFetchStatus, - reset, - setConfigSettings, - fetch, - setDefaults, - setDefaultsFromResource, - onConfigUpdated, -} from './modular/index'; - const statics = { LastFetchStatus: { SUCCESS: 'success', @@ -368,6 +344,8 @@ export default createModuleNamespace({ ModuleClass: FirebaseConfigModule, }); +export * from './modular'; + // import config, { firebase } from '@react-native-firebase/remote-config'; // config().X(...); // firebase.remoteConfig().X(...); diff --git a/packages/remote-config/lib/modular/index.d.ts b/packages/remote-config/lib/modular/index.d.ts new file mode 100644 index 0000000000..e5fa82c8a6 --- /dev/null +++ b/packages/remote-config/lib/modular/index.d.ts @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2016-present Invertase Limited & Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this library except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +import { FirebaseApp } from '@firebase/app-types'; +import { FirebaseRemoteConfigTypes } from '..'; + +import RemoteConfig = FirebaseRemoteConfigTypes.Module; +import ConfigValues = FirebaseRemoteConfigTypes.ConfigValues; +import ConfigValue = FirebaseRemoteConfigTypes.ConfigValue; +import ConfigDefaults = FirebaseRemoteConfigTypes.ConfigDefaults; +import ConfigSettings = FirebaseRemoteConfigTypes.ConfigSettings; +import LastFetchStatusType = FirebaseRemoteConfigTypes.LastFetchStatusType; +import RemoteConfigLogLevel = FirebaseRemoteConfigTypes.RemoteConfigLogLevel; + +/** + * Returns a RemoteConfig instance for the given app. + * @param app - FirebaseApp. Optional. + * @returns {RemoteConfig} + */ +export function getRemoteConfig(app?: FirebaseApp): RemoteConfig; + +/** + * Returns a Boolean which resolves to true if the current call + * activated the fetched configs. + * @param remoteConfig - RemoteConfig instance + * @returns {Promise} + */ +export function activate(remoteConfig: RemoteConfig): Promise; + +/** + * Ensures the last activated config are available to the getters. + * @param remoteConfig - RemoteConfig instance + * @returns {Promise} + */ +export function ensureInitialized(remoteConfig: RemoteConfig): Promise; + +/** + * Performs a fetch and returns a Boolean which resolves to true + * if the current call activated the fetched configs. + * @param remoteConfig - RemoteConfig instance + * @returns {Promise} + */ +export function fetchAndActivate(remoteConfig: RemoteConfig): Promise; + +/** + * Fetches and caches configuration from the Remote Config service. + * @param remoteConfig - RemoteConfig instance + * @returns {Promise} + */ +export function fetchConfig(remoteConfig: RemoteConfig): Promise; + +/** + * Gets all config. + * @param remoteConfig - RemoteConfig instance + * @returns {ConfigValues} + */ +export function getAll(remoteConfig: RemoteConfig): ConfigValues; + +/** + * Gets the value for the given key as a boolean. + * @param remoteConfig - RemoteConfig instance + * @param key - key for boolean value + * @returns {boolean} + */ +export function getBoolean(remoteConfig: RemoteConfig, key: string): boolean; + +/** + * Gets the value for the given key as a number. + * @param remoteConfig - RemoteConfig instance + * @param key - key for number value + * @returns {number} + */ +export function getNumber(remoteConfig: RemoteConfig, key: string): number; + +/** + * Gets the value for the given key as a string. + * @param remoteConfig - RemoteConfig instance + * @param key - key for string value + * @returns {string} + */ +export function getString(remoteConfig: RemoteConfig, key: string): string; + +/** + * Gets the value for the given key + * @param remoteConfig - RemoteConfig instance + * @param key - key for the given value + * @returns {ConfigValue} + */ +export function getValue(remoteConfig: RemoteConfig, key: string): ConfigValue; + +/** + * Defines the log level to use. + * @param remoteConfig - RemoteConfig instance + * @param logLevel - The log level to set + * @returns {RemoteConfigLogLevel} + */ +export function setLogLevel( + remoteConfig: RemoteConfig, + logLevel: RemoteConfigLogLevel, +): RemoteConfigLogLevel; + +/** + * Checks two different things. + * 1. Check if IndexedDB exists in the browser environment. + * 2. Check if the current browser context allows IndexedDB open() calls. + * @returns {Promise} + */ +export function isSupported(): Promise; + +/** + * Indicates the default value in milliseconds to abandon a pending fetch + * request made to the Remote Config server. Defaults to 60000 (One minute). + * @param remoteConfig - RemoteConfig instance + * @returns {number} + */ +export function fetchTimeMillis(remoteConfig: RemoteConfig): number; + +/** + * Returns a ConfigSettings object which provides the properties `minimumFetchIntervalMillis` & `fetchTimeMillis` if they have been set + * using setConfigSettings({ fetchTimeMillis: number, minimumFetchIntervalMillis: number }). + * @param remoteConfig - RemoteConfig instance + * @returns {ConfigSettings} + */ +export function settings(remoteConfig: RemoteConfig): ConfigSettings; + +/** + * The status of the latest Remote RemoteConfig fetch action. + * @param remoteConfig - RemoteConfig instance + * @returns {LastFetchStatusType} + */ +export function lastFetchStatus(remoteConfig: RemoteConfig): LastFetchStatusType; + +/** + * Deletes all activated, fetched and defaults configs and + * resets all Firebase Remote Config settings. + * Android only. iOS does not reset anything. + * @param remoteConfig - RemoteConfig instance + * @returns {Promise} + */ +export function reset(remoteConfig: RemoteConfig): Promise; + +/** + * Set the Remote RemoteConfig settings, currently able to set + * `fetchTimeMillis` & `minimumFetchIntervalMillis` + * Android only. iOS does not reset anything. + * @param remoteConfig - RemoteConfig instance + * @param settings - ConfigSettings instance + * @returns {Promise} + */ +export function setConfigSettings( + remoteConfig: RemoteConfig, + settings: ConfigSettings, +): Promise; + +/** + * Fetches parameter values for your app. + * @param remoteConfig - RemoteConfig instance + * @param expirationDurationSeconds - number + * @returns {Promise} + */ +export function fetch( + remoteConfig: RemoteConfig, + expirationDurationSeconds?: number, +): Promise; + +/** + * Fetches parameter values for your app. + * @param remoteConfig - RemoteConfig instance + * @param defaults - ConfigDefaults + * @returns {Promise} + */ +export function setDefaults(remoteConfig: RemoteConfig, defaults: ConfigDefaults): Promise; + +/** + * Fetches parameter values for your app. + * @param remoteConfig - RemoteConfig instance + * @param resourceName - string + * @returns {Promise} + */ +export function setDefaultsFromResource( + remoteConfig: RemoteConfig, + resourceName: string, +): Promise; + +/** + * Registers a listener to changes in the configuration. + * + * @param remoteConfig - RemoteConfig instance + * @param callback - function called on config change + * @returns {function} unsubscribe listener + */ +export function onConfigUpdated( + remoteConfig: RemoteConfig, + callback: (config: ConfigValues) => void, +): () => void; diff --git a/packages/remote-config/lib/modular/index.js b/packages/remote-config/lib/modular/index.js index ce9ce7714c..a2931bd210 100644 --- a/packages/remote-config/lib/modular/index.js +++ b/packages/remote-config/lib/modular/index.js @@ -17,9 +17,20 @@ import { firebase } from '..'; +/** + * @typedef {import('@firebase/app').FirebaseApp} FirebaseApp + * @typedef {import('..').FirebaseRemoteConfigTypes.Module} RemoteConfig + * @typedef {import('..').FirebaseRemoteConfigTypes.ConfigDefaults} ConfigDefaults + * @typedef {import('..').FirebaseRemoteConfigTypes.ConfigSettings} ConfigSettings + * @typedef {import('..').FirebaseRemoteConfigTypes.ConfigValue} ConfigValue + * @typedef {import('..').FirebaseRemoteConfigTypes.ConfigValues} ConfigValues + * @typedef {import('..').FirebaseRemoteConfigTypes.LastFetchStatusType} LastFetchStatusType + * @typedef {import('..').FirebaseRemoteConfigTypes.RemoteConfigLogLevel} RemoteConfigLogLevel + */ + /** * Returns a RemoteConfig instance for the given app. - * @param app - FirebaseApp. Optional. + * @param {FirebaseApp} [app] - FirebaseApp. Optional. * @returns {RemoteConfig} */ export function getRemoteConfig(app) { @@ -33,7 +44,7 @@ export function getRemoteConfig(app) { /** * Returns a Boolean which resolves to true if the current call * activated the fetched configs. - * @param remoteConfig - RemoteConfig instance + * @param {RemoteConfig} remoteConfig - RemoteConfig instance * @returns {Promise} */ export function activate(remoteConfig) { @@ -42,7 +53,7 @@ export function activate(remoteConfig) { /** * Ensures the last activated config are available to the getters. - * @param remoteConfig - RemoteConfig instance + * @param {RemoteConfig} remoteConfig - RemoteConfig instance * @returns {Promise} */ export function ensureInitialized(remoteConfig) { @@ -52,7 +63,7 @@ export function ensureInitialized(remoteConfig) { /** * Performs a fetch and returns a Boolean which resolves to true * if the current call activated the fetched configs. - * @param remoteConfig - RemoteConfig instance + * @param {RemoteConfig} remoteConfig - RemoteConfig instance * @returns {Promise} */ export function fetchAndActivate(remoteConfig) { @@ -61,7 +72,7 @@ export function fetchAndActivate(remoteConfig) { /** * Fetches and caches configuration from the Remote Config service. - * @param remoteConfig - RemoteConfig instance + * @param {RemoteConfig} remoteConfig - RemoteConfig instance * @returns {Promise} */ export function fetchConfig(remoteConfig) { @@ -70,8 +81,8 @@ export function fetchConfig(remoteConfig) { /** * Gets all config. - * @param remoteConfig - RemoteConfig instance - * @returns {Promise} + * @param {RemoteConfig} remoteConfig - RemoteConfig instance + * @returns {ConfigValues} */ export function getAll(remoteConfig) { return remoteConfig.getAll(); @@ -79,8 +90,8 @@ export function getAll(remoteConfig) { /** * Gets the value for the given key as a boolean. - * @param remoteConfig - RemoteConfig instance - * @param key - key for boolean value + * @param {RemoteConfig} remoteConfig - RemoteConfig instance + * @param {string} key - key for boolean value * @returns {boolean} */ export function getBoolean(remoteConfig, key) { @@ -89,8 +100,8 @@ export function getBoolean(remoteConfig, key) { /** * Gets the value for the given key as a number. - * @param remoteConfig - RemoteConfig instance - * @param key - key for number value + * @param {RemoteConfig} remoteConfig - RemoteConfig instance + * @param {string} key - key for number value * @returns {number} */ export function getNumber(remoteConfig, key) { @@ -99,8 +110,8 @@ export function getNumber(remoteConfig, key) { /** * Gets the value for the given key as a string. - * @param remoteConfig - RemoteConfig instance - * @param key - key for string value + * @param {RemoteConfig} remoteConfig - RemoteConfig instance + * @param {string} key - key for string value * @returns {string} */ export function getString(remoteConfig, key) { @@ -109,8 +120,8 @@ export function getString(remoteConfig, key) { /** * Gets the value for the given key - * @param remoteConfig - RemoteConfig instance - * @param key - key for the given value + * @param {RemoteConfig} remoteConfig - RemoteConfig instance + * @param {string} key - key for the given value * @returns {ConfigValue} */ export function getValue(remoteConfig, key) { @@ -119,8 +130,8 @@ export function getValue(remoteConfig, key) { /** * Defines the log level to use. - * @param remoteConfig - RemoteConfig instance - * @param logLevel - The log level to set + * @param {RemoteConfig} remoteConfig - RemoteConfig instance + * @param {RemoteConfigLogLevel} logLevel - The log level to set * @returns {RemoteConfigLogLevel} */ // eslint-disable-next-line @@ -143,7 +154,7 @@ export function isSupported() { /** * Indicates the default value in milliseconds to abandon a pending fetch * request made to the Remote Config server. Defaults to 60000 (One minute). - * @param remoteConfig - RemoteConfig instance + * @param {RemoteConfig} remoteConfig - RemoteConfig instance * @returns {number} */ export function fetchTimeMillis(remoteConfig) { @@ -153,7 +164,7 @@ export function fetchTimeMillis(remoteConfig) { /** * Returns a ConfigSettings object which provides the properties `minimumFetchIntervalMillis` & `fetchTimeMillis` if they have been set * using setConfigSettings({ fetchTimeMillis: number, minimumFetchIntervalMillis: number }). - * @param remoteConfig - RemoteConfig instance + * @param {RemoteConfig} remoteConfig - RemoteConfig instance * @returns {ConfigSettings} */ export function settings(remoteConfig) { @@ -162,7 +173,7 @@ export function settings(remoteConfig) { /** * The status of the latest Remote RemoteConfig fetch action. - * @param remoteConfig - RemoteConfig instance + * @param {RemoteConfig} remoteConfig - RemoteConfig instance * @returns {LastFetchStatusType} */ export function lastFetchStatus(remoteConfig) { @@ -173,7 +184,7 @@ export function lastFetchStatus(remoteConfig) { * Deletes all activated, fetched and defaults configs and * resets all Firebase Remote Config settings. * Android only. iOS does not reset anything. - * @param remoteConfig - RemoteConfig instance + * @param {RemoteConfig} remoteConfig - RemoteConfig instance * @returns {Promise} */ export function reset(remoteConfig) { @@ -184,8 +195,8 @@ export function reset(remoteConfig) { * Set the Remote RemoteConfig settings, currently able to set * `fetchTimeMillis` & `minimumFetchIntervalMillis` * Android only. iOS does not reset anything. - * @param remoteConfig - RemoteConfig instance - * @param settings - ConfigSettings instance + * @param {RemoteConfig} remoteConfig - RemoteConfig instance + * @param {ConfigSettings} settings - ConfigSettings instance * @returns {Promise} */ export function setConfigSettings(remoteConfig, settings) { @@ -194,8 +205,8 @@ export function setConfigSettings(remoteConfig, settings) { /** * Fetches parameter values for your app. - * @param remoteConfig - RemoteConfig instance - * @param expirationDurationSeconds - number + * @param {RemoteConfig} remoteConfig - RemoteConfig instance + * @param {number} expirationDurationSeconds - number * @returns {Promise} */ export function fetch(remoteConfig, expirationDurationSeconds) { @@ -204,8 +215,8 @@ export function fetch(remoteConfig, expirationDurationSeconds) { /** * Fetches parameter values for your app. - * @param remoteConfig - RemoteConfig instance - * @param defaults - ConfigDefaults + * @param {RemoteConfig} remoteConfig - RemoteConfig instance + * @param {ConfigDefaults} defaults - ConfigDefaults * @returns {Promise} */ export function setDefaults(remoteConfig, defaults) { @@ -214,8 +225,8 @@ export function setDefaults(remoteConfig, defaults) { /** * Fetches parameter values for your app. - * @param remoteConfig - RemoteConfig instance - * @param resourceName - string + * @param {RemoteConfig} remoteConfig - RemoteConfig instance + * @param {string} resourceName - string * @returns {Promise} */ export function setDefaultsFromResource(remoteConfig, resourceName) { @@ -225,8 +236,8 @@ export function setDefaultsFromResource(remoteConfig, resourceName) { /** * Registers a listener to changes in the configuration. * - * @param remoteConfig - RemoteConfig instance - * @param callback - function called on config change + * @param {RemoteConfig} remoteConfig - RemoteConfig instance + * @param {function(ConfigValues): void} callback - function called on config change * @returns {function} unsubscribe listener */ export function onConfigUpdated(remoteConfig, callback) {