import { firebase , FirebaseApp , FirebaseError } from '@nativescript/firebase-core' ; import { IInstallations } from './common' ; let defaultInstallations ; const fb = firebase ( ) ; Object . defineProperty ( fb , 'installations' , { value : ( app ? ) => { if ( ! app ) { if ( ! defaultInstallations ) { defaultInstallations = new Installations ( ) ; } return defaultInstallations ; } return new Installations ( app ) ; } , writable : false , } ) ; export class Installations implements IInstallations { #native : FIRInstallations ; #app : FirebaseApp ; constructor ( app ? ) { if ( app ?. native ) { this . #native = FIRInstallations . installationsWithApp ( app . native ) ; } else { if ( defaultInstallations ) { return defaultInstallations ; } defaultInstallations = this ; this . #native = FIRInstallations . installations ( ) ; } } delete ( ) { return new Promise ( ( resolve , reject ) => { this . native . deleteWithCompletion ( ( error ) => { if ( error ) { reject ( FirebaseError . fromNative ( error ) ) ; } else { resolve ( ) ; } } ) ; } ) ; } getId ( ) { return new Promise ( ( resolve , reject ) => { this . native . installationIDWithCompletion ( ( id , error ) => { if ( error ) { reject ( FirebaseError . fromNative ( error ) ) ; } else { resolve ( id ) ; } } ) ; } ) ; } getToken ( forceRefresh = false ) { return new Promise ( ( resolve , reject ) => { this . native . authTokenForcingRefreshCompletion ( forceRefresh , ( result , error ) => { if ( error ) { reject ( FirebaseError . fromNative ( error ) ) ; } else { resolve ( result . authToken ) ; } } ) ; } ) ; } get native ( ) { return this . #native ; } get ios ( ) { return this . native ; } get app ( ) : FirebaseApp { if ( ! this . #app ) { this . #app = FirebaseApp . fromNative ( this . native . app ) ; } return this . #app ; } }