@react-native-firebase/app 21.11.0 → 21.12.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 +6 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseVersion.java +1 -1
- package/ios/RNFBApp/RNFBVersion.m +1 -1
- package/lib/internal/index.js +1 -0
- package/lib/internal/logger.d.ts +85 -0
- package/lib/internal/logger.js +241 -0
- package/lib/internal/registry/app.js +3 -0
- package/lib/modular/index.d.ts +14 -4
- package/lib/modular/index.js +8 -5
- package/lib/version.js +1 -1
- package/package.json +2 -2
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
|
+
## [21.12.0](https://github.com/invertase/react-native-firebase/compare/v21.11.0...v21.12.0) (2025-03-03)
|
7
|
+
|
8
|
+
### Features
|
9
|
+
|
10
|
+
- vertexAI package support ([#8236](https://github.com/invertase/react-native-firebase/issues/8236)) ([a1d1361](https://github.com/invertase/react-native-firebase/commit/a1d13610f443a96a7195b3f769f77d9676c0e577))
|
11
|
+
|
6
12
|
## [21.11.0](https://github.com/invertase/react-native-firebase/compare/v21.10.1...v21.11.0) (2025-02-20)
|
7
13
|
|
8
14
|
**Note:** Version bump only for package @react-native-firebase/app
|
package/lib/internal/index.js
CHANGED
@@ -0,0 +1,85 @@
|
|
1
|
+
export type LogLevelString = 'debug' | 'verbose' | 'info' | 'warn' | 'error' | 'silent';
|
2
|
+
|
3
|
+
export interface LogOptions {
|
4
|
+
level: LogLevelString;
|
5
|
+
}
|
6
|
+
|
7
|
+
export type LogCallback = (callbackParams: LogCallbackParams) => void;
|
8
|
+
|
9
|
+
export interface LogCallbackParams {
|
10
|
+
level: LogLevelString;
|
11
|
+
message: string;
|
12
|
+
args: unknown[];
|
13
|
+
type: string;
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* A container for all of the Logger instances
|
18
|
+
*/
|
19
|
+
export const instances: Logger[] = [];
|
20
|
+
|
21
|
+
/**
|
22
|
+
* The JS SDK supports 5 log levels and also allows a user the ability to
|
23
|
+
* silence the logs altogether.
|
24
|
+
*
|
25
|
+
* The order is a follows:
|
26
|
+
* DEBUG < VERBOSE < INFO < WARN < ERROR
|
27
|
+
*
|
28
|
+
* All of the log types above the current log level will be captured (i.e. if
|
29
|
+
* you set the log level to `INFO`, errors will still be logged, but `DEBUG` and
|
30
|
+
* `VERBOSE` logs will not)
|
31
|
+
*/
|
32
|
+
export enum LogLevel {
|
33
|
+
DEBUG,
|
34
|
+
VERBOSE,
|
35
|
+
INFO,
|
36
|
+
WARN,
|
37
|
+
ERROR,
|
38
|
+
SILENT,
|
39
|
+
}
|
40
|
+
|
41
|
+
type LevelStringToEnum = {
|
42
|
+
debug: LogLevel.DEBUG;
|
43
|
+
verbose: LogLevel.VERBOSE;
|
44
|
+
info: LogLevel.INFO;
|
45
|
+
warn: LogLevel.WARN;
|
46
|
+
error: LogLevel.ERROR;
|
47
|
+
silent: LogLevel.SILENT;
|
48
|
+
};
|
49
|
+
|
50
|
+
/**
|
51
|
+
* The default log level
|
52
|
+
*/
|
53
|
+
type DefaultLogLevel = LogLevel.INFO;
|
54
|
+
|
55
|
+
/**
|
56
|
+
* We allow users the ability to pass their own log handler. We will pass the
|
57
|
+
* type of log, the current log level, and any other arguments passed (i.e. the
|
58
|
+
* messages that the user wants to log) to this function.
|
59
|
+
*/
|
60
|
+
export type LogHandler = (loggerInstance: Logger, logType: LogLevel, ...args: unknown[]) => void;
|
61
|
+
|
62
|
+
export class Logger {
|
63
|
+
constructor(name: string);
|
64
|
+
|
65
|
+
get logLevel(): LogLevel;
|
66
|
+
set logLevel(val: LogLevel);
|
67
|
+
|
68
|
+
setLogLevel(val: LogLevel | LogLevelString): void;
|
69
|
+
|
70
|
+
get logHandler(): LogHandler;
|
71
|
+
set logHandler(val: LogHandler);
|
72
|
+
|
73
|
+
get userLogHandler(): LogHandler | null;
|
74
|
+
set userLogHandler(val: LogHandler | null);
|
75
|
+
|
76
|
+
debug(...args: unknown[]): void;
|
77
|
+
log(...args: unknown[]): void;
|
78
|
+
info(...args: unknown[]): void;
|
79
|
+
warn(...args: unknown[]): void;
|
80
|
+
error(...args: unknown[]): void;
|
81
|
+
}
|
82
|
+
|
83
|
+
export const setLogLevel: (level: LogLevelString | LogLevel) => void;
|
84
|
+
|
85
|
+
export const setUserLogHandler: (logCallback: LogCallback | null, options?: LogOptions) => void;
|
@@ -0,0 +1,241 @@
|
|
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
|
+
/**
|
19
|
+
* @typedef {import('./logger').Logger} Logger
|
20
|
+
* @typedef {import('./logger').setLogLevel} setLogLevel
|
21
|
+
* @typedef {import('./logger').setUserLogHandler} setUserLogHandler
|
22
|
+
* @typedef {import('./logger').LogHandler} LogHandler
|
23
|
+
* @typedef {import('./logger').LogLevel} LogLevel
|
24
|
+
* @typedef {import('./logger').LevelStringToEnum} LevelStringToEnum
|
25
|
+
* @typedef {import('./logger').DefaultLogLevel} DefaultLogLevel
|
26
|
+
*/
|
27
|
+
|
28
|
+
const LogLevel = {
|
29
|
+
DEBUG: 0,
|
30
|
+
VERBOSE: 1,
|
31
|
+
INFO: 2,
|
32
|
+
WARN: 3,
|
33
|
+
ERROR: 4,
|
34
|
+
SILENT: 5,
|
35
|
+
};
|
36
|
+
|
37
|
+
// mimic the LogLevel in firebase-js-sdk TS
|
38
|
+
const reverseLogLevel = obj => {
|
39
|
+
const reversed = {};
|
40
|
+
for (const [key, value] of Object.entries(obj)) {
|
41
|
+
reversed[value] = key;
|
42
|
+
}
|
43
|
+
return reversed;
|
44
|
+
};
|
45
|
+
|
46
|
+
const LogLevelReversed = reverseLogLevel(LogLevel);
|
47
|
+
|
48
|
+
const levelStringToEnum = {
|
49
|
+
debug: LogLevel.DEBUG,
|
50
|
+
verbose: LogLevel.VERBOSE,
|
51
|
+
info: LogLevel.INFO,
|
52
|
+
warn: LogLevel.WARN,
|
53
|
+
error: LogLevel.ERROR,
|
54
|
+
silent: LogLevel.SILENT,
|
55
|
+
};
|
56
|
+
|
57
|
+
/**
|
58
|
+
* By default, `console.debug` is not displayed in the developer console (in
|
59
|
+
* chrome). To avoid forcing users to have to opt-in to these logs twice
|
60
|
+
* (i.e. once for firebase, and once in the console), we are sending `DEBUG`
|
61
|
+
* logs to the `console.log` function.
|
62
|
+
*/
|
63
|
+
const ConsoleMethod = {
|
64
|
+
[LogLevel.DEBUG]: 'log',
|
65
|
+
[LogLevel.VERBOSE]: 'log',
|
66
|
+
[LogLevel.INFO]: 'info',
|
67
|
+
[LogLevel.WARN]: 'warn',
|
68
|
+
[LogLevel.ERROR]: 'error',
|
69
|
+
};
|
70
|
+
|
71
|
+
/**
|
72
|
+
* The default log handler will forward DEBUG, VERBOSE, INFO, WARN, and ERROR
|
73
|
+
* messages on to their corresponding console counterparts (if the log method
|
74
|
+
* is supported by the current log level)
|
75
|
+
* @type {LogHandler}
|
76
|
+
*/
|
77
|
+
const defaultLogHandler = (instance, logType, ...args) => {
|
78
|
+
if (logType < instance.logLevel) {
|
79
|
+
return;
|
80
|
+
}
|
81
|
+
const now = new Date().toISOString();
|
82
|
+
const method = ConsoleMethod[logType];
|
83
|
+
if (method) {
|
84
|
+
// 'log' | 'info' | 'warn' | 'error'
|
85
|
+
// eslint-disable-next-line no-console
|
86
|
+
console[method](`[${now}] ${instance.name}:`, ...args);
|
87
|
+
} else {
|
88
|
+
throw new Error(`Attempted to log a message with an invalid logType (value: ${logType})`);
|
89
|
+
}
|
90
|
+
};
|
91
|
+
|
92
|
+
const defaultLogLevel = LogLevel.INFO;
|
93
|
+
|
94
|
+
export const instances = [];
|
95
|
+
|
96
|
+
/**
|
97
|
+
* @type {Logger}
|
98
|
+
*/
|
99
|
+
|
100
|
+
export class Logger {
|
101
|
+
/**
|
102
|
+
* Gives you an instance of a Logger to capture messages according to
|
103
|
+
* Firebase's logging scheme.
|
104
|
+
*
|
105
|
+
* @param name The name that the logs will be associated with
|
106
|
+
*/
|
107
|
+
constructor(name) {
|
108
|
+
/**
|
109
|
+
* Capture the current instance for later use
|
110
|
+
*/
|
111
|
+
this.name = name;
|
112
|
+
instances.push(this);
|
113
|
+
}
|
114
|
+
|
115
|
+
/**
|
116
|
+
* The log level of the given Logger instance.
|
117
|
+
*/
|
118
|
+
_logLevel = defaultLogLevel;
|
119
|
+
|
120
|
+
get logLevel() {
|
121
|
+
return this._logLevel;
|
122
|
+
}
|
123
|
+
|
124
|
+
set logLevel(val) {
|
125
|
+
if (!(val in LogLevel)) {
|
126
|
+
throw new TypeError(`Invalid value "${val}" assigned to \`logLevel\``);
|
127
|
+
}
|
128
|
+
this._logLevel = val;
|
129
|
+
}
|
130
|
+
|
131
|
+
// Workaround for setter/getter having to be the same type.
|
132
|
+
setLogLevel(val) {
|
133
|
+
this._logLevel = typeof val === 'string' ? levelStringToEnum[val] : val;
|
134
|
+
}
|
135
|
+
|
136
|
+
/**
|
137
|
+
* The main (internal) log handler for the Logger instance.
|
138
|
+
* Can be set to a new function in internal package code but not by user.
|
139
|
+
*/
|
140
|
+
_logHandler = defaultLogHandler;
|
141
|
+
get logHandler() {
|
142
|
+
return this._logHandler;
|
143
|
+
}
|
144
|
+
set logHandler(val) {
|
145
|
+
if (typeof val !== 'function') {
|
146
|
+
throw new TypeError('Value assigned to `logHandler` must be a function');
|
147
|
+
}
|
148
|
+
this._logHandler = val;
|
149
|
+
}
|
150
|
+
|
151
|
+
/**
|
152
|
+
* The optional, additional, user-defined log handler for the Logger instance.
|
153
|
+
*/
|
154
|
+
_userLogHandler = null;
|
155
|
+
get userLogHandler() {
|
156
|
+
return this._userLogHandler;
|
157
|
+
}
|
158
|
+
set userLogHandler(val) {
|
159
|
+
this._userLogHandler = val;
|
160
|
+
}
|
161
|
+
|
162
|
+
/**
|
163
|
+
* The functions below are all based on the `console` interface
|
164
|
+
*/
|
165
|
+
|
166
|
+
debug(...args) {
|
167
|
+
this._userLogHandler && this._userLogHandler(this, LogLevel.DEBUG, ...args);
|
168
|
+
this._logHandler(this, LogLevel.DEBUG, ...args);
|
169
|
+
}
|
170
|
+
log(...args) {
|
171
|
+
this._userLogHandler && this._userLogHandler(this, LogLevel.VERBOSE, ...args);
|
172
|
+
this._logHandler(this, LogLevel.VERBOSE, ...args);
|
173
|
+
}
|
174
|
+
info(...args) {
|
175
|
+
this._userLogHandler && this._userLogHandler(this, LogLevel.INFO, ...args);
|
176
|
+
this._logHandler(this, LogLevel.INFO, ...args);
|
177
|
+
}
|
178
|
+
warn(...args) {
|
179
|
+
this._userLogHandler && this._userLogHandler(this, LogLevel.WARN, ...args);
|
180
|
+
this._logHandler(this, LogLevel.WARN, ...args);
|
181
|
+
}
|
182
|
+
error(...args) {
|
183
|
+
this._userLogHandler && this._userLogHandler(this, LogLevel.ERROR, ...args);
|
184
|
+
this._logHandler(this, LogLevel.ERROR, ...args);
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
/**
|
189
|
+
* @type {setLogLevel}
|
190
|
+
*/
|
191
|
+
export function setLogLevelInternal(level) {
|
192
|
+
instances.forEach(inst => {
|
193
|
+
inst.setLogLevel(level);
|
194
|
+
});
|
195
|
+
}
|
196
|
+
|
197
|
+
/**
|
198
|
+
* @type {setUserLogHandler}
|
199
|
+
*/
|
200
|
+
export function setUserLogHandler(logCallback, options) {
|
201
|
+
for (const instance of instances) {
|
202
|
+
let customLogLevel = null;
|
203
|
+
if (options && options.level) {
|
204
|
+
customLogLevel = levelStringToEnum[options.level];
|
205
|
+
}
|
206
|
+
if (logCallback === null) {
|
207
|
+
instance.userLogHandler = null;
|
208
|
+
} else {
|
209
|
+
instance.userLogHandler = (instance, level, ...args) => {
|
210
|
+
const message = args
|
211
|
+
.map(arg => {
|
212
|
+
if (arg == null) {
|
213
|
+
return null;
|
214
|
+
} else if (typeof arg === 'string') {
|
215
|
+
return arg;
|
216
|
+
} else if (typeof arg === 'number' || typeof arg === 'boolean') {
|
217
|
+
return arg.toString();
|
218
|
+
} else if (arg instanceof Error) {
|
219
|
+
return arg.message;
|
220
|
+
} else {
|
221
|
+
try {
|
222
|
+
return JSON.stringify(arg);
|
223
|
+
} catch (_ignored) {
|
224
|
+
return null;
|
225
|
+
}
|
226
|
+
}
|
227
|
+
})
|
228
|
+
.filter(arg => arg)
|
229
|
+
.join(' ');
|
230
|
+
if (level >= (customLogLevel ?? instance.logLevel)) {
|
231
|
+
logCallback({
|
232
|
+
level: LogLevelReversed[level].toLowerCase(),
|
233
|
+
message,
|
234
|
+
args,
|
235
|
+
type: instance.name,
|
236
|
+
});
|
237
|
+
}
|
238
|
+
};
|
239
|
+
}
|
240
|
+
}
|
241
|
+
}
|
@@ -29,6 +29,7 @@ import FirebaseApp from '../../FirebaseApp';
|
|
29
29
|
import { DEFAULT_APP_NAME } from '../constants';
|
30
30
|
import { setReactNativeAsyncStorageInternal } from '../asyncStorage';
|
31
31
|
import { getAppModule } from './nativeModule';
|
32
|
+
import { setLogLevelInternal } from '../logger';
|
32
33
|
|
33
34
|
const APP_REGISTRY = {};
|
34
35
|
let onAppCreateFn = null;
|
@@ -208,6 +209,8 @@ export function setLogLevel(logLevel) {
|
|
208
209
|
if (!['error', 'warn', 'info', 'debug', 'verbose'].includes(logLevel)) {
|
209
210
|
throw new Error('LogLevel must be one of "error", "warn", "info", "debug", "verbose"');
|
210
211
|
}
|
212
|
+
// This is setting LogLevel for VertexAI which does not wrap around native SDK
|
213
|
+
setLogLevelInternal(logLevel);
|
211
214
|
|
212
215
|
if (isIOS || isOther) {
|
213
216
|
getAppModule().setLogLevel(logLevel);
|
package/lib/modular/index.d.ts
CHANGED
@@ -25,13 +25,23 @@ export function registerVersion(
|
|
25
25
|
): Promise<void>;
|
26
26
|
|
27
27
|
/**
|
28
|
-
* Sets log handler for all Firebase SDKs.
|
28
|
+
* Sets log handler for all Firebase SDKs. Currently only supported on VertexAI.
|
29
29
|
* @param logCallback - The callback function to handle logs.
|
30
30
|
* @param options - Optional settings for log handling.
|
31
|
-
* @returns
|
32
|
-
* @throws Error - onLog is only supported on Web
|
31
|
+
* @returns <void>
|
33
32
|
*/
|
34
|
-
|
33
|
+
|
34
|
+
interface LogCallbackParams {
|
35
|
+
level: LogLevelString;
|
36
|
+
message: string;
|
37
|
+
args: unknown[];
|
38
|
+
type: string;
|
39
|
+
}
|
40
|
+
|
41
|
+
export function onLog(
|
42
|
+
logCallback: (callbackParams: LogCallbackParams) => void,
|
43
|
+
options?: any,
|
44
|
+
): void;
|
35
45
|
|
36
46
|
/**
|
37
47
|
* Gets the list of all initialized apps.
|
package/lib/modular/index.js
CHANGED
@@ -7,12 +7,15 @@ import {
|
|
7
7
|
initializeApp as initializeAppCompat,
|
8
8
|
setLogLevel as setLogLevelCompat,
|
9
9
|
} from '../internal';
|
10
|
+
import { setUserLogHandler } from '../internal/logger';
|
10
11
|
import sdkVersion from '../version';
|
11
12
|
|
12
13
|
/**
|
13
14
|
* @typedef {import('..').ReactNativeFirebase.FirebaseApp} FirebaseApp
|
14
15
|
* @typedef {import('..').ReactNativeFirebase.FirebaseAppOptions} FirebaseAppOptions
|
15
16
|
* @typedef {import('..').ReactNativeFirebase.LogLevelString} LogLevelString
|
17
|
+
* @typedef {import('../internal/logger').LogCallback} LogCallback
|
18
|
+
* @typedef {import('../internal/logger').LogOptions} LogOptions
|
16
19
|
*/
|
17
20
|
|
18
21
|
/**
|
@@ -36,13 +39,13 @@ export function registerVersion(libraryKeyOrName, version, variant) {
|
|
36
39
|
}
|
37
40
|
|
38
41
|
/**
|
39
|
-
* Sets log handler for
|
40
|
-
* @param {
|
41
|
-
* @param {
|
42
|
-
* @returns {
|
42
|
+
* Sets log handler for VertexAI only currently.
|
43
|
+
* @param {LogCallback | null} logCallback - The callback function to handle logs.
|
44
|
+
* @param {LogOptions} [options] - Optional settings for log handling.
|
45
|
+
* @returns {void}
|
43
46
|
*/
|
44
47
|
export function onLog(logCallback, options) {
|
45
|
-
|
48
|
+
setUserLogHandler(logCallback, options);
|
46
49
|
}
|
47
50
|
|
48
51
|
/**
|
package/lib/version.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
// Generated by genversion.
|
2
|
-
module.exports = '21.
|
2
|
+
module.exports = '21.12.0';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@react-native-firebase/app",
|
3
|
-
"version": "21.
|
3
|
+
"version": "21.12.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",
|
@@ -90,5 +90,5 @@
|
|
90
90
|
"firebaseAppDistributionGradle": "5.1.1"
|
91
91
|
}
|
92
92
|
},
|
93
|
-
"gitHead": "
|
93
|
+
"gitHead": "00a5540bc2d8007858dd01903d8f8c171587a766"
|
94
94
|
}
|