From fe52ab2ae475cb7421a97fcbc395fb9ae121a7a6 Mon Sep 17 00:00:00 2001 From: MichaelVerdon Date: Mon, 16 Jun 2025 13:38:11 +0100 Subject: [PATCH] chore(remote-config): deprecations for next major release --- packages/app/lib/common/index.js | 25 +++ .../__tests__/remote-config.test.ts | 187 +++++++++++++++++- packages/remote-config/e2e/config.e2e.js | 4 +- packages/remote-config/lib/modular/index.js | 48 +++-- 4 files changed, 242 insertions(+), 22 deletions(-) diff --git a/packages/app/lib/common/index.js b/packages/app/lib/common/index.js index e979845e17..152a77d254 100644 --- a/packages/app/lib/common/index.js +++ b/packages/app/lib/common/index.js @@ -337,6 +337,28 @@ const mapOfDeprecationReplacements = { nanoseconds: NO_REPLACEMENT, }, }, + remoteConfig: { + default: { + activate: 'activate()', + ensureInitialized: 'ensureInitialized()', + fetchAndActivate: 'fetchAndActivate()', + getAll: 'getAll()', + getBoolean: 'getBoolean()', + getNumber: 'getNumber()', + getString: 'getString()', + getValue: 'getValue()', + reset: 'reset()', + setConfigSettings: 'setConfigSettings()', + fetch: 'fetch()', + setDefaults: 'setDefaults()', + setDefaultsFromResource: 'setDefaultsFromResource()', + onConfigUpdated: 'onConfigUpdated()', + }, + statics: { + LastFetchStatus: 'LastFetchStatus', + ValueSource: 'ValueSource', + }, + }, storage: { default: { useEmulator: 'connectStorageEmulator()', @@ -493,6 +515,9 @@ export function createDeprecationProxy(instance) { ) { deprecationConsoleWarning('firestore', prop, 'statics', false); } + if (prop === 'LastFetchStatus' || prop === 'ValueSource') { + deprecationConsoleWarning('remoteConfig', prop, 'statics', false); + } if (prop === 'CustomProvider') { deprecationConsoleWarning('appCheck', prop, 'statics', false); } diff --git a/packages/remote-config/__tests__/remote-config.test.ts b/packages/remote-config/__tests__/remote-config.test.ts index 14c5648bc6..6013bd36a2 100644 --- a/packages/remote-config/__tests__/remote-config.test.ts +++ b/packages/remote-config/__tests__/remote-config.test.ts @@ -14,7 +14,7 @@ * limitations under the License. * */ -import { afterAll, beforeAll, describe, expect, it } from '@jest/globals'; +import { afterAll, beforeAll, describe, expect, it, beforeEach, jest } from '@jest/globals'; import { firebase, @@ -44,6 +44,14 @@ import { ValueSource, } from '../lib'; +import { + createCheckV9Deprecation, + CheckV9DeprecationFunction, +} from '../../app/lib/common/unitTestUtils'; + +// @ts-ignore test +import FirebaseModule from '../../app/lib/internal/FirebaseModule'; + describe('remoteConfig()', function () { describe('namespace', function () { beforeAll(async function () { @@ -246,5 +254,182 @@ describe('remoteConfig()', function () { expect(ValueSource.REMOTE).toBeDefined(); expect(ValueSource.STATIC).toBeDefined(); }); + + describe('test `console.warn` is called for RNFB v8 API & not called for v9 API', function () { + let remoteConfigV9Deprecation: CheckV9DeprecationFunction; + let staticsV9Deprecation: CheckV9DeprecationFunction; + + beforeEach(function () { + remoteConfigV9Deprecation = createCheckV9Deprecation(['remoteConfig']); + + staticsV9Deprecation = createCheckV9Deprecation(['remoteConfig', 'statics']); + + // @ts-ignore test + jest.spyOn(FirebaseModule.prototype, 'native', 'get').mockImplementation(() => { + return new Proxy( + {}, + { + get: () => + jest.fn().mockResolvedValue({ + result: true, + constants: { + lastFetchTime: Date.now(), + lastFetchStatus: 'success', + fetchTimeout: 60, + minimumFetchInterval: 12, + values: {}, + }, + } as never), + }, + ); + }); + }); + + describe('remoteConfig functions', function () { + it('activate()', function () { + const remoteConfig = getRemoteConfig(); + remoteConfigV9Deprecation( + () => activate(remoteConfig), + () => remoteConfig.activate(), + 'activate', + ); + }); + + it('ensureInitialized()', function () { + const remoteConfig = getRemoteConfig(); + remoteConfigV9Deprecation( + () => ensureInitialized(remoteConfig), + () => remoteConfig.ensureInitialized(), + 'ensureInitialized', + ); + }); + + it('fetchAndActivate()', function () { + const remoteConfig = getRemoteConfig(); + remoteConfigV9Deprecation( + () => fetchAndActivate(remoteConfig), + () => remoteConfig.fetchAndActivate(), + 'fetchAndActivate', + ); + }); + + it('getAll()', function () { + const remoteConfig = getRemoteConfig(); + remoteConfigV9Deprecation( + () => getAll(remoteConfig), + () => remoteConfig.getAll(), + 'getAll', + ); + }); + + it('getBoolean()', function () { + const remoteConfig = getRemoteConfig(); + remoteConfigV9Deprecation( + () => getBoolean(remoteConfig, 'foo'), + () => remoteConfig.getBoolean('foo'), + 'getBoolean', + ); + }); + + it('getNumber()', function () { + const remoteConfig = getRemoteConfig(); + remoteConfigV9Deprecation( + () => getNumber(remoteConfig, 'foo'), + () => remoteConfig.getNumber('foo'), + 'getNumber', + ); + }); + + it('getString()', function () { + const remoteConfig = getRemoteConfig(); + remoteConfigV9Deprecation( + () => getString(remoteConfig, 'foo'), + () => remoteConfig.getString('foo'), + 'getString', + ); + }); + + it('getValue()', function () { + const remoteConfig = getRemoteConfig(); + remoteConfigV9Deprecation( + () => getValue(remoteConfig, 'foo'), + () => remoteConfig.getValue('foo'), + 'getValue', + ); + }); + + it('reset()', function () { + const remoteConfig = getRemoteConfig(); + remoteConfigV9Deprecation( + () => reset(remoteConfig), + () => remoteConfig.reset(), + 'reset', + ); + }); + + it('setConfigSettings()', function () { + const remoteConfig = getRemoteConfig(); + remoteConfigV9Deprecation( + () => setConfigSettings(remoteConfig, { minimumFetchIntervalMillis: 12 }), + () => remoteConfig.setConfigSettings({ minimumFetchIntervalMillis: 12 }), + 'setConfigSettings', + ); + }); + + it('fetch()', function () { + const remoteConfig = getRemoteConfig(); + remoteConfigV9Deprecation( + () => fetch(remoteConfig, 12), + () => remoteConfig.fetch(12), + 'fetch', + ); + }); + + it('setDefaults()', function () { + const remoteConfig = getRemoteConfig(); + remoteConfigV9Deprecation( + () => setDefaults(remoteConfig, { foo: 'bar' }), + () => remoteConfig.setDefaults({ foo: 'bar' }), + 'setDefaults', + ); + }); + + it('setDefaultsFromResource()', function () { + const remoteConfig = getRemoteConfig(); + remoteConfigV9Deprecation( + () => setDefaultsFromResource(remoteConfig, 'foo'), + () => remoteConfig.setDefaultsFromResource('foo'), + 'setDefaultsFromResource', + ); + }); + + it('onConfigUpdated()', function () { + const remoteConfig = getRemoteConfig(); + remoteConfigV9Deprecation( + () => onConfigUpdated(remoteConfig, () => {}), + () => remoteConfig.onConfigUpdated(() => {}), + 'onConfigUpdated', + ); + }); + }); + + describe('statics', function () { + it('LastFetchStatus', function () { + staticsV9Deprecation( + () => LastFetchStatus.FAILURE, + () => firebase.remoteConfig.LastFetchStatus.FAILURE, + 'LastFetchStatus', + ); + }); + + it('ValueSource', function () { + staticsV9Deprecation( + () => ValueSource.DEFAULT, + () => firebase.remoteConfig.ValueSource.DEFAULT, + 'ValueSource', + ); + }); + }); + }); }); }); diff --git a/packages/remote-config/e2e/config.e2e.js b/packages/remote-config/e2e/config.e2e.js index b6532511d9..7498a2e202 100644 --- a/packages/remote-config/e2e/config.e2e.js +++ b/packages/remote-config/e2e/config.e2e.js @@ -379,7 +379,7 @@ describe('remoteConfig()', function () { describe('fetch()', function () { it('with expiration provided', async function () { - const { getRemoteConfig, ensureInitialized, fetch } = remoteConfigModular; + const { getRemoteConfig, ensureInitialized, fetch, LastFetchStatus } = remoteConfigModular; const date = Date.now() - 30000; const remoteConfig = getRemoteConfig(); await ensureInitialized(remoteConfig); @@ -390,7 +390,7 @@ describe('remoteConfig()', function () { } await fetch(remoteConfig, 0); - remoteConfig.lastFetchStatus.should.equal(firebase.remoteConfig.LastFetchStatus.SUCCESS); + remoteConfig.lastFetchStatus.should.equal(LastFetchStatus.SUCCESS); should.equal(getRemoteConfig().fetchTimeMillis >= date, true); }); diff --git a/packages/remote-config/lib/modular/index.js b/packages/remote-config/lib/modular/index.js index 6aa495bded..a217116486 100644 --- a/packages/remote-config/lib/modular/index.js +++ b/packages/remote-config/lib/modular/index.js @@ -17,6 +17,8 @@ import { getApp } from '@react-native-firebase/app'; +import { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/lib/common'; + /** * @typedef {import('@firebase/app').FirebaseApp} FirebaseApp * @typedef {import('..').FirebaseRemoteConfigTypes.Module} RemoteConfig @@ -49,7 +51,7 @@ export function getRemoteConfig(app) { * @returns {Promise} */ export function activate(remoteConfig) { - return remoteConfig.activate(); + return remoteConfig.activate.call(remoteConfig, MODULAR_DEPRECATION_ARG); } /** @@ -58,7 +60,7 @@ export function activate(remoteConfig) { * @returns {Promise} */ export function ensureInitialized(remoteConfig) { - return remoteConfig.ensureInitialized(); + return remoteConfig.ensureInitialized.call(remoteConfig, MODULAR_DEPRECATION_ARG); } /** @@ -68,7 +70,7 @@ export function ensureInitialized(remoteConfig) { * @returns {Promise} */ export function fetchAndActivate(remoteConfig) { - return remoteConfig.fetchAndActivate(); + return remoteConfig.fetchAndActivate.call(remoteConfig, MODULAR_DEPRECATION_ARG); } /** @@ -77,7 +79,7 @@ export function fetchAndActivate(remoteConfig) { * @returns {Promise} */ export function fetchConfig(remoteConfig) { - return remoteConfig.fetchConfig(); + return remoteConfig.fetchConfig.call(remoteConfig, MODULAR_DEPRECATION_ARG); } /** @@ -86,7 +88,7 @@ export function fetchConfig(remoteConfig) { * @returns {ConfigValues} */ export function getAll(remoteConfig) { - return remoteConfig.getAll(); + return remoteConfig.getAll.call(remoteConfig, MODULAR_DEPRECATION_ARG); } /** @@ -96,7 +98,7 @@ export function getAll(remoteConfig) { * @returns {boolean} */ export function getBoolean(remoteConfig, key) { - return remoteConfig.getBoolean(key); + return remoteConfig.getBoolean.call(remoteConfig, key, MODULAR_DEPRECATION_ARG); } /** @@ -106,7 +108,7 @@ export function getBoolean(remoteConfig, key) { * @returns {number} */ export function getNumber(remoteConfig, key) { - return remoteConfig.getNumber(key); + return remoteConfig.getNumber.call(remoteConfig, key, MODULAR_DEPRECATION_ARG); } /** @@ -116,7 +118,7 @@ export function getNumber(remoteConfig, key) { * @returns {string} */ export function getString(remoteConfig, key) { - return remoteConfig.getString(key); + return remoteConfig.getString.call(remoteConfig, key, MODULAR_DEPRECATION_ARG); } /** @@ -126,7 +128,7 @@ export function getString(remoteConfig, key) { * @returns {ConfigValue} */ export function getValue(remoteConfig, key) { - return remoteConfig.getValue(key); + return remoteConfig.getValue.call(remoteConfig, key, MODULAR_DEPRECATION_ARG); } /** @@ -159,7 +161,7 @@ export function isSupported() { * @returns {number} */ export function fetchTimeMillis(remoteConfig) { - return remoteConfig.fetchTimeMillis; + return remoteConfig.fetchTimeMillis.call(remoteConfig, MODULAR_DEPRECATION_ARG); } /** @@ -169,7 +171,7 @@ export function fetchTimeMillis(remoteConfig) { * @returns {ConfigSettings} */ export function settings(remoteConfig) { - return remoteConfig.settings; + return remoteConfig.settings.call(remoteConfig, MODULAR_DEPRECATION_ARG); } /** @@ -178,7 +180,7 @@ export function settings(remoteConfig) { * @returns {LastFetchStatusType} */ export function lastFetchStatus(remoteConfig) { - return remoteConfig.lastFetchStatus; + return remoteConfig.lastFetchStatus.call(remoteConfig, MODULAR_DEPRECATION_ARG); } /** @@ -189,7 +191,7 @@ export function lastFetchStatus(remoteConfig) { * @returns {Promise} */ export function reset(remoteConfig) { - return remoteConfig.reset(); + return remoteConfig.reset.call(remoteConfig, MODULAR_DEPRECATION_ARG); } /** @@ -200,7 +202,7 @@ export function reset(remoteConfig) { * @returns {Promise} */ export function setConfigSettings(remoteConfig, settings) { - return remoteConfig.setConfigSettings(settings); + return remoteConfig.setConfigSettings.call(remoteConfig, settings, MODULAR_DEPRECATION_ARG); } /** @@ -210,7 +212,7 @@ export function setConfigSettings(remoteConfig, settings) { * @returns {Promise} */ export function fetch(remoteConfig, expirationDurationSeconds) { - return remoteConfig.fetch(expirationDurationSeconds); + return remoteConfig.fetch.call(remoteConfig, expirationDurationSeconds, MODULAR_DEPRECATION_ARG); } /** @@ -220,7 +222,7 @@ export function fetch(remoteConfig, expirationDurationSeconds) { * @returns {Promise} */ export function setDefaults(remoteConfig, defaults) { - return remoteConfig.setDefaults(defaults); + return remoteConfig.setDefaults.call(remoteConfig, defaults, MODULAR_DEPRECATION_ARG); } /** @@ -230,7 +232,11 @@ export function setDefaults(remoteConfig, defaults) { * @returns {Promise} */ export function setDefaultsFromResource(remoteConfig, resourceName) { - return remoteConfig.setDefaultsFromResource(resourceName); + return remoteConfig.setDefaultsFromResource.call( + remoteConfig, + resourceName, + MODULAR_DEPRECATION_ARG, + ); } /** @@ -241,7 +247,7 @@ export function setDefaultsFromResource(remoteConfig, resourceName) { * @returns {function} unsubscribe listener */ export function onConfigUpdated(remoteConfig, callback) { - return remoteConfig.onConfigUpdated(callback); + return remoteConfig.onConfigUpdated.call(remoteConfig, callback, MODULAR_DEPRECATION_ARG); } /** @@ -258,7 +264,11 @@ export async function setCustomSignals(remoteConfig, customSignals) { ); } } - return remoteConfig._promiseWithConstants(remoteConfig.native.setCustomSignals(customSignals)); + return remoteConfig._promiseWithConstants.call( + remoteConfig, + remoteConfig.native.setCustomSignals(customSignals), + MODULAR_DEPRECATION_ARG, + ); } export { LastFetchStatus, ValueSource } from '../statics';