2017-11-17 11:07:52 +00:00
/ * *
* @ flow
* /
2018-01-03 20:00:38 +00:00
import { Platform } from 'react-native' ;
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-10-07 02:06:29 +00:00
const PLAY _SERVICES _CODES = {
2018-02-17 12:55:19 +00:00
// $FlowExpectedError: Doesn't like numerical object keys: https://github.com/facebook/flow/issues/380
2017-10-07 02:06:29 +00:00
1 : {
code : 'SERVICE_MISSING' ,
message : 'Google Play services is missing on this device.' ,
} ,
2018-02-17 12:55:19 +00:00
// $FlowExpectedError: Doesn't like numerical object keys: https://github.com/facebook/flow/issues/380
2017-10-07 02:06:29 +00:00
2 : {
code : 'SERVICE_VERSION_UPDATE_REQUIRED' ,
2018-01-25 18:25:39 +00:00
message :
'The installed version of Google Play services on this device is out of date.' ,
2017-10-07 02:06:29 +00:00
} ,
2018-02-17 12:55:19 +00:00
// $FlowExpectedError: Doesn't like numerical object keys: https://github.com/facebook/flow/issues/380
2017-10-07 02:06:29 +00:00
3 : {
code : 'SERVICE_DISABLED' ,
2018-01-25 18:25:39 +00:00
message :
'The installed version of Google Play services has been disabled on this device.' ,
2017-10-07 02:06:29 +00:00
} ,
2018-02-17 12:55:19 +00:00
// $FlowExpectedError: Doesn't like numerical object keys: https://github.com/facebook/flow/issues/380
2017-10-07 02:06:29 +00:00
9 : {
code : 'SERVICE_INVALID' ,
2018-01-25 18:25:39 +00:00
message :
'The version of the Google Play services installed on this device is not authentic.' ,
2017-10-07 02:06:29 +00:00
} ,
2018-02-17 12:55:19 +00:00
// $FlowExpectedError: Doesn't like numerical object keys: https://github.com/facebook/flow/issues/380
2017-10-07 02:06:29 +00:00
18 : {
code : 'SERVICE_UPDATING' ,
message : 'Google Play services is currently being updated on this device.' ,
} ,
2018-02-17 12:55:19 +00:00
// $FlowExpectedError: Doesn't like numerical object keys: https://github.com/facebook/flow/issues/380
2017-10-07 02:06:29 +00:00
19 : {
code : 'SERVICE_MISSING_PERMISSION' ,
2018-01-25 18:25:39 +00:00
message :
"Google Play service doesn't have one or more required permissions." ,
2017-10-07 02:06:29 +00:00
} ,
} ;
2017-06-29 16:24:34 +00:00
export default {
// default options
OPTIONS : {
logLevel : 'warn' ,
2017-10-07 02:06:29 +00:00
errorOnMissingPlayServices : true ,
promptOnMissingPlayServices : true ,
} ,
FLAGS : {
checkedPlayServices : false ,
2017-06-29 16:24:34 +00:00
} ,
STRINGS : {
2018-01-25 18:25:39 +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." ,
2017-08-18 20:05:47 +00:00
/ * *
* @ return { string }
* /
get ERROR _MISSING _CORE ( ) {
if ( Platform . OS === 'ios' ) {
2018-01-25 18:25:39 +00:00
return (
'RNFirebase core module was not found natively on iOS, ensure you have ' +
2017-08-18 20:05:47 +00:00
'correctly included the RNFirebase pod in your projects `Podfile` and have run `pod install`.' +
2018-01-25 18:25:39 +00:00
'\r\n\r\n See http://invertase.link/ios for the ios setup guide.'
) ;
2017-08-18 20:05:47 +00:00
}
2018-01-25 18:25:39 +00:00
return (
'RNFirebase core module was not found natively on Android, ensure you have ' +
2017-08-18 20:05:47 +00:00
'correctly added the RNFirebase and Firebase gradle dependencies to your `android/app/build.gradle` file.' +
2018-01-25 18:25:39 +00:00
'\r\n\r\n See http://invertase.link/android for the android setup guide.'
) ;
2017-08-18 20:05:47 +00:00
} ,
2018-01-25 18:25:39 +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-06-29 16:24:34 +00:00
2017-11-21 23:37:05 +00:00
/ * *
* @ return { string }
* /
ERROR _INIT _SERVICE _URL _UNSUPPORTED ( namespace : string ) {
return ` ${ namespace } does not support URL as a param, please pass in an app. ` ;
} ,
2017-08-19 04:22:07 +00:00
/ * *
* @ return { string }
* /
2017-11-17 11:07:52 +00:00
ERROR _MISSING _CB ( method : string ) {
2017-08-19 04:22:07 +00:00
return ` Missing required callback for method ${ method } (). ` ;
} ,
2017-08-26 22:41:59 +00:00
/ * *
* @ return { string }
* /
2017-11-17 11:07:52 +00:00
ERROR _MISSING _ARG ( type : string , method : string ) {
2017-08-26 22:41:59 +00:00
return ` Missing required argument of type ' ${ type } ' for method ' ${ method } ()'. ` ;
} ,
2017-09-24 12:18:39 +00:00
/ * *
* @ return { string }
* /
2017-11-17 11:07:52 +00:00
ERROR _MISSING _ARG _NAMED ( name : string , type : string , method : string ) {
2017-09-24 12:18:39 +00:00
return ` Missing required argument ' ${ name } ' of type ' ${ type } ' for method ' ${ method } ()'. ` ;
} ,
/ * *
* @ return { string }
* /
2017-11-17 11:07:52 +00:00
ERROR _ARG _INVALID _VALUE ( name : string , expected : string , got : string ) {
2017-09-24 12:18:39 +00:00
return ` Invalid value for argument ' ${ name } ' expected value ' ${ expected } ' but got ' ${ got } '. ` ;
} ,
2017-08-26 22:41:59 +00:00
/ * *
* @ return { string }
* /
2017-11-17 11:07:52 +00:00
ERROR _PROTECTED _PROP ( name : string ) {
2017-08-26 22:41:59 +00:00
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-11-17 11:07:52 +00:00
ERROR _MISSING _MODULE ( namespace : string , nativeModule : string ) {
2017-08-18 20:05:47 +00:00
const snippet = ` firebase. ${ namespace } () ` ;
if ( Platform . OS === 'ios' ) {
2018-01-25 18:25:39 +00:00
return (
` You attempted to use a firebase module that's not installed natively on your iOS project by calling ${ snippet } . ` +
2017-08-18 20:05:47 +00:00
'\r\n\r\nEnsure you have the required Firebase iOS SDK pod for this module included in your Podfile, in this instance ' +
2018-01-25 18:25:39 +00:00
` confirm you've added "pod ' ${
NAMESPACE _PODS [ namespace ]
} ' " to your Podfile ` +
'\r\n\r\nSee http://invertase.link/ios for full setup instructions.'
) ;
2017-08-18 20:05:47 +00:00
}
2018-01-25 18:25:39 +00:00
const fbSDKDep = ` 'com.google.firebase:firebase- ${ GRADLE _DEPS [
namespace
] || namespace } ' ` ;
2017-08-18 20:05:47 +00:00
const rnFirebasePackage = ` 'io.invertase.firebase. ${ namespace } . ${ nativeModule } Package' ` ;
const newInstance = ` 'new ${ nativeModule } Package()' ` ;
2018-01-25 18:25:39 +00:00
return (
` You attempted to use a firebase module that's not installed on your Android project by calling ${ snippet } . ` +
2017-08-18 20:05:47 +00:00
` \r \n \r \n Ensure you have: \r \n \r \n 1) Installed the required Firebase Android SDK dependency ${ fbSDKDep } in your 'android/app/build.gradle' ` +
` file. \r \n \r \n 2) Imported the ${ rnFirebasePackage } module in your 'MainApplication.java' file. \r \n \r \n 3) Added the ` +
` ${ newInstance } line inside of the RN 'getPackages()' method list. ` +
2018-01-25 18:25:39 +00:00
'\r\n\r\nSee http://invertase.link/android for full setup instructions.'
) ;
2017-06-29 16:24:34 +00:00
} ,
/ * *
* @ return { string }
* /
2017-11-17 11:07:52 +00:00
ERROR _APP _NOT _INIT ( appName : string ) {
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
* /
2017-11-17 11:07:52 +00:00
ERROR _MISSING _OPT ( optName : string ) {
2017-07-18 05:04:12 +00:00
return ` Failed to initialize app. FirebaseOptions missing or invalid ' ${ optName } ' property. ` ;
} ,
2017-06-29 16:24:34 +00:00
/ * *
* @ return { string }
* /
2017-11-17 11:07:52 +00:00
ERROR _NOT _APP ( namespace : string ) {
2018-01-05 17:20:02 +00:00
return ` Invalid App instance passed to firebase. ${ namespace } (app <--). ` ;
2017-06-29 16:24:34 +00:00
} ,
2017-09-23 15:14:35 +00:00
/ * *
* @ return { string }
* /
2017-11-17 11:07:52 +00:00
ERROR _UNSUPPORTED _CLASS _METHOD ( className : string , method : string ) {
2017-10-07 02:06:29 +00:00
return ` ${ className } . ${ method } () is unsupported by the native Firebase SDKs. ` ;
2017-09-23 15:14:35 +00:00
} ,
/ * *
* @ return { string }
* /
2017-11-17 11:07:52 +00:00
ERROR _UNSUPPORTED _CLASS _PROPERTY ( className : string , property : string ) {
2017-10-07 02:06:29 +00:00
return ` ${ className } . ${ property } is unsupported by the native Firebase SDKs. ` ;
2017-09-23 15:14:35 +00:00
} ,
/ * *
* @ return { string }
* /
2018-01-03 20:00:38 +00:00
ERROR _UNSUPPORTED _MODULE _METHOD ( namespace : string , method : string ) {
return ` firebase. ${ namespace } (). ${ method } () is unsupported by the native Firebase SDKs. ` ;
2017-09-23 15:14:35 +00:00
} ,
2017-10-07 02:06:29 +00:00
/ * *
* @ return { string }
* /
2017-11-17 11:07:52 +00:00
ERROR _PLAY _SERVICES ( statusCode : number ) {
2017-10-07 02:06:29 +00:00
const knownError = PLAY _SERVICES _CODES [ statusCode ] ;
2018-01-25 18:25:39 +00:00
let start =
'Google Play Services is required to run firebase services on android but a valid installation was not found on this device.' ;
2017-10-07 02:06:29 +00:00
if ( statusCode === 2 ) {
2018-01-25 18:25:39 +00:00
start =
'Google Play Services is out of date and may cause some firebase services like authentication to hang when used. It is recommended that you update it.' ;
2017-10-07 02:06:29 +00:00
}
// eslint-disable-next-line prefer-template
2018-01-25 18:25:39 +00:00
return (
` ${ ` ${ start } \r \n \r \n ------------------------- \r \n ` } ${
knownError
? ` ${ knownError . code } : ${ knownError . message } (code ${ statusCode } ) `
: ` A specific play store availability reason reason was not available (unknown code: ${ statusCode } ) `
} \ r \ n -- -- -- -- -- -- -- -- -- -- -- -- - ` +
` \r \n \r \n ` +
` For more information on how to resolve this issue, configure Play Services checks or for guides on how to validate Play Services on your users devices see the link below: ` +
` \r \n \r \n http://invertase.link/play-services `
) ;
2017-10-07 02:06:29 +00:00
} ,
2017-06-29 16:24:34 +00:00
} ,
} ;