@react-native-firebase/app 20.2.1 → 20.4.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,18 @@
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.4.0](https://github.com/invertase/react-native-firebase/compare/v20.3.0...v20.4.0) (2024-08-13)
7
+
8
+ ### Features
9
+
10
+ - **firestore:** support for second database ([#7949](https://github.com/invertase/react-native-firebase/issues/7949)) ([eec08a0](https://github.com/invertase/react-native-firebase/commit/eec08a06f41dd96d13778fbed2afcaaac238fca4))
11
+
12
+ ## [20.3.0](https://github.com/invertase/react-native-firebase/compare/v20.2.1...v20.3.0) (2024-07-19)
13
+
14
+ ### Bug Fixes
15
+
16
+ - **other:** add api for persistence via Async Storage ([030eea9](https://github.com/invertase/react-native-firebase/commit/030eea91f297a4014ab86cfb141ae938f200c5e5))
17
+
6
18
  ## [20.2.1](https://github.com/invertase/react-native-firebase/compare/v20.2.0...v20.2.1) (2024-07-17)
7
19
 
8
20
  **Note:** Version bump only for package @react-native-firebase/app
@@ -0,0 +1,43 @@
1
+ import { describe, expect, it } from '@jest/globals';
2
+
3
+ import {
4
+ deleteApp,
5
+ registerVersion,
6
+ onLog,
7
+ getApps,
8
+ initializeApp,
9
+ getApp,
10
+ setLogLevel,
11
+ } from '../lib';
12
+
13
+ describe('App', function () {
14
+ describe('modular', function () {
15
+ it('`deleteApp` function is properly exposed to end user', function () {
16
+ expect(deleteApp).toBeDefined();
17
+ });
18
+
19
+ it('`registerVersion` function is properly exposed to end user', function () {
20
+ expect(registerVersion).toBeDefined();
21
+ });
22
+
23
+ it('`onLog` function is properly exposed to end user', function () {
24
+ expect(onLog).toBeDefined();
25
+ });
26
+
27
+ it('`getApps` function is properly exposed to end user', function () {
28
+ expect(getApps).toBeDefined();
29
+ });
30
+
31
+ it('`initializeApp` function is properly exposed to end user', function () {
32
+ expect(initializeApp).toBeDefined();
33
+ });
34
+
35
+ it('`getApp` function is properly exposed to end user', function () {
36
+ expect(getApp).toBeDefined();
37
+ });
38
+
39
+ it('`setLogLevel` function is properly exposed to end user', function () {
40
+ expect(setLogLevel).toBeDefined();
41
+ });
42
+ });
43
+ });
@@ -18,5 +18,5 @@ package io.invertase.firebase.app;
18
18
  */
19
19
  // generated file - do not modify or commit
20
20
  public class ReactNativeFirebaseVersion {
21
- public static String VERSION = "20.2.1";
21
+ public static String VERSION = "20.4.0";
22
22
  }
@@ -18,4 +18,4 @@
18
18
  #import <React/RCTVersion.h>
19
19
 
20
20
  // generated file - do not modify or commit
21
- NSString* const RNFBVersionString = @"20.2.1";
21
+ NSString* const RNFBVersionString = @"20.4.0";
package/lib/index.d.ts CHANGED
@@ -158,6 +158,36 @@ export namespace ReactNativeFirebase {
158
158
  utils(): Utils.Module;
159
159
  }
160
160
 
161
+ /**
162
+ * Interface for a supplied `AsyncStorage`.
163
+ */
164
+ export interface ReactNativeAsyncStorage {
165
+ /**
166
+ * Persist an item in storage.
167
+ *
168
+ * @param key - storage key.
169
+ * @param value - storage value.
170
+ */
171
+ // eslint-disable-next-line @typescript-eslint/ban-types
172
+ setItem: Function;
173
+ /**
174
+ * Retrieve an item from storage.
175
+ *
176
+ * @param key - storage key.
177
+ */
178
+ // eslint-disable-next-line @typescript-eslint/ban-types
179
+ getItem: Function;
180
+ /**
181
+ * Remove an item from storage.
182
+ *
183
+ * @param key - storage key.
184
+ */
185
+ // eslint-disable-next-line @typescript-eslint/ban-types
186
+ removeItem: Function;
187
+
188
+ [key: string]: any;
189
+ }
190
+
161
191
  export interface Module {
162
192
  /**
163
193
  * Create (and initialize) a FirebaseApp.
@@ -201,6 +231,14 @@ export namespace ReactNativeFirebase {
201
231
  */
202
232
  setLogLevel(logLevel: LogLevelString): void;
203
233
 
234
+ /**
235
+ * The `AsyncStorage` implementation to use for persisting data on 'Other' platforms.
236
+ * If not specified, in memory persistence is used.
237
+ *
238
+ * This is required if you want to persist things like Auth sessions, Analytics device IDs, etc.
239
+ */
240
+ setReactNativeAsyncStorage(asyncStorage: ReactNativeAsyncStorage): void;
241
+
204
242
  /**
205
243
  * A (read-only) array of all the initialized Apps.
206
244
  */
@@ -573,5 +611,7 @@ export namespace Utils {
573
611
  */
574
612
  export const utils: ReactNativeFirebase.FirebaseModuleWithStatics<Utils.Module, Utils.Statics>;
575
613
 
614
+ export * from './modular';
615
+
576
616
  declare const module: ReactNativeFirebase.Module;
577
617
  export default module;
package/lib/index.js CHANGED
@@ -18,7 +18,7 @@
18
18
  import { getFirebaseRoot } from './internal/registry/namespace';
19
19
 
20
20
  export const firebase = getFirebaseRoot();
21
- export * from './modular/app';
21
+ export * from './modular';
22
22
  export { default as utils } from './utils';
23
23
 
24
24
  export default firebase;
@@ -0,0 +1,47 @@
1
+ export const memoryStorage = new Map();
2
+
3
+ export const prefix = '@react-native-firebase:';
4
+
5
+ const asyncStorageMemory = {
6
+ setItem(key, value) {
7
+ memoryStorage.set(key, value);
8
+ return Promise.resolve();
9
+ },
10
+ getItem(key) {
11
+ const hasValue = memoryStorage.has(key);
12
+ if (hasValue) {
13
+ return Promise.resolve(memoryStorage.get(key));
14
+ }
15
+ return Promise.resolve(null);
16
+ },
17
+ removeItem: function (key) {
18
+ memoryStorage.delete(key);
19
+ return Promise.resolve();
20
+ },
21
+ };
22
+
23
+ let asyncStorage = asyncStorageMemory;
24
+
25
+ export async function getReactNativeAsyncStorageInternal() {
26
+ return asyncStorage;
27
+ }
28
+
29
+ export function setReactNativeAsyncStorageInternal(asyncStorageInstance) {
30
+ asyncStorage = asyncStorageInstance || asyncStorageMemory;
31
+ }
32
+
33
+ export function isMemoryStorage() {
34
+ return asyncStorage === asyncStorageMemory;
35
+ }
36
+
37
+ export async function setItem(key, value) {
38
+ return await asyncStorage.setItem(prefix + key, value);
39
+ }
40
+
41
+ export async function getItem(key) {
42
+ return await asyncStorage.getItem(prefix + key);
43
+ }
44
+
45
+ export async function removeItem(key) {
46
+ return await asyncStorage.removeItem(prefix + key);
47
+ }
@@ -20,11 +20,13 @@ import {
20
20
  isOther,
21
21
  isNull,
22
22
  isObject,
23
+ isFunction,
23
24
  isString,
24
25
  isUndefined,
25
26
  } from '@react-native-firebase/app/lib/common';
26
27
  import FirebaseApp from '../../FirebaseApp';
27
28
  import { DEFAULT_APP_NAME } from '../constants';
29
+ import { setReactNativeAsyncStorageInternal } from '../asyncStorage';
28
30
  import { getAppModule } from './nativeModule';
29
31
 
30
32
  const APP_REGISTRY = {};
@@ -172,7 +174,7 @@ export function initializeApp(options = {}, configOrName) {
172
174
  );
173
175
  }
174
176
 
175
- const app = new FirebaseApp(options, { name }, false, deleteApp.bind(null, name, true));
177
+ const app = new FirebaseApp(options, appConfig, false, deleteApp.bind(null, name, true));
176
178
 
177
179
  // Note these initialization actions with side effects are performed prior to knowledge of
178
180
  // successful initialization in the native code. Native code *may* throw an error.
@@ -180,7 +182,7 @@ export function initializeApp(options = {}, configOrName) {
180
182
  onAppCreateFn(APP_REGISTRY[name]);
181
183
 
182
184
  return getAppModule()
183
- .initializeApp(options, { name })
185
+ .initializeApp(options, appConfig)
184
186
  .then(() => {
185
187
  app._initialized = true;
186
188
  return app;
@@ -207,6 +209,32 @@ export function setLogLevel(logLevel) {
207
209
  }
208
210
  }
209
211
 
212
+ export function setReactNativeAsyncStorage(asyncStorage) {
213
+ if (!isObject(asyncStorage)) {
214
+ throw new Error("firebase.setReactNativeAsyncStorage(*) 'asyncStorage' must be an object.");
215
+ }
216
+
217
+ if (!isFunction(asyncStorage.setItem)) {
218
+ throw new Error(
219
+ "firebase.setReactNativeAsyncStorage(*) 'asyncStorage.setItem' must be a function.",
220
+ );
221
+ }
222
+
223
+ if (!isFunction(asyncStorage.getItem)) {
224
+ throw new Error(
225
+ "firebase.setReactNativeAsyncStorage(*) 'asyncStorage.getItem' must be a function.",
226
+ );
227
+ }
228
+
229
+ if (!isFunction(asyncStorage.removeItem)) {
230
+ throw new Error(
231
+ "firebase.setReactNativeAsyncStorage(*) 'asyncStorage.removeItem' must be a function.",
232
+ );
233
+ }
234
+
235
+ setReactNativeAsyncStorageInternal(asyncStorage);
236
+ }
237
+
210
238
  /**
211
239
  *
212
240
  */
@@ -15,7 +15,7 @@
15
15
  *
16
16
  */
17
17
 
18
- import { isString } from '@react-native-firebase/app/lib/common';
18
+ import { isString } from '../../common';
19
19
  import FirebaseApp from '../../FirebaseApp';
20
20
  import SDK_VERSION from '../../version';
21
21
  import { DEFAULT_APP_NAME, KNOWN_NAMESPACES } from '../constants';
@@ -25,6 +25,7 @@ import {
25
25
  getApps,
26
26
  initializeApp,
27
27
  setLogLevel,
28
+ setReactNativeAsyncStorage,
28
29
  setOnAppCreate,
29
30
  setOnAppDestroy,
30
31
  } from './app';
@@ -92,19 +93,21 @@ function getOrCreateModuleForApp(app, moduleNamespace) {
92
93
  );
93
94
  }
94
95
 
95
- // e.g. firebase.storage(customUrlOrRegion)
96
- function firebaseModuleWithArgs(customUrlOrRegion) {
97
- if (customUrlOrRegion !== undefined) {
96
+ // e.g. firebase.storage(customUrlOrRegion), firebase.functions(customUrlOrRegion), firebase.firestore(databaseId), firebase.database(url)
97
+ function firebaseModuleWithArgs(customUrlOrRegionOrDatabaseId) {
98
+ if (customUrlOrRegionOrDatabaseId !== undefined) {
98
99
  if (!hasCustomUrlOrRegionSupport) {
99
100
  // TODO throw Module does not support arguments error
100
101
  }
101
102
 
102
- if (!isString(customUrlOrRegion)) {
103
+ if (!isString(customUrlOrRegionOrDatabaseId)) {
103
104
  // TODO throw Module first argument must be a string error
104
105
  }
105
106
  }
106
107
 
107
- const key = customUrlOrRegion ? `${customUrlOrRegion}:${moduleNamespace}` : moduleNamespace;
108
+ const key = customUrlOrRegionOrDatabaseId
109
+ ? `${customUrlOrRegionOrDatabaseId}:${moduleNamespace}`
110
+ : moduleNamespace;
108
111
 
109
112
  if (!APP_MODULE_INSTANCE[app.name]) {
110
113
  APP_MODULE_INSTANCE[app.name] = {};
@@ -114,7 +117,7 @@ function getOrCreateModuleForApp(app, moduleNamespace) {
114
117
  APP_MODULE_INSTANCE[app.name][key] = new ModuleClass(
115
118
  app,
116
119
  NAMESPACE_REGISTRY[moduleNamespace],
117
- customUrlOrRegion,
120
+ customUrlOrRegionOrDatabaseId,
118
121
  );
119
122
  }
120
123
 
@@ -241,6 +244,7 @@ export function firebaseAppModuleProxy(app, moduleNamespace) {
241
244
  export function createFirebaseRoot() {
242
245
  FIREBASE_ROOT = {
243
246
  initializeApp,
247
+ setReactNativeAsyncStorage,
244
248
  get app() {
245
249
  return getApp;
246
250
  },
@@ -153,7 +153,10 @@ function initialiseNativeModule(module) {
153
153
  function subscribeToNativeModuleEvent(eventName) {
154
154
  if (!NATIVE_MODULE_EVENT_SUBSCRIPTIONS[eventName]) {
155
155
  RNFBNativeEventEmitter.addListener(eventName, event => {
156
- if (event.appName) {
156
+ if (event.appName && event.databaseId) {
157
+ // Firestore requires both appName and databaseId to prefix
158
+ SharedEventEmitter.emit(`${event.appName}-${event.databaseId}-${eventName}`, event);
159
+ } else if (event.appName) {
157
160
  // native event has an appName property - auto prefix and internally emit
158
161
  SharedEventEmitter.emit(`${event.appName}-${eventName}`, event);
159
162
  } else {
@@ -0,0 +1,62 @@
1
+ import { ReactNativeFirebase } from '..';
2
+
3
+ import FirebaseApp = ReactNativeFirebase.FirebaseApp;
4
+ import FirebaseAppOptions = ReactNativeFirebase.FirebaseAppOptions;
5
+ import LogLevelString = ReactNativeFirebase.LogLevelString;
6
+
7
+ /**
8
+ * Renders this app unusable and frees the resources of all associated services.
9
+ * @param app - FirebaseApp - The app to delete.
10
+ * @returns Promise<void>
11
+ */
12
+ export function deleteApp(app: FirebaseApp): Promise<void>;
13
+
14
+ /**
15
+ * Registers a library's name and version for platform logging purposes.
16
+ * @param libraryKeyOrName - Library name or key.
17
+ * @param version - Library version.
18
+ * @param variant - Library variant.
19
+ * @returns Promise<void>
20
+ */
21
+ export function registerVersion(
22
+ libraryKeyOrName: string,
23
+ version: string,
24
+ variant: string | null,
25
+ ): Promise<void>;
26
+
27
+ /**
28
+ * Sets log handler for all Firebase SDKs.
29
+ * @param logCallback - The callback function to handle logs.
30
+ * @param options - Optional settings for log handling.
31
+ * @returns Promise<void>
32
+ * @throws Error - onLog is only supported on Web
33
+ */
34
+ export function onLog(logCallback: (logData: any) => void, options?: any): Promise<void>;
35
+
36
+ /**
37
+ * Gets the list of all initialized apps.
38
+ * @returns FirebaseApp[] - An array of all initialized Firebase apps.
39
+ */
40
+ export function getApps(): FirebaseApp[];
41
+
42
+ /**
43
+ * Initializes a Firebase app with the provided options and name.
44
+ * @param options - Options to configure the services used in the app.
45
+ * @param name - The optional name of the app to initialize ('[DEFAULT]' if omitted).
46
+ * @returns FirebaseApp - The initialized Firebase app.
47
+ */
48
+ export function initializeApp(options: FirebaseAppOptions, name?: string): FirebaseApp;
49
+
50
+ /**
51
+ * Retrieves an instance of a Firebase app.
52
+ * @param name - The optional name of the app to return ('[DEFAULT]' if omitted).
53
+ * @returns FirebaseApp - The requested Firebase app instance.
54
+ */
55
+ export function getApp(name?: string): FirebaseApp;
56
+
57
+ /**
58
+ * Sets the log level across all Firebase SDKs.
59
+ * @param logLevel - The log level to set ('debug', 'verbose', 'info', 'warn', 'error', 'silent').
60
+ * @returns void
61
+ */
62
+ export function setLogLevel(logLevel: LogLevelString): void;
@@ -0,0 +1,80 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ import {
3
+ deleteApp as deleteAppCompat,
4
+ getApp as getAppCompat,
5
+ getApps as getAppsCompat,
6
+ initializeApp as initializeAppCompat,
7
+ setLogLevel as setLogLevelCompat,
8
+ } from '../internal';
9
+
10
+ /**
11
+ * @typedef {import('..').ReactNativeFirebase.FirebaseApp} FirebaseApp
12
+ * @typedef {import('..').ReactNativeFirebase.FirebaseAppOptions} FirebaseAppOptions
13
+ * @typedef {import('..').ReactNativeFirebase.LogLevelString} LogLevelString
14
+ */
15
+
16
+ /**
17
+ * Renders this app unusable and frees the resources of all associated services.
18
+ * @param {FirebaseApp} app - The app to delete.
19
+ * @returns {Promise<void>}
20
+ */
21
+ export function deleteApp(app) {
22
+ return deleteAppCompat(app.name, app._nativeInitialized);
23
+ }
24
+
25
+ /**
26
+ * Registers a library's name and version for platform logging purposes.
27
+ @param {string} libraryKeyOrName - library name or key.
28
+ @param {string} version - library version.
29
+ @param {string | null} variant - library variant.
30
+ * @returns {Promise<void>}
31
+ */
32
+ export function registerVersion(libraryKeyOrName, version, variant) {
33
+ throw new Error('registerVersion is only supported on Web');
34
+ }
35
+
36
+ /**
37
+ * Sets log handler for all Firebase SDKs.
38
+ * @param {Function} logCallback - The callback function to handle logs.
39
+ * @param {Object} [options] - Optional settings for log handling.
40
+ * @returns {Promise<void>}
41
+ */
42
+ export function onLog(logCallback, options) {
43
+ throw new Error('onLog is only supported on Web');
44
+ }
45
+
46
+ /**
47
+ * Gets the list of all initialized apps.
48
+ * @returns {FirebaseApp[]} - An array of all initialized Firebase apps.
49
+ */
50
+ export function getApps() {
51
+ return getAppsCompat();
52
+ }
53
+
54
+ /**
55
+ * Initializes a Firebase app with the provided options and name.
56
+ * @param {FirebaseAppOptions} options - Options to configure the services used in the app.
57
+ * @param {string} [name] - The optional name of the app to initialize ('[DEFAULT]' if omitted).
58
+ * @returns {FirebaseApp} - The initialized Firebase app.
59
+ */
60
+ export function initializeApp(options, name) {
61
+ return initializeAppCompat(options, name);
62
+ }
63
+
64
+ /**
65
+ * Retrieves an instance of a Firebase app.
66
+ * @param {string} [name] - The optional name of the app to return ('[DEFAULT]' if omitted).
67
+ * @returns {FirebaseApp} - The requested Firebase app instance.
68
+ */
69
+ export function getApp(name) {
70
+ return getAppCompat(name);
71
+ }
72
+
73
+ /**
74
+ * Sets the log level across all Firebase SDKs.
75
+ * @param {LogLevelString} logLevel - The log level to set ('debug', 'verbose', 'info', 'warn', 'error', 'silent').
76
+ * @returns {void}
77
+ */
78
+ export function setLogLevel(logLevel) {
79
+ return setLogLevelCompat(logLevel);
80
+ }
package/lib/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- module.exports = '20.2.1';
2
+ module.exports = '20.4.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-firebase/app",
3
- "version": "20.2.1",
3
+ "version": "20.4.0",
4
4
  "author": "Invertase <oss@invertase.io> (http://invertase.io)",
5
5
  "description": "A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Admob, Analytics, Auth, Crash Reporting, Cloud Firestore, Database, Dynamic Links, Functions, Messaging (FCM), Remote Config, Storage and more.",
6
6
  "main": "lib/index.js",
@@ -58,10 +58,10 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "firebase": "10.12.2",
61
- "opencollective-postinstall": "^2.0.3",
62
61
  "superstruct": "^0.6.2"
63
62
  },
64
63
  "devDependencies": {
64
+ "@react-native-async-storage/async-storage": "^1.24.0",
65
65
  "expo": "^50.0.19"
66
66
  },
67
67
  "peerDependenciesMeta": {
@@ -89,5 +89,5 @@
89
89
  "playServicesAuth": "21.2.0"
90
90
  }
91
91
  },
92
- "gitHead": "2c787c2dbefbefcc637018e1e5d74a73b39600ab"
92
+ "gitHead": "3ac3e9623674a8db52c111b4aa0a85a883260116"
93
93
  }
@@ -1,33 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import {
3
- deleteApp as deleteAppCompat,
4
- getApp,
5
- getApps,
6
- initializeApp,
7
- setLogLevel,
8
- } from '../internal';
9
-
10
- /**
11
- * Renders this app unusable and frees the resources of all associated services.
12
- * @param app - FirebaseApp - The app to delete.
13
- * @returns
14
- */
15
- export function deleteApp(app) {
16
- return deleteAppCompat(app.name, app._nativeInitialized);
17
- }
18
-
19
- /**
20
- * Registers a library's name and version for platform logging purposes.
21
- */
22
- export function registerVersion() {
23
- throw new Error('registerVersion is only supported on Web');
24
- }
25
-
26
- /**
27
- * Sets log handler for all Firebase SDKs.
28
- */
29
- export function onLog(logCallback, options) {
30
- throw new Error('onLog is only supported on Web');
31
- }
32
-
33
- export { getApps, initializeApp, getApp, setLogLevel };