@react-native-firebase/app 20.2.1 → 20.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +6 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseVersion.java +1 -1
- package/ios/RNFBApp/RNFBVersion.m +1 -1
- package/lib/index.d.ts +38 -0
- package/lib/internal/asyncStorage.js +47 -0
- package/lib/internal/registry/app.js +30 -2
- package/lib/internal/registry/namespace.js +2 -0
- package/lib/version.js +1 -1
- package/package.json +3 -3
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.3.0](https://github.com/invertase/react-native-firebase/compare/v20.2.1...v20.3.0) (2024-07-19)
|
7
|
+
|
8
|
+
### Bug Fixes
|
9
|
+
|
10
|
+
- **other:** add api for persistence via Async Storage ([030eea9](https://github.com/invertase/react-native-firebase/commit/030eea91f297a4014ab86cfb141ae938f200c5e5))
|
11
|
+
|
6
12
|
## [20.2.1](https://github.com/invertase/react-native-firebase/compare/v20.2.0...v20.2.1) (2024-07-17)
|
7
13
|
|
8
14
|
**Note:** Version bump only for package @react-native-firebase/app
|
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
|
*/
|
@@ -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,
|
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,
|
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
|
*/
|
@@ -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';
|
@@ -241,6 +242,7 @@ export function firebaseAppModuleProxy(app, moduleNamespace) {
|
|
241
242
|
export function createFirebaseRoot() {
|
242
243
|
FIREBASE_ROOT = {
|
243
244
|
initializeApp,
|
245
|
+
setReactNativeAsyncStorage,
|
244
246
|
get app() {
|
245
247
|
return getApp;
|
246
248
|
},
|
package/lib/version.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
// Generated by genversion.
|
2
|
-
module.exports = '20.
|
2
|
+
module.exports = '20.3.0';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@react-native-firebase/app",
|
3
|
-
"version": "20.
|
3
|
+
"version": "20.3.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": "
|
92
|
+
"gitHead": "a916b37b022cf40588fa0fd915b7ab901e2458d0"
|
93
93
|
}
|