@react-native-firebase/remote-config 16.7.0 → 17.1.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,20 @@
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
+ ## [17.1.0](https://github.com/invertase/react-native-firebase/compare/v17.0.0...v17.1.0) (2023-02-09)
7
+
8
+ ### Features
9
+
10
+ - **remote-config:** Expose modular API that matches the Firebase web JS SDK v9 API ([#6868](https://github.com/invertase/react-native-firebase/issues/6868)) ([e1504aa](https://github.com/invertase/react-native-firebase/commit/e1504aabd6ffba5c7d4b85c46ed44e12e0b9f916))
11
+
12
+ ### Bug Fixes
13
+
14
+ - **remote-config:** incorrect if condition & doc update ([#6892](https://github.com/invertase/react-native-firebase/issues/6892)) ([1a1488c](https://github.com/invertase/react-native-firebase/commit/1a1488ced6aac8e6886cfd73033757a97e6e1abd))
15
+
16
+ ## [17.0.0](https://github.com/invertase/react-native-firebase/compare/v16.7.0...v17.0.0) (2023-02-02)
17
+
18
+ **Note:** Version bump only for package @react-native-firebase/remote-config
19
+
6
20
  ## [16.7.0](https://github.com/invertase/react-native-firebase/compare/v16.6.0...v16.7.0) (2023-01-28)
7
21
 
8
22
  **Note:** Version bump only for package @react-native-firebase/remote-config
package/lib/index.d.ts CHANGED
@@ -55,7 +55,10 @@ import { ReactNativeFirebase } from '@react-native-firebase/app';
55
55
  */
56
56
  export namespace FirebaseRemoteConfigTypes {
57
57
  import FirebaseModule = ReactNativeFirebase.FirebaseModule;
58
-
58
+ /**
59
+ * Defines levels of Remote Config logging. Web only.
60
+ */
61
+ export declare type RemoteConfigLogLevel = 'debug' | 'error' | 'silent';
59
62
  /**
60
63
  * A pseudo-enum for usage with ConfigSettingsRead.lastFetchStatus to determine the last fetch status.
61
64
  *
@@ -283,6 +286,11 @@ export namespace FirebaseRemoteConfigTypes {
283
286
  [key: string]: number | string | boolean;
284
287
  }
285
288
 
289
+ /**
290
+ * The status of the latest Remote RemoteConfig fetch action.
291
+ */
292
+ type LastFetchStatusType = 'success' | 'failure' | 'no_fetch_yet' | 'throttled';
293
+
286
294
  /**
287
295
  * The Firebase Remote RemoteConfig service interface.
288
296
  *
@@ -306,7 +314,7 @@ export namespace FirebaseRemoteConfigTypes {
306
314
  *
307
315
  * See the `LastFetchStatus` statics definition.
308
316
  */
309
- lastFetchStatus: 'success' | 'failure' | 'no_fetch_yet' | 'throttled';
317
+ lastFetchStatus: LastFetchStatusType;
310
318
 
311
319
  /**
312
320
  * Provides an object which provides the properties `minimumFetchIntervalMillis` & `fetchTimeMillis` if they have been set
@@ -314,7 +322,12 @@ export namespace FirebaseRemoteConfigTypes {
314
322
  * can be found above
315
323
  *
316
324
  */
317
- settings: { fetchTimeMillis: number; minimumFetchIntervalMillis: number };
325
+ settings: ConfigSettings;
326
+
327
+ /**
328
+ * Provides an object with the type ConfigDefaults for default configuration values
329
+ */
330
+ defaultConfig: ConfigDefaults;
318
331
 
319
332
  /**
320
333
  * Set the Remote RemoteConfig settings, currently able to set `fetchTimeMillis` & `minimumFetchIntervalMillis`
package/lib/index.js CHANGED
@@ -30,6 +30,30 @@ import {
30
30
  getFirebaseRoot,
31
31
  } from '@react-native-firebase/app/lib/internal';
32
32
  import version from './version';
33
+ import { Platform } from 'react-native';
34
+
35
+ export {
36
+ getRemoteConfig,
37
+ activate,
38
+ ensureInitialized,
39
+ fetchAndActivate,
40
+ fetchConfig,
41
+ getAll,
42
+ getBoolean,
43
+ getNumber,
44
+ getString,
45
+ getValue,
46
+ setLogLevel,
47
+ isSupported,
48
+ fetchTimeMillis,
49
+ settings,
50
+ lastFetchStatus,
51
+ reset,
52
+ setConfigSettings,
53
+ fetch,
54
+ setDefaults,
55
+ setDefaultsFromResource,
56
+ } from './modular/index';
33
57
 
34
58
  const statics = {
35
59
  LastFetchStatus: {
@@ -59,6 +83,41 @@ class FirebaseConfigModule extends FirebaseModule {
59
83
  };
60
84
  this._lastFetchTime = -1;
61
85
  this._values = {};
86
+ this._isWeb = Platform.OS !== 'ios' && Platform.OS !== 'android';
87
+ }
88
+
89
+ get defaultConfig() {
90
+ const updatedDefaultConfig = {};
91
+ Object.keys(this._values).forEach(key => {
92
+ // Need to make it an object with key and literal value. Not `Value` instance.
93
+ updatedDefaultConfig[key] = this._values[key].value;
94
+ });
95
+
96
+ return updatedDefaultConfig;
97
+ }
98
+
99
+ set defaultConfig(defaults) {
100
+ if (!isObject(defaults)) {
101
+ throw new Error("firebase.remoteConfig().defaultConfig: 'defaults' must be an object.");
102
+ }
103
+ // To make Firebase web v9 API compatible, we update the config first so it immediately
104
+ // updates defaults on the instance. We then pass to underlying SDK to update. We do this because
105
+ // there is no way to "await" a setter.
106
+ this._updateFromConstants(defaults);
107
+ this.setDefaults.call(this, defaults, true);
108
+ }
109
+
110
+ get settings() {
111
+ return this._settings;
112
+ }
113
+
114
+ set settings(settings) {
115
+ // To make Firebase web v9 API compatible, we update the settings first so it immediately
116
+ // updates settings on the instance. We then pass to underlying SDK to update. We do this because
117
+ // there is no way to "await" a setter. We can't delegate to `setConfigSettings()` as it is setup
118
+ // for native.
119
+ this._updateFromConstants(settings);
120
+ this.setConfigSettings.call(this, settings, true);
62
121
  }
63
122
 
64
123
  getValue(key) {
@@ -94,10 +153,6 @@ class FirebaseConfigModule extends FirebaseModule {
94
153
  return values;
95
154
  }
96
155
 
97
- get settings() {
98
- return this._settings;
99
- }
100
-
101
156
  get fetchTimeMillis() {
102
157
  // android returns -1 if no fetch yet and iOS returns 0
103
158
  return this._lastFetchTime;
@@ -120,38 +175,49 @@ class FirebaseConfigModule extends FirebaseModule {
120
175
  }
121
176
 
122
177
  setConfigSettings(settings) {
123
- const nativeSettings = {
124
- //iOS & Android expect seconds
125
- fetchTimeout: this._settings.fetchTimeMillis / 1000,
126
- minimumFetchInterval: this._settings.minimumFetchIntervalMillis / 1000,
127
- };
128
-
178
+ const updatedSettings = {};
179
+ if (this._isWeb) {
180
+ updatedSettings.fetchTimeMillis = this._settings.fetchTimeMillis;
181
+ updatedSettings.minimumFetchIntervalMillis = this._settings.minimumFetchIntervalMillis;
182
+ } else {
183
+ //iOS & Android expect seconds & different property names
184
+ updatedSettings.fetchTimeout = this._settings.fetchTimeMillis / 1000;
185
+ updatedSettings.minimumFetchInterval = this._settings.minimumFetchIntervalMillis / 1000;
186
+ }
187
+ const apiCalled = arguments[1] == true ? 'settings' : 'setConfigSettings';
129
188
  if (!isObject(settings)) {
130
- throw new Error('firebase.remoteConfig().setConfigSettings(*): settings must set an object.');
189
+ throw new Error(`firebase.remoteConfig().${apiCalled}(*): settings must set an object.`);
131
190
  }
132
191
 
133
192
  if (hasOwnProperty(settings, 'minimumFetchIntervalMillis')) {
134
193
  if (!isNumber(settings.minimumFetchIntervalMillis)) {
135
194
  throw new Error(
136
- "firebase.remoteConfig().setConfigSettings(): 'settings.minimumFetchIntervalMillis' must be a number type in milliseconds.",
195
+ `firebase.remoteConfig().${apiCalled}(): 'settings.minimumFetchIntervalMillis' must be a number type in milliseconds.`,
137
196
  );
138
197
  } else {
139
- nativeSettings.minimumFetchInterval = settings.minimumFetchIntervalMillis / 1000;
198
+ if (this._isWeb) {
199
+ updatedSettings.minimumFetchIntervalMillis = settings.minimumFetchIntervalMillis;
200
+ } else {
201
+ updatedSettings.minimumFetchInterval = settings.minimumFetchIntervalMillis / 1000;
202
+ }
140
203
  }
141
204
  }
142
205
 
143
206
  if (hasOwnProperty(settings, 'fetchTimeMillis')) {
144
207
  if (!isNumber(settings.fetchTimeMillis)) {
145
208
  throw new Error(
146
- "firebase.remoteConfig().setConfigSettings(): 'settings.fetchTimeMillis' must be a number type in milliseconds.",
209
+ `firebase.remoteConfig().${apiCalled}(): 'settings.fetchTimeMillis' must be a number type in milliseconds.`,
147
210
  );
148
211
  } else {
149
- nativeSettings.fetchTimeout = settings.fetchTimeMillis / 1000;
212
+ if (this._isWeb) {
213
+ updatedSettings.fetchTimeMillis = settings.fetchTimeMillis;
214
+ } else {
215
+ updatedSettings.fetchTimeout = settings.fetchTimeMillis / 1000;
216
+ }
150
217
  }
151
218
  }
152
219
 
153
- // this._settings = settings;
154
- return this._promiseWithConstants(this.native.setConfigSettings(nativeSettings));
220
+ return this._promiseWithConstants(this.native.setConfigSettings(updatedSettings));
155
221
  }
156
222
 
157
223
  /**
@@ -194,8 +260,9 @@ class FirebaseConfigModule extends FirebaseModule {
194
260
  * @param {object} defaults
195
261
  */
196
262
  setDefaults(defaults) {
263
+ const apiCalled = arguments[1] === true ? 'defaultConfig' : 'setDefaults';
197
264
  if (!isObject(defaults)) {
198
- throw new Error("firebase.remoteConfig().setDefaults(): 'defaults' must be an object.");
265
+ throw new Error(`firebase.remoteConfig().${apiCalled}(): 'defaults' must be an object.`);
199
266
  }
200
267
 
201
268
  return this._promiseWithConstants(this.native.setDefaults(defaults));
@@ -216,13 +283,27 @@ class FirebaseConfigModule extends FirebaseModule {
216
283
  }
217
284
 
218
285
  _updateFromConstants(constants) {
219
- this._lastFetchTime = constants.lastFetchTime;
220
- this._lastFetchStatus = constants.lastFetchStatus;
286
+ // Wrapped this as we update using sync getters initially for `defaultConfig` & `settings`
287
+ if (constants.lastFetchTime) {
288
+ this._lastFetchTime = constants.lastFetchTime;
289
+ }
221
290
 
222
- this._settings = {
223
- fetchTimeMillis: constants.fetchTimeout * 1000,
224
- minimumFetchIntervalMillis: constants.minimumFetchInterval * 1000,
225
- };
291
+ // Wrapped this as we update using sync getters initially for `defaultConfig` & `settings`
292
+ if (constants.lastFetchStatus) {
293
+ this._lastFetchStatus = constants.lastFetchStatus;
294
+ }
295
+
296
+ if (this._isWeb) {
297
+ this._settings = {
298
+ fetchTimeMillis: constants.fetchTimeMillis,
299
+ minimumFetchIntervalMillis: constants.minimumFetchIntervalMillis,
300
+ };
301
+ } else {
302
+ this._settings = {
303
+ fetchTimeMillis: constants.fetchTimeout * 1000,
304
+ minimumFetchIntervalMillis: constants.minimumFetchInterval * 1000,
305
+ };
306
+ }
226
307
 
227
308
  this._values = Object.freeze(constants.values);
228
309
  }
@@ -0,0 +1,223 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import { firebase } from '..';
19
+
20
+ /**
21
+ * Returns a RemoteConfig instance for the given app.
22
+ * @param app - FirebaseApp. Optional.
23
+ * @returns {RemoteConfig}
24
+ */
25
+ export function getRemoteConfig(app) {
26
+ if (app) {
27
+ return firebase.app(app.name).remoteConfig();
28
+ }
29
+
30
+ return firebase.app().remoteConfig();
31
+ }
32
+
33
+ /**
34
+ * Returns a Boolean which resolves to true if the current call
35
+ * activated the fetched configs.
36
+ * @param remoteConfig - RemoteConfig instance
37
+ * @returns {Promise<boolean>}
38
+ */
39
+ export function activate(remoteConfig) {
40
+ return remoteConfig.activate();
41
+ }
42
+
43
+ /**
44
+ * Ensures the last activated config are available to the getters.
45
+ * @param remoteConfig - RemoteConfig instance
46
+ * @returns {Promise<void>}
47
+ */
48
+ export function ensureInitialized(remoteConfig) {
49
+ return remoteConfig.ensureInitialized();
50
+ }
51
+
52
+ /**
53
+ * Performs a fetch and returns a Boolean which resolves to true
54
+ * if the current call activated the fetched configs.
55
+ * @param remoteConfig - RemoteConfig instance
56
+ * @returns {Promise<boolean>}
57
+ */
58
+ export function fetchAndActivate(remoteConfig) {
59
+ return remoteConfig.fetchAndActivate();
60
+ }
61
+
62
+ /**
63
+ * Fetches and caches configuration from the Remote Config service.
64
+ * @param remoteConfig - RemoteConfig instance
65
+ * @returns {Promise<void>}
66
+ */
67
+ export function fetchConfig(remoteConfig) {
68
+ return remoteConfig.fetchConfig();
69
+ }
70
+
71
+ /**
72
+ * Gets all config.
73
+ * @param remoteConfig - RemoteConfig instance
74
+ * @returns {Promise<ConfigValues>}
75
+ */
76
+ export function getAll(remoteConfig) {
77
+ return remoteConfig.getAll();
78
+ }
79
+
80
+ /**
81
+ * Gets the value for the given key as a boolean.
82
+ * @param remoteConfig - RemoteConfig instance
83
+ * @param key - key for boolean value
84
+ * @returns {boolean}
85
+ */
86
+ export function getBoolean(remoteConfig, key) {
87
+ return remoteConfig.getBoolean(key);
88
+ }
89
+
90
+ /**
91
+ * Gets the value for the given key as a number.
92
+ * @param remoteConfig - RemoteConfig instance
93
+ * @param key - key for number value
94
+ * @returns {number}
95
+ */
96
+ export function getNumber(remoteConfig, key) {
97
+ return remoteConfig.getNumber(key);
98
+ }
99
+
100
+ /**
101
+ * Gets the value for the given key as a string.
102
+ * @param remoteConfig - RemoteConfig instance
103
+ * @param key - key for string value
104
+ * @returns {string}
105
+ */
106
+ export function getString(remoteConfig, key) {
107
+ return remoteConfig.getString(key);
108
+ }
109
+
110
+ /**
111
+ * Gets the value for the given key
112
+ * @param remoteConfig - RemoteConfig instance
113
+ * @param key - key for the given value
114
+ * @returns {ConfigValue}
115
+ */
116
+ export function getValue(remoteConfig, key) {
117
+ return remoteConfig.getValue(key);
118
+ }
119
+
120
+ /**
121
+ * Defines the log level to use.
122
+ * @param remoteConfig - RemoteConfig instance
123
+ * @param logLevel - The log level to set
124
+ * @returns {RemoteConfigLogLevel}
125
+ */
126
+ // eslint-disable-next-line
127
+ export function setLogLevel(remoteConfig, logLevel) {
128
+ // always return the "error" log level for now as the setter is ignored on native. Web only.
129
+ return 'error';
130
+ }
131
+
132
+ /**
133
+ * Checks two different things.
134
+ * 1. Check if IndexedDB exists in the browser environment.
135
+ * 2. Check if the current browser context allows IndexedDB open() calls.
136
+ * @returns {Promise<boolean>}
137
+ */
138
+ export function isSupported() {
139
+ // always return "true" for now. Web only.
140
+ return Promise.resolve(true);
141
+ }
142
+
143
+ /**
144
+ * Indicates the default value in milliseconds to abandon a pending fetch
145
+ * request made to the Remote Config server. Defaults to 60000 (One minute).
146
+ * @param remoteConfig - RemoteConfig instance
147
+ * @returns {number}
148
+ */
149
+ export function fetchTimeMillis(remoteConfig) {
150
+ return remoteConfig.fetchTimeMillis;
151
+ }
152
+
153
+ /**
154
+ * Returns a ConfigSettings object which provides the properties `minimumFetchIntervalMillis` & `fetchTimeMillis` if they have been set
155
+ * using setConfigSettings({ fetchTimeMillis: number, minimumFetchIntervalMillis: number }).
156
+ * @param remoteConfig - RemoteConfig instance
157
+ * @returns {ConfigSettings}
158
+ */
159
+ export function settings(remoteConfig) {
160
+ return remoteConfig.settings;
161
+ }
162
+
163
+ /**
164
+ * The status of the latest Remote RemoteConfig fetch action.
165
+ * @param remoteConfig - RemoteConfig instance
166
+ * @returns {LastFetchStatusType}
167
+ */
168
+ export function lastFetchStatus(remoteConfig) {
169
+ return remoteConfig.lastFetchStatus;
170
+ }
171
+
172
+ /**
173
+ * Deletes all activated, fetched and defaults configs and
174
+ * resets all Firebase Remote Config settings.
175
+ * Android only. iOS does not reset anything.
176
+ * @param remoteConfig - RemoteConfig instance
177
+ * @returns {Promise<void>}
178
+ */
179
+ export function reset(remoteConfig) {
180
+ return remoteConfig.reset();
181
+ }
182
+
183
+ /**
184
+ * Set the Remote RemoteConfig settings, currently able to set
185
+ * `fetchTimeMillis` & `minimumFetchIntervalMillis`
186
+ * Android only. iOS does not reset anything.
187
+ * @param remoteConfig - RemoteConfig instance
188
+ * @param settings - ConfigSettings instance
189
+ * @returns {Promise<void>}
190
+ */
191
+ export function setConfigSettings(remoteConfig, settings) {
192
+ return remoteConfig.setConfigSettings(settings);
193
+ }
194
+
195
+ /**
196
+ * Fetches parameter values for your app.
197
+ * @param remoteConfig - RemoteConfig instance
198
+ * @param expirationDurationSeconds - number
199
+ * @returns {Promise<void>}
200
+ */
201
+ export function fetch(remoteConfig, expirationDurationSeconds) {
202
+ return remoteConfig.fetch(expirationDurationSeconds);
203
+ }
204
+
205
+ /**
206
+ * Fetches parameter values for your app.
207
+ * @param remoteConfig - RemoteConfig instance
208
+ * @param defaults - ConfigDefaults
209
+ * @returns {Promise<void>}
210
+ */
211
+ export function setDefaults(remoteConfig, defaults) {
212
+ return remoteConfig.setDefaults(defaults);
213
+ }
214
+
215
+ /**
216
+ * Fetches parameter values for your app.
217
+ * @param remoteConfig - RemoteConfig instance
218
+ * @param resourceName - string
219
+ * @returns {Promise<null>}
220
+ */
221
+ export function setDefaultsFromResource(remoteConfig, resourceName) {
222
+ return remoteConfig.setDefaultsFromResource(resourceName);
223
+ }
package/lib/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- module.exports = '16.7.0';
2
+ module.exports = '17.1.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-firebase/remote-config",
3
- "version": "16.7.0",
3
+ "version": "17.1.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": "16.7.0",
28
- "@react-native-firebase/app": "16.7.0"
27
+ "@react-native-firebase/analytics": "17.1.0",
28
+ "@react-native-firebase/app": "17.1.0"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"
32
32
  },
33
- "gitHead": "a94f371da16f9bf873c18b09541cbeb19960978d"
33
+ "gitHead": "635d595389bfb224fc530681627fb2180fea6e26"
34
34
  }