2017-03-02 13:10:10 +00:00
|
|
|
/**
|
|
|
|
* @flow
|
|
|
|
*/
|
2017-12-22 15:24:31 +00:00
|
|
|
import { NativeModules } from 'react-native';
|
2017-03-02 13:10:10 +00:00
|
|
|
|
2017-12-22 15:24:31 +00:00
|
|
|
import APPS from '../../utils/apps';
|
2017-11-17 16:17:27 +00:00
|
|
|
import INTERNALS from '../../utils/internals';
|
2018-02-14 13:00:19 +00:00
|
|
|
import App from './app';
|
2018-01-09 17:31:54 +00:00
|
|
|
import VERSION from '../../version';
|
2017-06-29 16:24:34 +00:00
|
|
|
|
|
|
|
// module imports
|
2018-01-25 18:25:39 +00:00
|
|
|
import {
|
|
|
|
statics as AdMobStatics,
|
|
|
|
MODULE_NAME as AdmobModuleName,
|
|
|
|
} from '../admob';
|
2018-01-03 20:00:38 +00:00
|
|
|
import { statics as AuthStatics, MODULE_NAME as AuthModuleName } from '../auth';
|
2018-01-25 18:25:39 +00:00
|
|
|
import {
|
|
|
|
statics as AnalyticsStatics,
|
|
|
|
MODULE_NAME as AnalyticsModuleName,
|
|
|
|
} from '../analytics';
|
|
|
|
import {
|
|
|
|
statics as ConfigStatics,
|
|
|
|
MODULE_NAME as ConfigModuleName,
|
|
|
|
} from '../config';
|
|
|
|
import {
|
|
|
|
statics as CrashStatics,
|
|
|
|
MODULE_NAME as CrashModuleName,
|
|
|
|
} from '../crash';
|
|
|
|
import {
|
|
|
|
statics as CrashlyticsStatics,
|
|
|
|
MODULE_NAME as CrashlyticsModuleName,
|
2018-04-03 15:51:05 +00:00
|
|
|
} from '../crashlytics';
|
2018-01-25 18:25:39 +00:00
|
|
|
import {
|
|
|
|
statics as DatabaseStatics,
|
|
|
|
MODULE_NAME as DatabaseModuleName,
|
|
|
|
} from '../database';
|
|
|
|
import {
|
|
|
|
statics as FirestoreStatics,
|
|
|
|
MODULE_NAME as FirestoreModuleName,
|
|
|
|
} from '../firestore';
|
2018-02-02 08:40:48 +00:00
|
|
|
import {
|
|
|
|
statics as InstanceIdStatics,
|
|
|
|
MODULE_NAME as InstanceIdModuleName,
|
2018-03-23 14:59:00 +00:00
|
|
|
} from '../iid';
|
2018-03-22 12:46:37 +00:00
|
|
|
import {
|
|
|
|
statics as InvitesStatics,
|
|
|
|
MODULE_NAME as InvitesModuleName,
|
|
|
|
} from '../invites';
|
2018-01-25 18:25:39 +00:00
|
|
|
import {
|
|
|
|
statics as LinksStatics,
|
|
|
|
MODULE_NAME as LinksModuleName,
|
|
|
|
} from '../links';
|
|
|
|
import {
|
|
|
|
statics as MessagingStatics,
|
|
|
|
MODULE_NAME as MessagingModuleName,
|
|
|
|
} from '../messaging';
|
2018-01-30 11:15:59 +00:00
|
|
|
import {
|
2018-02-02 08:40:48 +00:00
|
|
|
statics as NotificationsStatics,
|
|
|
|
MODULE_NAME as NotificationsModuleName,
|
|
|
|
} from '../notifications';
|
2018-01-25 18:25:39 +00:00
|
|
|
import {
|
|
|
|
statics as PerformanceStatics,
|
|
|
|
MODULE_NAME as PerfModuleName,
|
|
|
|
} from '../perf';
|
|
|
|
import {
|
|
|
|
statics as StorageStatics,
|
|
|
|
MODULE_NAME as StorageModuleName,
|
|
|
|
} from '../storage';
|
|
|
|
import {
|
|
|
|
statics as UtilsStatics,
|
|
|
|
MODULE_NAME as UtilsModuleName,
|
|
|
|
} from '../utils';
|
2017-09-09 18:49:45 +00:00
|
|
|
|
2017-11-23 17:29:40 +00:00
|
|
|
import type {
|
|
|
|
AdMobModule,
|
|
|
|
AnalyticsModule,
|
|
|
|
AuthModule,
|
|
|
|
ConfigModule,
|
|
|
|
CrashModule,
|
2018-04-03 15:51:05 +00:00
|
|
|
CrashlyticsModule,
|
2017-11-23 17:29:40 +00:00
|
|
|
DatabaseModule,
|
|
|
|
FirebaseOptions,
|
|
|
|
FirestoreModule,
|
2018-02-02 08:40:48 +00:00
|
|
|
InstanceIdModule,
|
2018-03-22 12:46:37 +00:00
|
|
|
InvitesModule,
|
2017-11-23 17:29:40 +00:00
|
|
|
LinksModule,
|
|
|
|
MessagingModule,
|
2018-02-02 08:40:48 +00:00
|
|
|
NotificationsModule,
|
2017-11-23 17:29:40 +00:00
|
|
|
PerformanceModule,
|
|
|
|
StorageModule,
|
|
|
|
UtilsModule,
|
|
|
|
} from '../../types';
|
|
|
|
|
2017-06-29 16:24:34 +00:00
|
|
|
const FirebaseCoreModule = NativeModules.RNFirebase;
|
2017-03-02 13:10:10 +00:00
|
|
|
|
2018-01-05 18:23:38 +00:00
|
|
|
class Firebase {
|
2017-11-23 17:29:40 +00:00
|
|
|
admob: AdMobModule;
|
|
|
|
analytics: AnalyticsModule;
|
|
|
|
auth: AuthModule;
|
|
|
|
config: ConfigModule;
|
|
|
|
crash: CrashModule;
|
2018-04-03 15:51:05 +00:00
|
|
|
crashlytics: CrashlyticsModule;
|
2017-11-23 17:29:40 +00:00
|
|
|
database: DatabaseModule;
|
|
|
|
firestore: FirestoreModule;
|
2018-03-23 14:59:00 +00:00
|
|
|
iid: InstanceIdModule;
|
2018-03-22 12:46:37 +00:00
|
|
|
invites: InvitesModule;
|
2017-11-23 17:29:40 +00:00
|
|
|
links: LinksModule;
|
|
|
|
messaging: MessagingModule;
|
2018-02-02 08:40:48 +00:00
|
|
|
notifications: NotificationsModule;
|
2017-11-23 17:29:40 +00:00
|
|
|
perf: PerformanceModule;
|
|
|
|
storage: StorageModule;
|
|
|
|
utils: UtilsModule;
|
2017-11-17 11:07:52 +00:00
|
|
|
|
2017-06-29 16:24:34 +00:00
|
|
|
constructor() {
|
2017-08-18 20:05:47 +00:00
|
|
|
if (!FirebaseCoreModule) {
|
2018-01-25 18:25:39 +00:00
|
|
|
throw new Error(INTERNALS.STRINGS.ERROR_MISSING_CORE);
|
2017-08-18 20:05:47 +00:00
|
|
|
}
|
2017-12-22 15:24:31 +00:00
|
|
|
APPS.initializeNativeApps();
|
2017-07-18 05:04:12 +00:00
|
|
|
|
|
|
|
// modules
|
2018-01-03 20:00:38 +00:00
|
|
|
this.admob = APPS.moduleAndStatics('admob', AdMobStatics, AdmobModuleName);
|
2018-01-25 18:25:39 +00:00
|
|
|
this.analytics = APPS.moduleAndStatics(
|
|
|
|
'analytics',
|
|
|
|
AnalyticsStatics,
|
|
|
|
AnalyticsModuleName
|
|
|
|
);
|
2018-01-03 20:00:38 +00:00
|
|
|
this.auth = APPS.moduleAndStatics('auth', AuthStatics, AuthModuleName);
|
2018-01-25 18:25:39 +00:00
|
|
|
this.config = APPS.moduleAndStatics(
|
|
|
|
'config',
|
|
|
|
ConfigStatics,
|
|
|
|
ConfigModuleName
|
|
|
|
);
|
2018-01-03 20:00:38 +00:00
|
|
|
this.crash = APPS.moduleAndStatics('crash', CrashStatics, CrashModuleName);
|
2018-04-03 15:51:05 +00:00
|
|
|
this.crashlytics = APPS.moduleAndStatics(
|
|
|
|
'crashlytics',
|
|
|
|
CrashlyticsStatics,
|
|
|
|
CrashlyticsModuleName
|
|
|
|
);
|
2018-01-25 18:25:39 +00:00
|
|
|
this.database = APPS.moduleAndStatics(
|
|
|
|
'database',
|
|
|
|
DatabaseStatics,
|
|
|
|
DatabaseModuleName
|
|
|
|
);
|
|
|
|
this.firestore = APPS.moduleAndStatics(
|
|
|
|
'firestore',
|
|
|
|
FirestoreStatics,
|
|
|
|
FirestoreModuleName
|
|
|
|
);
|
2018-03-23 14:59:00 +00:00
|
|
|
this.iid = APPS.moduleAndStatics(
|
|
|
|
'iid',
|
2018-02-02 08:40:48 +00:00
|
|
|
InstanceIdStatics,
|
|
|
|
InstanceIdModuleName
|
|
|
|
);
|
2018-03-22 12:46:37 +00:00
|
|
|
this.invites = APPS.moduleAndStatics(
|
|
|
|
'invites',
|
|
|
|
InvitesStatics,
|
|
|
|
InvitesModuleName
|
|
|
|
);
|
2018-01-03 20:00:38 +00:00
|
|
|
this.links = APPS.moduleAndStatics('links', LinksStatics, LinksModuleName);
|
2018-01-25 18:25:39 +00:00
|
|
|
this.messaging = APPS.moduleAndStatics(
|
|
|
|
'messaging',
|
|
|
|
MessagingStatics,
|
|
|
|
MessagingModuleName
|
|
|
|
);
|
2018-02-02 08:40:48 +00:00
|
|
|
this.notifications = APPS.moduleAndStatics(
|
|
|
|
'notifications',
|
|
|
|
NotificationsStatics,
|
|
|
|
NotificationsModuleName
|
2018-01-30 11:15:59 +00:00
|
|
|
);
|
2018-01-25 18:25:39 +00:00
|
|
|
this.perf = APPS.moduleAndStatics(
|
|
|
|
'perf',
|
|
|
|
PerformanceStatics,
|
|
|
|
PerfModuleName
|
|
|
|
);
|
|
|
|
this.storage = APPS.moduleAndStatics(
|
|
|
|
'storage',
|
|
|
|
StorageStatics,
|
|
|
|
StorageModuleName
|
|
|
|
);
|
2018-01-03 20:00:38 +00:00
|
|
|
this.utils = APPS.moduleAndStatics('utils', UtilsStatics, UtilsModuleName);
|
2017-06-29 16:24:34 +00:00
|
|
|
}
|
2017-04-04 16:58:20 +00:00
|
|
|
|
2017-03-02 13:10:10 +00:00
|
|
|
/**
|
2017-06-29 16:24:34 +00:00
|
|
|
* Web SDK initializeApp
|
2017-03-02 13:10:10 +00:00
|
|
|
*
|
|
|
|
* @param options
|
2017-06-29 16:24:34 +00:00
|
|
|
* @param name
|
|
|
|
* @return {*}
|
2017-03-02 13:10:10 +00:00
|
|
|
*/
|
2018-01-05 17:20:02 +00:00
|
|
|
initializeApp(options: FirebaseOptions, name: string): App {
|
2017-12-22 15:24:31 +00:00
|
|
|
return APPS.initializeApp(options, name);
|
2017-03-02 13:10:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-06-29 16:24:34 +00:00
|
|
|
* Retrieves a Firebase app instance.
|
|
|
|
*
|
|
|
|
* When called with no arguments, the default app is returned.
|
|
|
|
* When an app name is provided, the app corresponding to that name is returned.
|
|
|
|
*
|
2017-03-02 13:10:10 +00:00
|
|
|
* @param name
|
2017-06-29 16:24:34 +00:00
|
|
|
* @return {*}
|
2017-03-02 13:10:10 +00:00
|
|
|
*/
|
2018-01-05 17:20:02 +00:00
|
|
|
app(name?: string): App {
|
2017-12-22 15:24:31 +00:00
|
|
|
return APPS.app(name);
|
2017-06-29 16:24:34 +00:00
|
|
|
}
|
2017-03-02 13:10:10 +00:00
|
|
|
|
2017-06-29 16:24:34 +00:00
|
|
|
/**
|
|
|
|
* A (read-only) array of all initialized apps.
|
|
|
|
* @return {Array}
|
|
|
|
*/
|
2018-01-05 17:20:02 +00:00
|
|
|
get apps(): Array<App> {
|
2017-12-22 15:24:31 +00:00
|
|
|
return APPS.apps();
|
2017-07-12 14:49:33 +00:00
|
|
|
}
|
2018-01-09 17:31:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The current SDK version.
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
get SDK_VERSION(): string {
|
|
|
|
return VERSION;
|
|
|
|
}
|
2017-03-02 13:10:10 +00:00
|
|
|
}
|
2017-06-29 16:24:34 +00:00
|
|
|
|
2018-01-05 18:23:38 +00:00
|
|
|
export default new Firebase();
|