import { firebase , FirebaseApp } from '@nativescript/firebase-core' ; import { ICrashlytics } from './common' ; import StackTrace from 'stacktrace-js' ; let defaultCrashlytics ; const fb = firebase ( ) ; Object . defineProperty ( fb , 'crashlytics' , { value : ( ) => { if ( ! defaultCrashlytics ) { defaultCrashlytics = new Crashlytics ( ) ; } return defaultCrashlytics ; } , writable : false , } ) ; declare const TNSFirebaseCrashlytics ; export class Crashlytics implements ICrashlytics { #native : FIRCrashlytics ; constructor ( ) { if ( defaultCrashlytics ) { return defaultCrashlytics ; } defaultCrashlytics = this ; this . #native = FIRCrashlytics . crashlytics ( ) ; } get native ( ) { return this . #native ; } get ios ( ) { return this . native ; } #app : FirebaseApp ; get app ( ) : FirebaseApp { if ( ! this . #app ) { this . #app = FirebaseApp . fromNative ( this . native . app ) ; } return this . #app ; } get isCrashlyticsCollectionEnabled ( ) : boolean { return this . native . isCrashlyticsCollectionEnabled ( ) ; } checkForUnsentReports ( ) { return new Promise ( ( resolve , reject ) => { this . native . checkForUnsentReportsWithCompletion ( ( completed ) => { resolve ( completed ) ; } ) ; } ) ; } crash ( ) { TNSFirebaseCrashlytics . crash ( ) ; } deleteUnsentReports ( ) { this . native . deleteUnsentReports ( ) ; } didCrashOnPreviousExecution ( ) { return this . native . didCrashDuringPreviousExecution ( ) ; } log ( message ) { this . native . log ( message ) ; } recordError ( error ) { if ( error instanceof Error ) { StackTrace . fromError ( error ) . then ( ( stack ) => { const traceElements = [ ] ; stack . forEach ( ( item , i ) => { traceElements [ i ] = FIRStackFrame . stackFrameWithSymbolFileLine ( item . functionName , item . fileName , item . lineNumber ) ; } ) ; const e = FIRExceptionModel . exceptionModelWithNameReason ( 'JavaScriptError' , error . message ) ; this . native . recordExceptionModel ( e ) ; } ) ; } else { this . native . recordError ( error ) ; } } sendUnsentReports ( ) { this . native . sendUnsentReports ( ) ; } setAttribute ( name , value ) { this . native . setCustomValueForKey ( value , name ) ; } setAttributes ( attributes ) { Object . keys ( attributes ) . forEach ( ( key ) => { this . native . setCustomValueForKey ( attributes [ key ] , key ) ; } ) ; } setCrashlyticsCollectionEnabled ( enabled ) { this . native . setCrashlyticsCollectionEnabled ( enabled ) ; } setUserId ( userId ) { this . native . setUserID ( userId ) ; } }