@react-native-firebase/crashlytics 23.7.0 → 23.8.1

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.
Files changed (63) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/commonjs/handlers.js +175 -0
  3. package/dist/commonjs/handlers.js.map +1 -0
  4. package/dist/commonjs/index.js +38 -0
  5. package/dist/commonjs/index.js.map +1 -0
  6. package/dist/commonjs/modular.js +256 -0
  7. package/dist/commonjs/modular.js.map +1 -0
  8. package/dist/commonjs/namespaced.js +138 -0
  9. package/dist/commonjs/namespaced.js.map +1 -0
  10. package/dist/commonjs/package.json +1 -0
  11. package/dist/commonjs/types/crashlytics.js +47 -0
  12. package/dist/commonjs/types/crashlytics.js.map +1 -0
  13. package/dist/commonjs/version.js +9 -0
  14. package/dist/commonjs/version.js.map +1 -0
  15. package/{lib → dist/module}/handlers.js +39 -36
  16. package/dist/module/handlers.js.map +1 -0
  17. package/dist/module/index.js +28 -0
  18. package/dist/module/index.js.map +1 -0
  19. package/{lib/modular/index.js → dist/module/modular.js} +37 -43
  20. package/dist/module/modular.js.map +1 -0
  21. package/dist/module/namespaced.js +135 -0
  22. package/dist/module/namespaced.js.map +1 -0
  23. package/dist/module/package.json +1 -0
  24. package/dist/module/types/crashlytics.js +43 -0
  25. package/dist/module/types/crashlytics.js.map +1 -0
  26. package/dist/module/version.js +5 -0
  27. package/dist/module/version.js.map +1 -0
  28. package/dist/typescript/commonjs/lib/handlers.d.ts +28 -0
  29. package/dist/typescript/commonjs/lib/handlers.d.ts.map +1 -0
  30. package/dist/typescript/commonjs/lib/index.d.ts +5 -0
  31. package/dist/typescript/commonjs/lib/index.d.ts.map +1 -0
  32. package/{lib/modular/index.d.ts → dist/typescript/commonjs/lib/modular.d.ts} +37 -40
  33. package/dist/typescript/commonjs/lib/modular.d.ts.map +1 -0
  34. package/dist/typescript/commonjs/lib/namespaced.d.ts +12 -0
  35. package/dist/typescript/commonjs/lib/namespaced.d.ts.map +1 -0
  36. package/dist/typescript/commonjs/lib/types/crashlytics.d.ts +117 -0
  37. package/dist/typescript/commonjs/lib/types/crashlytics.d.ts.map +1 -0
  38. package/dist/typescript/commonjs/lib/version.d.ts +2 -0
  39. package/dist/typescript/commonjs/lib/version.d.ts.map +1 -0
  40. package/dist/typescript/commonjs/package.json +1 -0
  41. package/dist/typescript/module/lib/handlers.d.ts +28 -0
  42. package/dist/typescript/module/lib/handlers.d.ts.map +1 -0
  43. package/dist/typescript/module/lib/index.d.ts +5 -0
  44. package/dist/typescript/module/lib/index.d.ts.map +1 -0
  45. package/dist/typescript/module/lib/modular.d.ts +193 -0
  46. package/dist/typescript/module/lib/modular.d.ts.map +1 -0
  47. package/dist/typescript/module/lib/namespaced.d.ts +12 -0
  48. package/dist/typescript/module/lib/namespaced.d.ts.map +1 -0
  49. package/dist/typescript/module/lib/types/crashlytics.d.ts +117 -0
  50. package/dist/typescript/module/lib/types/crashlytics.d.ts.map +1 -0
  51. package/dist/typescript/module/lib/version.d.ts +2 -0
  52. package/dist/typescript/module/lib/version.d.ts.map +1 -0
  53. package/dist/typescript/module/package.json +1 -0
  54. package/lib/handlers.ts +196 -0
  55. package/lib/index.ts +26 -0
  56. package/lib/modular.ts +249 -0
  57. package/lib/{index.js → namespaced.ts} +51 -22
  58. package/lib/types/crashlytics.ts +159 -0
  59. package/lib/version.ts +2 -0
  60. package/package.json +50 -8
  61. package/tsconfig.json +21 -0
  62. package/lib/index.d.ts +0 -287
  63. package/lib/version.js +0 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modular.d.ts","sourceRoot":"","sources":["../../../../lib/modular.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;;;GAMG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAE5C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAGhF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAG3E;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAGtF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAGpD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAGnE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAG9F;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAGhE;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,SAAS,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGjF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGjG;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GACpC,OAAO,CAAC,IAAI,CAAC,CAGf;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,+BAA+B,CAC7C,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,IAAI,CAAC,CAOf"}
