2017-08-15 20:29:50 +00:00
|
|
|
import { Platform, NativeModules } from 'react-native';
|
2017-06-29 16:24:34 +00:00
|
|
|
|
2017-08-25 14:30:17 +00:00
|
|
|
import EventEmitter from './utils/emitter/EventEmitter';
|
2017-08-16 20:43:24 +00:00
|
|
|
import SyncTree from './utils/SyncTree';
|
|
|
|
|
2017-07-12 14:49:33 +00:00
|
|
|
const DEFAULT_APP_NAME = Platform.OS === 'ios' ? '__FIRAPP_DEFAULT' : '[DEFAULT]';
|
2017-06-29 16:24:34 +00:00
|
|
|
|
2017-08-18 20:05:47 +00:00
|
|
|
const NAMESPACE_PODS = {
|
|
|
|
admob: 'Firebase/AdMob',
|
|
|
|
analytics: 'Firebase/Analytics',
|
|
|
|
auth: 'Firebase/Auth',
|
|
|
|
config: 'Firebase/RemoteConfig',
|
|
|
|
crash: 'Firebase/Crash',
|
|
|
|
database: 'Firebase/Database',
|
|
|
|
links: 'Firebase/DynamicLinks',
|
|
|
|
messaging: 'Firebase/Messaging',
|
|
|
|
perf: 'Firebase/Performance',
|
|
|
|
storage: 'Firebase/Storage',
|
|
|
|
};
|
|
|
|
|
|
|
|
const GRADLE_DEPS = {
|
|
|
|
admob: 'ads',
|
|
|
|
};
|
|
|
|
|
2017-06-29 16:24:34 +00:00
|
|
|
export default {
|
|
|
|
// default options
|
|
|
|
OPTIONS: {
|
|
|
|
logLevel: 'warn',
|
|
|
|
},
|
|
|
|
|
|
|
|
// track all initialized firebase apps
|
|
|
|
APPS: {
|
|
|
|
[DEFAULT_APP_NAME]: null,
|
|
|
|
},
|
|
|
|
|
|
|
|
STRINGS: {
|
2017-08-18 20:05:47 +00:00
|
|
|
WARN_INITIALIZE_DEPRECATION: 'Deprecation: Calling \'initializeApp()\' for apps that are already initialised natively ' +
|
|
|
|
'is unnecessary, use \'firebase.app()\' instead to access the already initialized default app instance.',
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
get ERROR_MISSING_CORE() {
|
|
|
|
if (Platform.OS === 'ios') {
|
|
|
|
return 'RNFirebase core module was not found natively on iOS, ensure you have ' +
|
|
|
|
'correctly included the RNFirebase pod in your projects `Podfile` and have run `pod install`.' +
|
|
|
|
'\r\n\r\n See http://invertase.link/ios for the ios setup guide.';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'RNFirebase core module was not found natively on Android, ensure you have ' +
|
|
|
|
'correctly added the RNFirebase and Firebase gradle dependencies to your `android/app/build.gradle` file.' +
|
|
|
|
'\r\n\r\n See http://invertase.link/android for the android setup guide.';
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2017-06-29 16:24:34 +00:00
|
|
|
ERROR_INIT_OBJECT: 'Firebase.initializeApp(options <-- requires a valid configuration object.',
|
|
|
|
ERROR_INIT_STRING_NAME: 'Firebase.initializeApp(options, name <-- requires a valid string value.',
|
|
|
|
|
2017-08-19 04:22:07 +00:00
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
ERROR_MISSING_CB(method) {
|
|
|
|
return `Missing required callback for method ${method}().`;
|
|
|
|
},
|
|
|
|
|
2017-08-26 22:41:59 +00:00
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
ERROR_MISSING_ARG(type, method) {
|
|
|
|
return `Missing required argument of type '${type}' for method '${method}()'.`;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
ERROR_PROTECTED_PROP(name) {
|
|
|
|
return `Property '${name}' is protected and can not be overridden by extendApp.`;
|
|
|
|
},
|
|
|
|
|
2017-06-29 16:24:34 +00:00
|
|
|
/**
|
|
|
|
* @return {string}
|
2017-08-18 20:05:47 +00:00
|
|
|
* @param namespace
|
|
|
|
* @param nativeModule
|
2017-06-29 16:24:34 +00:00
|
|
|
*/
|
2017-08-18 20:05:47 +00:00
|
|
|
ERROR_MISSING_MODULE(namespace, nativeModule) {
|
|
|
|
const snippet = `firebase.${namespace}()`;
|
|
|
|
if (Platform.OS === 'ios') {
|
|
|
|
return `You attempted to use a firebase module that's not installed natively on your iOS project by calling ${snippet}.` +
|
|
|
|
'\r\n\r\nEnsure you have the required Firebase iOS SDK pod for this module included in your Podfile, in this instance ' +
|
|
|
|
`confirm you've added "pod '${NAMESPACE_PODS[namespace]}'" to your Podfile` +
|
|
|
|
'\r\n\r\nSee http://invertase.link/ios for full setup instructions.';
|
|
|
|
}
|
|
|
|
|
|
|
|
const fbSDKDep = `'com.google.firebase:firebase-${GRADLE_DEPS[namespace] || namespace}'`;
|
|
|
|
const rnFirebasePackage = `'io.invertase.firebase.${namespace}.${nativeModule}Package'`;
|
|
|
|
const newInstance = `'new ${nativeModule}Package()'`;
|
|
|
|
return `You attempted to use a firebase module that's not installed on your Android project by calling ${snippet}.` +
|
|
|
|
`\r\n\r\nEnsure you have:\r\n\r\n1) Installed the required Firebase Android SDK dependency ${fbSDKDep} in your 'android/app/build.gradle' ` +
|
|
|
|
`file.\r\n\r\n2) Imported the ${rnFirebasePackage} module in your 'MainApplication.java' file.\r\n\r\n3) Added the ` +
|
|
|
|
`${newInstance} line inside of the RN 'getPackages()' method list.` +
|
|
|
|
'\r\n\r\nSee http://invertase.link/android for full setup instructions.';
|
2017-06-29 16:24:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
ERROR_APP_NOT_INIT(appName) {
|
2017-07-17 17:20:27 +00:00
|
|
|
return `The [${appName}] firebase app has not been initialized!`;
|
2017-06-29 16:24:34 +00:00
|
|
|
},
|
|
|
|
|
2017-07-18 05:04:12 +00:00
|
|
|
/**
|
|
|
|
* @param optName
|
|
|
|
* @return {string}
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
ERROR_MISSING_OPT(optName) {
|
|
|
|
return `Failed to initialize app. FirebaseOptions missing or invalid '${optName}' property.`;
|
|
|
|
},
|
|
|
|
|
2017-06-29 16:24:34 +00:00
|
|
|
/**
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
ERROR_NOT_APP(namespace) {
|
|
|
|
return `Invalid FirebaseApp instance passed to firebase.${namespace}(app <--).`;
|
|
|
|
},
|
|
|
|
|
|
|
|
DEFAULT_APP_NAME,
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
SharedEventEmitter: new EventEmitter(),
|
2017-08-15 20:29:50 +00:00
|
|
|
SyncTree: NativeModules.RNFirebaseDatabase ? new SyncTree(NativeModules.RNFirebaseDatabase) : null,
|
2017-06-29 16:24:34 +00:00
|
|
|
|
|
|
|
// internal utils
|
|
|
|
deleteApp(name: String) {
|
|
|
|
const app = this.APPS[name];
|
|
|
|
if (!app) return Promise.resolve();
|
|
|
|
|
|
|
|
// https://firebase.google.com/docs/reference/js/firebase.app.App#delete
|
|
|
|
return app.delete().then(() => {
|
|
|
|
delete this.APPS[name];
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|