import * as firebase from 'firebase' ; import { LogEvent } from './logging' ; const firebaseConfig = { apiKey : process . env . FIREBASE_API_KEY , databaseURL : process . env . FIREBASE_DATA_URL , projectId : process . env . FIREBASE_PROJECT_ID , messagingSenderId : process . env . FIREBASE_SENDER_ID , appId : process . env . FIREBASE_APP_ID , } ; class APIManager { app : firebase . app . App ; isFirebaseInitialized = false ; constructor ( ) { try { this . app = firebase . initializeApp ( firebaseConfig ) ; this . isFirebaseInitialized = true ; } catch ( err ) { console . log ( 'Firebase not initialized with config:' , firebaseConfig ) ; } } writeLogEvent ( sessionId , logEvent ) { if ( ! this . isFirebaseInitialized ) { return ; } firebase . database ( ) . ref ( `logs/${ sessionId }/${ logEvent . timestamp }` ) . set ( logEvent ) ; } } export default new APIManager ( ) ;