@react-native-firebase/remote-config 20.1.0 → 20.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [20.2.0](https://github.com/invertase/react-native-firebase/compare/v20.1.0...v20.2.0) (2024-07-15)
7
+
8
+ ### Features
9
+
10
+ - **Other:** Add Remote Config support ([#7895](https://github.com/invertase/react-native-firebase/issues/7895)) ([a41e556](https://github.com/invertase/react-native-firebase/commit/a41e5568869320fb91afc01403ed402e5312e15c))
11
+
6
12
  ## [20.1.0](https://github.com/invertase/react-native-firebase/compare/v20.0.0...v20.1.0) (2024-06-04)
7
13
 
8
14
  **Note:** Version bump only for package @react-native-firebase/remote-config
package/lib/index.js CHANGED
@@ -29,8 +29,9 @@ import {
29
29
  FirebaseModule,
30
30
  getFirebaseRoot,
31
31
  } from '@react-native-firebase/app/lib/internal';
32
+ import { setReactNativeModule } from '@react-native-firebase/app/lib/internal/nativeModule';
33
+ import fallBackModule from './web/RNFBConfigModule';
32
34
  import version from './version';
33
- import { Platform } from 'react-native';
34
35
 
35
36
  export {
36
37
  getRemoteConfig,
@@ -84,7 +85,6 @@ class FirebaseConfigModule extends FirebaseModule {
84
85
  };
85
86
  this._lastFetchTime = -1;
86
87
  this._values = {};
87
- this._isWeb = Platform.OS !== 'ios' && Platform.OS !== 'android';
88
88
  this._configUpdateListenerCount = 0;
89
89
  }
90
90
 
@@ -178,14 +178,10 @@ class FirebaseConfigModule extends FirebaseModule {
178
178
 
179
179
  setConfigSettings(settings) {
180
180
  const updatedSettings = {};
181
- if (this._isWeb) {
182
- updatedSettings.fetchTimeMillis = this._settings.fetchTimeMillis;
183
- updatedSettings.minimumFetchIntervalMillis = this._settings.minimumFetchIntervalMillis;
184
- } else {
185
- //iOS & Android expect seconds & different property names
186
- updatedSettings.fetchTimeout = this._settings.fetchTimeMillis / 1000;
187
- updatedSettings.minimumFetchInterval = this._settings.minimumFetchIntervalMillis / 1000;
188
- }
181
+
182
+ updatedSettings.fetchTimeout = this._settings.fetchTimeMillis / 1000;
183
+ updatedSettings.minimumFetchInterval = this._settings.minimumFetchIntervalMillis / 1000;
184
+
189
185
  const apiCalled = arguments[1] == true ? 'settings' : 'setConfigSettings';
190
186
  if (!isObject(settings)) {
191
187
  throw new Error(`firebase.remoteConfig().${apiCalled}(*): settings must set an object.`);
@@ -197,11 +193,7 @@ class FirebaseConfigModule extends FirebaseModule {
197
193
  `firebase.remoteConfig().${apiCalled}(): 'settings.minimumFetchIntervalMillis' must be a number type in milliseconds.`,
198
194
  );
199
195
  } else {
200
- if (this._isWeb) {
201
- updatedSettings.minimumFetchIntervalMillis = settings.minimumFetchIntervalMillis;
202
- } else {
203
- updatedSettings.minimumFetchInterval = settings.minimumFetchIntervalMillis / 1000;
204
- }
196
+ updatedSettings.minimumFetchInterval = settings.minimumFetchIntervalMillis / 1000;
205
197
  }
206
198
  }
207
199
 
@@ -211,11 +203,7 @@ class FirebaseConfigModule extends FirebaseModule {
211
203
  `firebase.remoteConfig().${apiCalled}(): 'settings.fetchTimeMillis' must be a number type in milliseconds.`,
212
204
  );
213
205
  } else {
214
- if (this._isWeb) {
215
- updatedSettings.fetchTimeMillis = settings.fetchTimeMillis;
216
- } else {
217
- updatedSettings.fetchTimeout = settings.fetchTimeMillis / 1000;
218
- }
206
+ updatedSettings.fetchTimeout = settings.fetchTimeMillis / 1000;
219
207
  }
220
208
  }
221
209
 
@@ -348,17 +336,10 @@ class FirebaseConfigModule extends FirebaseModule {
348
336
  this._lastFetchStatus = constants.lastFetchStatus;
349
337
  }
350
338
 
351
- if (this._isWeb) {
352
- this._settings = {
353
- fetchTimeMillis: constants.fetchTimeMillis,
354
- minimumFetchIntervalMillis: constants.minimumFetchIntervalMillis,
355
- };
356
- } else {
357
- this._settings = {
358
- fetchTimeMillis: constants.fetchTimeout * 1000,
359
- minimumFetchIntervalMillis: constants.minimumFetchInterval * 1000,
360
- };
361
- }
339
+ this._settings = {
340
+ fetchTimeMillis: constants.fetchTimeout * 1000,
341
+ minimumFetchIntervalMillis: constants.minimumFetchInterval * 1000,
342
+ };
362
343
 
363
344
  this._values = Object.freeze(constants.values);
364
345
  }
@@ -391,3 +372,5 @@ export default createModuleNamespace({
391
372
  // config().X(...);
392
373
  // firebase.remoteConfig().X(...);
393
374
  export const firebase = getFirebaseRoot();
375
+
376
+ setReactNativeModule(nativeModuleName, fallBackModule);
package/lib/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- module.exports = '20.1.0';
2
+ module.exports = '20.2.0';
@@ -0,0 +1,2 @@
1
+ // No-op for android.
2
+ export default {};
@@ -0,0 +1,2 @@
1
+ // No-op for ios.
2
+ export default {};
@@ -0,0 +1,116 @@
1
+ import {
2
+ getApp,
3
+ getRemoteConfig,
4
+ activate,
5
+ ensureInitialized,
6
+ fetchAndActivate,
7
+ fetchConfig,
8
+ getAll,
9
+ makeIDBAvailable,
10
+ } from '@react-native-firebase/app/lib/internal/web/firebaseRemoteConfig';
11
+ import { guard } from '@react-native-firebase/app/lib/internal/web/utils';
12
+
13
+ let configSettingsForInstance = {
14
+ // [APP_NAME]: RemoteConfigSettings
15
+ };
16
+ let defaultConfigForInstance = {
17
+ // [APP_NAME]: { [key: string]: string | number | boolean }
18
+ };
19
+
20
+ function makeGlobalsAvailable() {
21
+ navigator.onLine = true;
22
+ makeIDBAvailable();
23
+ }
24
+
25
+ function getRemoteConfigInstanceForApp(appName, overrides /*: RemoteConfigSettings */) {
26
+ makeGlobalsAvailable();
27
+ const configSettings = configSettingsForInstance[appName] ?? {
28
+ minimumFetchIntervalMillis: 43200000,
29
+ fetchTimeoutMillis: 60000,
30
+ };
31
+ const defaultConfig = defaultConfigForInstance[appName] ?? {};
32
+ Object.assign(configSettings, overrides);
33
+ const app = getApp(appName);
34
+ const instance = getRemoteConfig(app);
35
+ for (const key in configSettings) {
36
+ instance.settings[key] = configSettings[key];
37
+ }
38
+ instance.defaultConfig = defaultConfig;
39
+ return instance;
40
+ }
41
+
42
+ async function resultAndConstants(instance, result) {
43
+ const response = { result };
44
+ const valuesRaw = getAll(instance);
45
+ const values = {};
46
+ for (const key in valuesRaw) {
47
+ const raw = valuesRaw[key];
48
+ values[key] = {
49
+ source: raw.getSource(),
50
+ value: raw.asString(),
51
+ };
52
+ }
53
+ response.constants = {
54
+ values,
55
+ lastFetchTime: instance.fetchTimeMillis === -1 ? 0 : instance.fetchTimeMillis,
56
+ lastFetchStatus: instance.lastFetchStatus.replace(/-/g, '_'),
57
+ minimumFetchInterval: instance.settings.minimumFetchIntervalMillis
58
+ ? instance.settings.minimumFetchIntervalMillis / 1000
59
+ : 43200,
60
+ fetchTimeout: instance.settings.fetchTimeoutMillis
61
+ ? instance.settings.fetchTimeoutMillis / 1000
62
+ : 60,
63
+ };
64
+ return response;
65
+ }
66
+
67
+ export default {
68
+ activate(appName) {
69
+ return guard(async () => {
70
+ const remoteConfig = getRemoteConfigInstanceForApp(appName);
71
+ return resultAndConstants(remoteConfig, await activate(remoteConfig));
72
+ });
73
+ },
74
+ setConfigSettings(appName, settings) {
75
+ return guard(async () => {
76
+ configSettingsForInstance[appName] = {
77
+ minimumFetchIntervalMillis: settings.minimumFetchInterval * 1000,
78
+ fetchTimeoutMillis: settings.fetchTimeout * 1000,
79
+ };
80
+ const remoteConfig = getRemoteConfigInstanceForApp(appName, settings);
81
+ return resultAndConstants(remoteConfig, null);
82
+ });
83
+ },
84
+ fetch(appName, expirationDurationSeconds) {
85
+ return guard(async () => {
86
+ let overrides = {};
87
+ if (expirationDurationSeconds != -1) {
88
+ overrides.minimumFetchIntervalMillis = expirationDurationSeconds * 1000;
89
+ }
90
+ const remoteConfig = getRemoteConfigInstanceForApp(appName, overrides);
91
+ await fetchConfig(remoteConfig);
92
+ return resultAndConstants(remoteConfig, null);
93
+ });
94
+ },
95
+ fetchAndActivate(appName) {
96
+ return guard(async () => {
97
+ const remoteConfig = getRemoteConfigInstanceForApp(appName);
98
+ const activated = await fetchAndActivate(remoteConfig);
99
+ return resultAndConstants(remoteConfig, activated);
100
+ });
101
+ },
102
+ ensureInitialized(appName) {
103
+ return guard(async () => {
104
+ const remoteConfig = getRemoteConfigInstanceForApp(appName);
105
+ await ensureInitialized(remoteConfig);
106
+ return resultAndConstants(remoteConfig, null);
107
+ });
108
+ },
109
+ setDefaults(appName, defaults) {
110
+ return guard(async () => {
111
+ defaultConfigForInstance[appName] = defaults;
112
+ const remoteConfig = getRemoteConfigInstanceForApp(appName);
113
+ return resultAndConstants(remoteConfig, null);
114
+ });
115
+ },
116
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-firebase/remote-config",
3
- "version": "20.1.0",
3
+ "version": "20.2.0",
4
4
  "author": "Invertase <oss@invertase.io> (http://invertase.io)",
5
5
  "description": "React Native Firebase - React Native Firebase provides native integration with Remote Config, allowing you to change the appearance and/or functionality of your app without requiring an app update.",
6
6
  "main": "lib/index.js",
@@ -24,11 +24,11 @@
24
24
  "remote-config"
25
25
  ],
26
26
  "peerDependencies": {
27
- "@react-native-firebase/analytics": "20.1.0",
28
- "@react-native-firebase/app": "20.1.0"
27
+ "@react-native-firebase/analytics": "20.2.0",
28
+ "@react-native-firebase/app": "20.2.0"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"
32
32
  },
33
- "gitHead": "99819b9cef23ac46080cbffe50cc85083305d04c"
33
+ "gitHead": "82c50138d07e673213cd8dee5ce9a2f9b5656649"
34
34
  }