@@ -0,0 +1,12 @@
1
+ import type { Crashlytics, Statics } from './types/crashlytics';
2
+ import type { ReactNativeFirebase } from '@react-native-firebase/app';
3
+ export declare const SDK_VERSION = "23.8.1";
4
+ type CrashlyticsNamespace = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<Crashlytics, Statics> & {
5
+ crashlytics: ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<Crashlytics, Statics>;
6
+ firebase: ReactNativeFirebase.Module;
7
+ app(name?: string): ReactNativeFirebase.FirebaseApp;
8
+ };
9
+ declare const _default: CrashlyticsNamespace;
10
+ export default _default;
11
+ export declare const firebase: ReactNativeFirebase.FirebaseNamespacedExport<"crashlytics", Crashlytics, Statics, false>;
12
+ //# sourceMappingURL=namespaced.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespaced.d.ts","sourceRoot":"","sources":["../../../../lib/namespaced.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAuHtE,eAAO,MAAM,WAAW,WAAU,CAAC;AAanC,KAAK,oBAAoB,GAAG,mBAAmB,CAAC,+BAA+B,CAC7E,WAAW,EACX,OAAO,CACR,GAAG;IACF,WAAW,EAAE,mBAAmB,CAAC,+BAA+B,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACvF,QAAQ,EAAE,mBAAmB,CAAC,MAAM,CAAC;IACrC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAAC,WAAW,CAAC;CACrD,CAAC;wBAIgD,oBAAoB;AAAtE,wBAAuE;AAKvE,eAAO,MAAM,QAAQ,EACa,mBAAmB,CAAC,wBAAwB,CAC1E,aAAa,EACb,WAAW,EACX,OAAO,EACP,KAAK,CACN,CAAC"}
@@ -0,0 +1,117 @@
1
+ import type { ReactNativeFirebase } from '@react-native-firebase/app';
2
+ /**
3
+ * Crashlytics module instance - returned from firebase.crashlytics() or firebase.app().crashlytics()
4
+ */
5
+ export interface Crashlytics extends ReactNativeFirebase.FirebaseModule {
6
+ /** The FirebaseApp this module is associated with */
7
+ app: ReactNativeFirebase.FirebaseApp;
8
+ /**
9
+ * Whether Crashlytics reporting is enabled.
10
+ */
11
+ readonly isCrashlyticsCollectionEnabled: boolean;
12
+ /**
13
+ * Determines whether there are any unsent crash reports cached on the device.
14
+ * The callback only executes if automatic data collection is disabled.
15
+ *
16
+ * @throws Error if Crashlytics collection is enabled (reports are automatically sent)
17
+ */
18
+ checkForUnsentReports(): Promise<boolean>;
19
+ /**
20
+ * Cause your app to crash for testing purposes. This is a native crash and will not contain a javascript stack trace.
21
+ * Note that crashes are intercepted by debuggers on iOS so no report will be seen under those conditions.
22
+ */
23
+ crash(): void;
24
+ /**
25
+ * Deletes any unsent reports on the device. This method only applies if automatic data collection is disabled.
26
+ */
27
+ deleteUnsentReports(): Promise<void>;
28
+ /**
29
+ * Returns a boolean value indicating whether the app crashed during the previous execution.
30
+ */
31
+ didCrashOnPreviousExecution(): Promise<boolean>;
32
+ /**
33
+ * Log a message that will appear in any subsequent Crash or Non-fatal error reports.
34
+ *
35
+ * @param message The message to log.
36
+ */
37
+ log(message: string): void;
38
+ /**
39
+ * Record a JavaScript Error.
40
+ *
41
+ * The JavaScript stack trace is converted into a mock native iOS or Android exception before submission.
42
+ *
43
+ * @param error Expects an instance of Error; e.g. classes that extend Error will also be supported.
44
+ * @param jsErrorName Optional string containing Javascript error name
45
+ */
46
+ recordError(error: Error, jsErrorName?: string): void;
47
+ /**
48
+ * Enqueues any unsent reports on the device to upload to Crashlytics. This method only applies if
49
+ * automatic data collection is disabled.
50
+ */
51
+ sendUnsentReports(): void;
52
+ /**
53
+ * Sets a string value to be associated with the given attribute name which will be visible in the Firebase Crashlytics console.
54
+ *
55
+ * @param name The name of the attribute to set.
56
+ * @param value A string value for the given attribute.
57
+ */
58
+ setAttribute(name: string, value: string): Promise<null>;
59
+ /**
60
+ * Like `setAttribute` but for multiple attributes.
61
+ *
62
+ * @param attributes An object of key/value attribute name and values.
63
+ */
64
+ setAttributes(attributes: {
65
+ [key: string]: string;
66
+ }): Promise<null>;
67
+ /**
68
+ * Specify a user identifier which will be visible in the Firebase Crashlytics console.
69
+ *
70
+ * It is recommended for privacy purposes that this value be a value that's meaningless to a third-party
71
+ * observer; such as an arbitrary string that ties an end-user to a record in your system e.g. a database record id.
72
+ *
73
+ * @param userId An arbitrary string that ties an end-user to a record in your system e.g. a database record id.
74
+ */
75
+ setUserId(userId: string): Promise<null>;
76
+ /**
77
+ * Enable/disable Crashlytics reporting.
78
+ *
79
+ * Use this for opt-in first user data collection flows combined with `firebase.json` settings to disable auto collection.
80
+ *
81
+ * @param enabled A boolean value representing whether to enable Crashlytics error collection.
82
+ */
83
+ setCrashlyticsCollectionEnabled(enabled: boolean): Promise<null>;
84
+ }
85
+ /**
86
+ * Static properties available on firebase.crashlytics
87
+ */
88
+ export interface Statics {
89
+ SDK_VERSION: string;
90
+ }
91
+ /**
92
+ * FirebaseApp type with crashlytics() method.
93
+ * @deprecated Import FirebaseApp from '@react-native-firebase/app' instead.
94
+ * The crashlytics() method is added via module augmentation.
95
+ */
96
+ export type FirebaseApp = ReactNativeFirebase.FirebaseApp;
97
+ declare module '@react-native-firebase/app' {
98
+ namespace ReactNativeFirebase {
99
+ interface Module {
100
+ crashlytics: FirebaseModuleWithStaticsAndApp<Crashlytics, Statics>;
101
+ }
102
+ interface FirebaseApp {
103
+ crashlytics(): Crashlytics;
104
+ }
105
+ }
106
+ }
107
+ type _Statics = Statics;
108
+ /**
109
+ * @deprecated Use the exported types directly instead.
110
+ * FirebaseCrashlyticsTypes namespace is kept for backwards compatibility.
111
+ */
112
+ export declare namespace FirebaseCrashlyticsTypes {
113
+ type Module = Crashlytics;
114
+ type Statics = _Statics;
115
+ }
116
+ export {};
117
+ //# sourceMappingURL=crashlytics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crashlytics.d.ts","sourceRoot":"","sources":["../../../../../lib/types/crashlytics.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAItE;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,mBAAmB,CAAC,cAAc;IACrE,qDAAqD;IACrD,GAAG,EAAE,mBAAmB,CAAC,WAAW,CAAC;IAErC;;OAEG;IACH,QAAQ,CAAC,8BAA8B,EAAE,OAAO,CAAC;IAEjD;;;;;OAKG;IACH,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAE1C;;;OAGG;IACH,KAAK,IAAI,IAAI,CAAC;IAEd;;OAEG;IACH,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAErC;;OAEG;IACH,2BAA2B,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAEhD;;;;OAIG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAE3B;;;;;;;OAOG;IACH,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtD;;;OAGG;IACH,iBAAiB,IAAI,IAAI,CAAC;IAE1B;;;;;OAKG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzD;;;;OAIG;IACH,aAAa,CAAC,UAAU,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpE;;;;;;;OAOG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzC;;;;;;OAMG;IACH,+BAA+B,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClE;AAID;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,mBAAmB,CAAC,WAAW,CAAC;AAK1D,OAAO,QAAQ,4BAA4B,CAAC;IAC1C,UAAU,mBAAmB,CAAC;QAC5B,UAAU,MAAM;YACd,WAAW,EAAE,+BAA+B,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;SACpE;QACD,UAAU,WAAW;YACnB,WAAW,IAAI,WAAW,CAAC;SAC5B;KACF;CACF;AAGD,KAAK,QAAQ,GAAG,OAAO,CAAC;AAExB;;;GAGG;AAEH,yBAAiB,wBAAwB,CAAC;IAExC,KAAY,MAAM,GAAG,WAAW,CAAC;IACjC,KAAY,OAAO,GAAG,QAAQ,CAAC;CAChC"}
@@ -0,0 +1,2 @@
1
+ export declare const version = "23.8.1";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../../lib/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,WAAW,CAAC"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,196 @@
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
+ import { isError, once } from '@react-native-firebase/app/lib/common';
20
+ // @ts-ignore - No declaration file for promise/setimmediate/rejection-tracking
21
+ import tracking from 'promise/setimmediate/rejection-tracking';
22
+ import StackTrace from 'stacktrace-js';
23
+ export const FATAL_FLAG = 'com.firebase.crashlytics.reactnative.fatal';
24
+
25
+ interface NativeErrorFrame {
26
+ src: string;
27
+ line: number;
28
+ col: number;
29
+ fn: string;
30
+ file: string;
31
+ }
32
+
33
+ interface NativeErrorObj {
34
+ message: string;
35
+ isUnhandledRejection: boolean;
36
+ frames: NativeErrorFrame[];
37
+ }
38
+
39
+ interface NativeModule {
40
+ isCrashlyticsCollectionEnabled: boolean;
41
+ isErrorGenerationOnJSCrashEnabled: boolean;
42
+ isCrashlyticsJavascriptExceptionHandlerChainingEnabled: boolean;
43
+ logPromise(message: string): Promise<void>;
44
+ setAttribute(name: string, value: string): Promise<void>;
45
+ recordErrorPromise(errorObj: NativeErrorObj): Promise<void>;
46
+ crashWithStackPromise(errorObj: NativeErrorObj): Promise<void>;
47
+ }
48
+
49
+ export function createNativeErrorObj(
50
+ error: Error,
51
+ stackFrames: StackTrace.StackFrame[],
52
+ isUnhandledRejection: boolean,
53
+ jsErrorName?: string,
54
+ ): NativeErrorObj {
55
+ const nativeObj: NativeErrorObj = {
56
+ message: `${error.message}`,
57
+ isUnhandledRejection,
58
+ frames: [],
59
+ };
60
+
61
+ if (jsErrorName) {
62
+ // Option to fix crashlytics display and alerting. You can add an error name to the recordError function
63
+ nativeObj.frames.push({
64
+ src: '<unknown>',
65
+ line: 0,
66
+ col: 0,
67
+ fn: '<unknown>',
68
+ file: jsErrorName,
69
+ });
70
+ }
71
+
72
+ for (let i = 0; i < stackFrames.length; i++) {
73
+ const frame = stackFrames[i];
74
+ if (!frame) continue;
75
+
76
+ const { columnNumber, lineNumber, fileName, functionName, source } = frame;
77
+ let fileNameParsed = '<unknown>';
78
+ if (fileName) {
79
+ const subStrLen = fileName.indexOf('?');
80
+ if (subStrLen < 0) {
81
+ fileNameParsed = fileName;
82
+ } else if (subStrLen > 0) {
83
+ fileNameParsed = fileName.substring(0, subStrLen);
84
+ }
85
+ }
86
+
87
+ nativeObj.frames.push({
88
+ src: source || '<unknown>',
89
+ line: lineNumber || 0,
90
+ col: columnNumber || 0,
91
+ fn: functionName || '<unknown>',
92
+ file: `${fileNameParsed}:${lineNumber || 0}:${columnNumber || 0}`,
93
+ });
94
+ }
95
+
96
+ return nativeObj;
97
+ }
98
+
99
+ export const setGlobalErrorHandler = once((nativeModule: NativeModule) => {
100
+ const originalHandler = ErrorUtils.getGlobalHandler();
101
+
102
+ async function handler(error: unknown, fatal?: boolean) {
103
+ // If collection is disabled, just forward to the original handler
104
+ if (!nativeModule.isCrashlyticsCollectionEnabled) {
105
+ return originalHandler(error, fatal);
106
+ }
107
+
108
+ if (!isError(error)) {
109
+ await nativeModule.logPromise(`Unknown Error: ${error}`);
110
+ return originalHandler(error, fatal);
111
+ }
112
+
113
+ // If we are supposed to log javascript-level stack traces, convert this error and log it
114
+ if (nativeModule.isErrorGenerationOnJSCrashEnabled) {
115
+ try {
116
+ const stackFrames = await StackTrace.fromError(error, { offline: true });
117
+ // The backend conversion scan converts the closest event to this timestamp without going over
118
+ // from the timestamp here. So the timestamp *must* be greater then the event log time.
119
+ //
120
+ // For that reason we always round up (`.ceil`) and add a second in case of latency
121
+ //
122
+ // Time is specified as seconds since start of Unix epoch as a baseline, as a string
123
+ const fatalTime = Math.ceil(new Date().getTime() / 1000) + 1 + '';
124
+
125
+ // Flag the Crashlytics backend that we have a fatal error, they will transform it
126
+ await nativeModule.setAttribute(FATAL_FLAG, fatalTime);
127
+
128
+ // remember our current deprecation warning state in case users
129
+ // have set it to non-default
130
+ const currentDeprecationWarningToggle =
131
+ globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS;
132
+
133
+ // Notify analytics, if it exists - throws error if not
134
+ try {
135
+ // FIXME - disable warnings and use the old namespaced style,
136
+ // See https://github.com/invertase/react-native-firebase/issues/8381
137
+ // Unfortunately, this fails completely when using modular!
138
+ // Did not matter if I did named imports above or dynamic require here.
139
+ // So temporarily reverting and silencing warnings instead
140
+ globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true;
141
+ // @ts-ignore - analytics types not available in crashlytics
142
+ await firebase.app().analytics().logEvent(
143
+ 'app_exception', // 'app_exception' is reserved but we make an exception for JS->fatal transforms
144
+ {
145
+ fatal: 1, // as in firebase-android-sdk
146
+ timestamp: fatalTime,
147
+ },
148
+ );
149
+ } catch (_) {
150
+ // This just means analytics was not present, so we could not log the analytics event
151
+ // console.log('error logging analytics app_exception: ' + e);
152
+ } finally {
153
+ globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = currentDeprecationWarningToggle;
154
+ }
155
+
156
+ // If we are chaining to other handlers, just record the error, otherwise we need to crash with it
157
+ if (nativeModule.isCrashlyticsJavascriptExceptionHandlerChainingEnabled) {
158
+ await nativeModule.recordErrorPromise(createNativeErrorObj(error, stackFrames, false));
159
+ } else {
160
+ await nativeModule.crashWithStackPromise(createNativeErrorObj(error, stackFrames, false));
161
+ }
162
+ } catch (_) {
163
+ // do nothing
164
+ // console.log('error logging handling the exception: ' + e);
165
+ }
166
+ }
167
+
168
+ // If we are configured to chain exception handlers, do so. It could result in duplicate errors though.
169
+ if (nativeModule.isCrashlyticsJavascriptExceptionHandlerChainingEnabled) {
170
+ return originalHandler(error, fatal);
171
+ }
172
+ }
173
+
174
+ ErrorUtils.setGlobalHandler(handler);
175
+ return handler;
176
+ });
177
+
178
+ export const setOnUnhandledPromiseRejectionHandler = once((nativeModule: NativeModule) => {
179
+ async function onUnhandled(_id: number, error: Error) {
180
+ if (!__DEV__) {
181
+ // TODO(salakar): Option to disable
182
+ try {
183
+ const stackFrames = await StackTrace.fromError(error, { offline: true });
184
+ await nativeModule.recordErrorPromise(createNativeErrorObj(error, stackFrames, true));
185
+ } catch (_) {
186
+ // do nothing
187
+ }
188
+ }
189
+ }
190
+ tracking.enable({
191
+ allRejections: true,
192
+ onUnhandled,
193
+ });
194
+
195
+ return onUnhandled;
196
+ });
package/lib/index.ts ADDED
@@ -0,0 +1,26 @@
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
+ // Export types from types/crashlytics
19
+ export type { Crashlytics, FirebaseCrashlyticsTypes } from './types/crashlytics';
20
+
21
+ // Export modular API functions
22
+ export * from './modular';
23
+
24
+ // Export namespaced API
25
+ export * from './namespaced';
26
+ export { default } from './namespaced';
package/lib/modular.ts ADDED
@@ -0,0 +1,249 @@
1
+ import { getApp } from '@react-native-firebase/app';
2
+ import { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/lib/common';
3
+ import type { Crashlytics } from './types/crashlytics';
4
+
5
+ /**
6
+ * Returns Crashlytics instance.
7
+ * #### Example
8
+ * ```js
9
+ * const crashlytics = getCrashlytics();
10
+ * ```
11
+ */
12
+ export function getCrashlytics(): Crashlytics {
13
+ return getApp().crashlytics();
14
+ }
15
+
16
+ /**
17
+ * Determines whether there are any unsent crash reports cached on the device. The callback only executes
18
+ * if automatic data collection is disabled.
19
+ *
20
+ * #### Example
21
+ *
22
+ * ```js
23
+ * async checkReports() {
24
+ * // returns boolean value
25
+ * const crashlytics = getCrashlytics();
26
+ * const unsentReports = await checkForUnsentReports(crashlytics);
27
+ * }
28
+ *
29
+ * checkReports();
30
+ * ```
31
+ * @param crashlytics A crashlytics instance.
32
+ * @returns Promise that resolves to a boolean indicating if there are unsent reports.
33
+ */
34
+ export function checkForUnsentReports(crashlytics: Crashlytics): Promise<boolean> {
35
+ // @ts-ignore - MODULAR_DEPRECATION_ARG is not defined in the global scope
36
+ return crashlytics.checkForUnsentReports.call(crashlytics, MODULAR_DEPRECATION_ARG);
37
+ }
38
+
39
+ /**
40
+ * Deletes any unsent reports on the device. This method only applies if automatic data collection is
41
+ * disabled.
42
+ *
43
+ * #### Example
44
+ *
45
+ * ```js
46
+ * const crashlytics = getCrashlytics();
47
+ * deleteUnsentReports(crashlytics);
48
+ * ```
49
+ * @param crashlytics A crashlytics instance.
50
+ */
51
+ export function deleteUnsentReports(crashlytics: Crashlytics): Promise<void> {
52
+ // @ts-ignore - MODULAR_DEPRECATION_ARG is not defined in the global scope
53
+ return crashlytics.deleteUnsentReports.call(crashlytics, MODULAR_DEPRECATION_ARG);
54
+ }
55
+
56
+ /**
57
+ * Returns a boolean value indicating whether the app crashed during the previous execution.
58
+ *
59
+ * #### Example
60
+ *
61
+ * ```js
62
+ * async didCrashPreviously() {
63
+ * // returns boolean value
64
+ * const crashlytics = getCrashlytics();
65
+ * const didCrash = await didCrashOnPreviousExecution(crashlytics);
66
+ * }
67
+ *
68
+ * didCrashPreviously();
69
+ * ```
70
+ * @param crashlytics A crashlytics instance.
71
+ * @returns Promise that resolves to a boolean indicating if the app crashed previously.
72
+ */
73
+ export function didCrashOnPreviousExecution(crashlytics: Crashlytics): Promise<boolean> {
74
+ // @ts-ignore - MODULAR_DEPRECATION_ARG is not defined in the global scope
75
+ return crashlytics.didCrashOnPreviousExecution.call(crashlytics, MODULAR_DEPRECATION_ARG);
76
+ }
77
+
78
+ /**
79
+ * Cause your app to crash for testing purposes. This is a native crash and will not contain a javascript stack trace.
80
+ * Note that crashes are intercepted by debuggers on iOS so no report will be seen under those conditions. Additionally
81
+ * if it is a debug build you will need to ensure your firebase.json is configured to enable crashlytics even in debug mode.
82
+ *
83
+ * #### Example
84
+ *
85
+ * ```js
86
+ * const crashlytics = getCrashlytics();
87
+ * crash(crashlytics);
88
+ * ```
89
+ * @param crashlytics A crashlytics instance.
90
+ */
91
+ export function crash(crashlytics: Crashlytics): void {
92
+ // @ts-ignore - MODULAR_DEPRECATION_ARG is not defined in the global scope
93
+ return crashlytics.crash.call(crashlytics, MODULAR_DEPRECATION_ARG);
94
+ }
95
+
96
+ /**
97
+ * Log a message that will appear in any subsequent Crash or Non-fatal error reports.
98
+ *
99
+ * #### Example
100
+ *
101
+ * ```js
102
+ * const crashlytics = getCrashlytics();
103
+ * log(crashlytics, 'Testing a crash');
104
+ * crash(crashlytics);
105
+ * ```
106
+ * @param crashlytics A crashlytics instance.
107
+ * @param message The message to log.
108
+ */
109
+ export function log(crashlytics: Crashlytics, message: string): void {
110
+ // @ts-ignore - MODULAR_DEPRECATION_ARG is not defined in the global scope
111
+ return crashlytics.log.call(crashlytics, message, MODULAR_DEPRECATION_ARG);
112
+ }
113
+
114
+ /**
115
+ * Record a JavaScript Error.
116
+ *
117
+ * The JavaScript stack trace is converted into a mock native iOS or Android exception before submission.
118
+ * The line numbers in the stack trace (if available) will be relative to the javascript bundle built by your packager,
119
+ * after whatever transpilation or minimization steps happen. You will need to maintain sourcemaps to decode them if desired.
120
+ *
121
+ * #### Example
122
+ *
123
+ * ```js
124
+ * const crashlytics = getCrashlytics();
125
+ * recordError(
126
+ * crashlytics,
127
+ * new Error('An error was caught')
128
+ * );
129
+ * ```
130
+ * @param crashlytics A crashlytics instance.
131
+ * @param error Expects an instance of Error; e.g. classes that extend Error will also be supported.
132
+ * @param jsErrorName Optional string containing Javascript error name
133
+ */
134
+ export function recordError(crashlytics: Crashlytics, error: Error, jsErrorName?: string): void {
135
+ // @ts-ignore - MODULAR_DEPRECATION_ARG is not defined in the global scope
136
+ return crashlytics.recordError.call(crashlytics, error, jsErrorName, MODULAR_DEPRECATION_ARG);
137
+ }
138
+
139
+ /**
140
+ * Enqueues any unsent reports on the device to upload to Crashlytics. This method only applies if
141
+ * automatic data collection is disabled.
142
+ *
143
+ * #### Example
144
+ *
145
+ * ```js
146
+ * const crashlytics = getCrashlytics();
147
+ * sendUnsentReports(crashlytics);
148
+ * ```
149
+ * @param crashlytics A crashlytics instance.
150
+ */
151
+ export function sendUnsentReports(crashlytics: Crashlytics): void {
152
+ // @ts-ignore - MODULAR_DEPRECATION_ARG is not defined in the global scope
153
+ return crashlytics.sendUnsentReports.call(crashlytics, MODULAR_DEPRECATION_ARG);
154
+ }
155
+
156
+ /**
157
+ * Specify a user identifier which will be visible in the Firebase Crashlytics console.
158
+ *
159
+ * It is recommended for privacy purposes that this value be a value that's meaningless to a third-party
160
+ * observer; such as an arbitrary string that ties an end-user to a record in your system e.g. a database record id.
161
+ *
162
+ * #### Example
163
+ *
164
+ * ```js
165
+ * const auth = getAuth();
166
+ * const crashlytics = getCrashlytics();
167
+ * // Custom user id
168
+ * await setUserId(crashlytics, '123456789');
169
+ * // Firebase auth uid
170
+ * await setUserId(
171
+ * crashlytics,
172
+ * auth.currentUser.uid
173
+ * );
174
+ * ```
175
+ * @param crashlytics A crashlytics instance.
176
+ * @param userId An arbitrary string that ties an end-user to a record in your system e.g. a database record id.
177
+ */
178
+ export function setUserId(crashlytics: Crashlytics, userId: string): Promise<null> {
179
+ // @ts-ignore - MODULAR_DEPRECATION_ARG is not defined in the global scope
180
+ return crashlytics.setUserId.call(crashlytics, userId, MODULAR_DEPRECATION_ARG);
181
+ }
182
+
183
+ /**
184
+ * Sets a string value to be associated with the given attribute name which will be visible in the Firebase Crashlytics console.
185
+ *
186
+ * #### Example
187
+ *
188
+ * ```js
189
+ * const crashlytics = getCrashlytics();
190
+ * await setAttribute(crashlytics, 'role', 'admin');
191
+ * ```
192
+ * @param crashlytics A crashlytics instance.
193
+ * @param name The name of the attribute to set.
194
+ * @param value A string value for the given attribute.
195
+ */
196
+ export function setAttribute(crashlytics: Crashlytics, name: string, value: string): Promise<null> {
197
+ // @ts-ignore - MODULAR_DEPRECATION_ARG is not defined in the global scope
198
+ return crashlytics.setAttribute.call(crashlytics, name, value, MODULAR_DEPRECATION_ARG);
199
+ }
200
+
201
+ /**
202
+ * Like `setAttribute` but for multiple attributes.
203
+ *
204
+ * #### Example
205
+ *
206
+ * ```js
207
+ * const crashlytics = getCrashlytics();
208
+ * await setAttributes(crashlytics, {
209
+ * role: 'admin',
210
+ * followers: '13',
211
+ * });
212
+ * ```
213
+ * @param crashlytics A crashlytics instance.
214
+ * @param attributes An object of key/value attribute name and values.
215
+ */
216
+ export function setAttributes(
217
+ crashlytics: Crashlytics,
218
+ attributes: { [key: string]: string },
219
+ ): Promise<null> {
220
+ // @ts-ignore - MODULAR_DEPRECATION_ARG is not defined in the global scope
221
+ return crashlytics.setAttributes.call(crashlytics, attributes, MODULAR_DEPRECATION_ARG);
222
+ }
223
+
224
+ /**
225
+ * Enable/disable Crashlytics reporting.
226
+ *
227
+ * Use this for opt-in first user data collection flows combined with `firebase.json` settings to disable auto collection.
228
+ *
229
+ * #### Example
230
+ *
231
+ * ```js
232
+ * const crashlytics = getCrashlytics();
233
+ * // Disable crash reporting
234
+ * await setCrashlyticsCollectionEnabled(crashlytics, false);
235
+ * ```
236
+ * @param crashlytics A crashlytics instance.
237
+ * @param enabled A boolean value representing whether to enable Crashlytics error collection.
238
+ */
239
+ export function setCrashlyticsCollectionEnabled(
240
+ crashlytics: Crashlytics,
241
+ enabled: boolean,
242
+ ): Promise<null> {
243
+ return crashlytics.setCrashlyticsCollectionEnabled.call(
244
+ crashlytics,
245
+ enabled,
246
+ // @ts-ignore - MODULAR_DEPRECATION_ARG is not defined in the global scope
247
+ MODULAR_DEPRECATION_ARG,
248
+ );
249
+ }