1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | 2× 6× 6× 6× 4× 4× 2× 2× 2× 2× 6× 6× 6× 6× 6× 6× 6× 6× 6× 6× 6× 6× 6× 6× 6× 6× 8670× 58× 6× 2× 4× 4× 4× 4× 2× 2× 2× 2× 6× 2× 2× 2× 2× 66× | /* * @flow */ import { NativeModules } from 'react-native'; import APPS from '../../utils/apps'; import { SharedEventEmitter } from '../../utils/events'; import INTERNALS from '../../utils/internals'; import { isObject } from '../../utils'; import AdMob, { NAMESPACE as AdmobNamespace } from '../admob'; import Auth, { NAMESPACE as AuthNamespace } from '../auth'; import Analytics, { NAMESPACE as AnalyticsNamespace } from '../analytics'; import Config, { NAMESPACE as ConfigNamespace } from '../config'; import Crash, { NAMESPACE as CrashNamespace } from '../crash'; import Crashlytics, { NAMESPACE as CrashlyticsNamespace, } from '../fabric/crashlytics'; import Database, { NAMESPACE as DatabaseNamespace } from '../database'; import Firestore, { NAMESPACE as FirestoreNamespace } from '../firestore'; import InstanceId, { NAMESPACE as InstanceIdNamespace } from '../instanceid'; import Links, { NAMESPACE as LinksNamespace } from '../links'; import Messaging, { NAMESPACE as MessagingNamespace } from '../messaging'; import Notifications, { NAMESPACE as NotificationsNamespace, } from '../notifications'; import Performance, { NAMESPACE as PerfNamespace } from '../perf'; import Storage, { NAMESPACE as StorageNamespace } from '../storage'; import Utils, { NAMESPACE as UtilsNamespace } from '../utils'; import type { FirebaseOptions } from '../../types'; const FirebaseCoreModule = NativeModules.RNFirebase; export default class App { _extendedProps: { [string]: boolean }; _initialized: boolean = false; _name: string; _nativeInitialized: boolean = false; _options: FirebaseOptions; admob: () => AdMob; analytics: () => Analytics; auth: () => Auth; config: () => Config; crash: () => Crash; database: () => Database; fabric: { crashlytics: () => Crashlytics, }; firestore: () => Firestore; instanceid: () => InstanceId; links: () => Links; messaging: () => Messaging; notifications: () => Notifications; perf: () => Performance; storage: () => Storage; utils: () => Utils; constructor( name: string, options: FirebaseOptions, fromNative: boolean = false ) { this._name = name; this._options = Object.assign({}, options); if (fromNative) { this._initialized = true; this._nativeInitialized = true; } else Eif (options.databaseURL && options.apiKey) { FirebaseCoreModule.initializeApp( this._name, this._options, (error, result) => { this._initialized = true; SharedEventEmitter.emit(`AppReady:${this._name}`, { error, result }); } ); } // modules this.admob = APPS.appModule(this, AdmobNamespace, AdMob); this.analytics = APPS.appModule(this, AnalyticsNamespace, Analytics); this.auth = APPS.appModule(this, AuthNamespace, Auth); this.config = APPS.appModule(this, ConfigNamespace, Config); this.crash = APPS.appModule(this, CrashNamespace, Crash); this.database = APPS.appModule(this, DatabaseNamespace, Database); this.fabric = { crashlytics: APPS.appModule(this, CrashlyticsNamespace, Crashlytics), }; this.firestore = APPS.appModule(this, FirestoreNamespace, Firestore); this.instanceid = APPS.appModule(this, InstanceIdNamespace, InstanceId); this.links = APPS.appModule(this, LinksNamespace, Links); this.messaging = APPS.appModule(this, MessagingNamespace, Messaging); this.notifications = APPS.appModule( this, NotificationsNamespace, Notifications ); this.perf = APPS.appModule(this, PerfNamespace, Performance); this.storage = APPS.appModule(this, StorageNamespace, Storage); this.utils = APPS.appModule(this, UtilsNamespace, Utils); this._extendedProps = {}; } /** * * @return {*} */ get name(): string { return this._name; } /** * * @return {*} */ get options(): FirebaseOptions { return Object.assign({}, this._options); } /** * Undocumented firebase web sdk method that allows adding additional properties onto * a firebase app instance. * * See: https://github.com/firebase/firebase-js-sdk/blob/master/tests/app/firebase_app.test.ts#L328 * * @param props */ extendApp(props: Object) { if (!isObject(props)) { throw new Error( INTERNALS.STRINGS.ERROR_MISSING_ARG('Object', 'extendApp') ); } const keys = Object.keys(props); for (let i = 0, len = keys.length; i < len; i++) { const key = keys[i]; if (!this._extendedProps[key] && Object.hasOwnProperty.call(this, key)) { throw new Error(INTERNALS.STRINGS.ERROR_PROTECTED_PROP(key)); } // $FlowExpectedError: Flow doesn't support indexable signatures on classes: https://github.com/facebook/flow/issues/1323 this[key] = props[key]; this._extendedProps[key] = true; } } /** * * @return {Promise} */ delete() { throw new Error( INTERNALS.STRINGS.ERROR_UNSUPPORTED_CLASS_METHOD('app', 'delete') ); // TODO only the ios sdk currently supports delete, add back in when android also supports it // if (this._name === APPS.DEFAULT_APP_NAME && this._nativeInitialized) { // return Promise.reject( // new Error('Unable to delete the default native firebase app instance.'), // ); // } // // return FirebaseCoreModule.deleteApp(this._name); } /** * * @return {*} */ onReady(): Promise<App> { if (this._initialized) return Promise.resolve(this); return new Promise((resolve, reject) => { SharedEventEmitter.once(`AppReady:${this._name}`, ({ error }) => { Iif (error) return reject(new Error(error)); // error is a string as it's from native return resolve(this); // return app }); }); } /** * toString returns the name of the app. * * @return {string} */ toString() { return this._name; } } |