Socket
Socket
Sign inDemoInstall

tobostudio.cordova-plugin-firebase

Package Overview
Dependencies
0
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.0 to 4.0.4

_config.yml

26

package.json

@@ -8,9 +8,9 @@ {

"type": "git",
"url": "https://github.com/devtobo/cordova-plugin-firebase"
"url": "https://github.com/arnesson/cordova-plugin-firebase"
},
"name": "tobostudio.cordova-plugin-firebase",
"version": "4.0.0",
"version": "4.0.4",
"description": "Cordova plugin for Google Firebase",
"cordova": {
"id": "tobostudio.cordova-plugin-firebase",
"id": "cordova-plugin-firebase",
"platforms": [

@@ -31,3 +31,21 @@ "android",

"phone auth"
]
],
"scripts": {
"version": "node ./bump-version.js && git add -A plugin.xml",
"postversion": "git push && git push --tags && npm publish --verbose",
"test": "npm run test:ios && npm run test:android && npm run test:browser",
"test:android": "npm run test:cordova@6.5.0:android@6.4.0 && npm run test:cordova@7.1.0:android@7.1.0 && npm run test:cordova@8.0.0:android@7.1.0",
"test:browser": "npm run test:cordova@6.5.0:browser@5.0.3 && npm run test:cordova@7.1.0:browser@5.0.3 && npm run test:cordova@8.0.0:browser@5.0.3",
"test:ios": "npm run test:cordova@6.5.0:ios@4.5.4 && npm run test:cordova@7.1.0:ios@4.5.4 && npm run test:cordova@8.0.0:ios@4.5.4",
"test:cordova@6.5.0:ios@4.5.4": "bash ./test/test-default.sh 6.5.0 ios 4.5.4",
"test:cordova@7.1.0:ios@4.5.4": "bash ./test/test-default.sh 7.1.0 ios 4.5.4",
"test:cordova@8.0.0:ios@4.5.4": "bash ./test/test-default.sh 8.0.0 ios 4.5.4",
"test:cordova@6.5.0:android@6.4.0": "bash ./test/test-default.sh 6.5.0 android 6.4.0 && bash ./test/test-with-3-plugins.sh 6.5.0 android 6.4.0 cordova-plugin-request-location-accuracy cordova-android-play-services-gradle-release cordova-android-firebase-gradle-release",
"test:cordova@7.1.0:android@7.1.0": "bash ./test/test-default.sh 7.1.0 android 7.1.0 && bash ./test/test-with-3-plugins.sh 7.1.0 android 7.1.0 cordova-plugin-request-location-accuracy cordova-android-play-services-gradle-release cordova-android-firebase-gradle-release",
"test:cordova@8.0.0:android@7.1.0": "bash ./test/test-default.sh 8.0.0 android 7.1.0 && bash ./test/test-with-3-plugins.sh 8.0.0 android 7.1.0 cordova-plugin-request-location-accuracy cordova-android-play-services-gradle-release cordova-android-firebase-gradle-release",
"test:cordova@6.5.0:browser@5.0.3": "bash ./test/test-default.sh 6.5.0 browser 5.0.3",
"test:cordova@7.1.0:browser@5.0.3": "bash ./test/test-default.sh 7.1.0 browser 5.0.3",
"test:cordova@8.0.0:browser@5.0.3": "bash ./test/test-default.sh 8.0.0 browser 5.0.3"
},
"dependencies": {}
}

582

README.md
[![Build Status](https://travis-ci.org/arnesson/cordova-plugin-firebase.svg?branch=master)](https://travis-ci.org/arnesson/cordova-plugin-firebase)
# cordova-plugin-firebase
This plugin brings push notifications, analytics, event tracking, crash reporting and more from Google Firebase to your Cordova project!
Android and iOS supported.
This plugin brings push notifications, analytics, event tracking, crash reporting and more from Google Firebase to your Cordova project! Android and iOS supported.
Donations are welcome and will go towards further development of this project. Use the addresses below to donate.
## Supported Cordova Versions
- cordova: `>= 6`
- cordova-android: `>= 6.4`
- cordova-ios: `>= 4`
```
BTC: 1JuXhHMCPHXT2fDfSRUTef9TpE2D67sc9f
ETH: 0x74B5eDEce465fDd360b3b03C6984784140ac742e
BCH: qzu5ffphkcgajn7kd7d90etq82maylz34uqg4uj5jf
LTC: LKnFugRfczVH7qfBrmhzZDknhqxCzz6wJB
XMR: 43ZMMEh5x4miZLMZF3W3faAL5Y44fPBXrFWBVXYePBjwXCvxLuo84Cof8ufXgb4sZLEpSDE3eKr5X7jNPfd4kppr8oMX9uM
Paypal: https://paypal.me/arnesson
```
Thank you for your support!
## Installation
See npm package for versions - https://www.npmjs.com/package/cordova-plugin-firebase
Great installation and setup guide by Medium.com - [https://medium.com/@felipepucinelli/how-to-add-push...](https://medium.com/@felipepucinelli/how-to-add-push-notifications-in-your-cordova-application-using-firebase-69fac067e821)
Install the plugin by running:
Install the plugin by adding it to your project's config.xml:
```
cordova plugin add cordova-plugin-firebase --APP_DOMAIN=123456.app.goo.gl
<plugin name="cordova-plugin-firebase" spec="^2.0.0" />
```
or adding it to your project's package.json:
or by running:
```
"cordova-plugin-firebase": {
"APP_DOMAIN": "123456.app.goo.gl",
},
cordova plugin add cordova-plugin-firebase --save
```
Your APP_DOMAIN is used for Firebase Dynamic Links. You can find it when creating a Dynamic Link, or use a dummy one if you don't need to use dynamic links.
### Guides
Great installation and setup guide by Medium.com - [https://medium.com/@felipepucinelli/how-to-add-push...](https://medium.com/@felipepucinelli/how-to-add-push-notifications-in-your-cordova-application-using-firebase-69fac067e821)
You can use the variables GMS_VERSION and FIREBASE_VERSION to change the version of the libraries for Android.
### Setup
Download your Firebase configuration files, GoogleService-Info.plist for iOS and google-services.json for android, and place them in the root folder of your cordova project. Check out this [firebase article](https://support.google.com/firebase/answer/7015592) for details on how to download the files.
Download your Firebase configuration files, GoogleService-Info.plist for ios and google-services.json for android, and place them in the root folder of your cordova project:
```

@@ -54,538 +38,24 @@ - My Project/

See https://support.google.com/firebase/answer/7015592 for details how to download the files from firebase.
###### IMPORTANT NOTES
- This plugin uses a hook (after prepare) that copies the configuration files to the right place, namely `platforms/ios/\<My Project\>/Resources` for ios and `platforms/android` for android.
- Firebase SDK requires the configuration files to be present and valid, otherwise your app will crash on boot or Firebase features won't work.
This plugin uses a hook (after prepare) that copies the configuration files to the right place, namely platforms/ios/\<My Project\>/Resources for ios and platforms/android for android.
### PhoneGap Build
Hooks do not work with PhoneGap Build. This means you will have to manually make sure the configuration files are included. One way to do that is to make a private fork of this plugin and replace the placeholder config files (see `src/ios` and `src/android`) with your actual ones, as well as hard coding your app id and api key in `plugin.xml`.
For iOS, the hook also adds a Shell Script build phase to upload your dSYM to Crashlytics automatically.
### Google Play Services
Your build may fail if you are installing multiple plugins that use Google Play Services. This is caused by the plugins installing different versions of the Google Play Services library. This can be resolved by installing [cordova-android-play-services-gradle-release](https://github.com/dpa99c/cordova-android-play-services-gradle-release).
For Android, the hook changes your build.gradle files to add the necessary build dependencies and gradle plugins needed. It tries as much as possible not to mess with the rest of the build.gradle, but you might run into issues if you are also modifying this file outside of cordova.
If your build is still failing, you can try installing [cordova-android-firebase-gradle-release](https://github.com/dpa99c/cordova-android-firebase-gradle-release). For more info, read the following [comment](https://github.com/dpa99c/cordova-plugin-request-location-accuracy/issues/50#issuecomment-390025013) about locking down the specific versions for play services and firebase. It is suggested to use `+` instead of `15.+` to ensure the correct versions are used.
**Note that the Firebase SDK requires the configuration files to be present and valid, otherwise your app will crash on boot or Firebase features won't work.**
### Notes about PhoneGap Build
Hooks does not work with PhoneGap Build. This means you will have to manually make sure the configuration files are included. One way to do that is to make a private fork of this plugin and replace the placeholder config files (see src/ios and src/android) with your actual ones, as well as hard coding your app id and api key in plugin.xml.
## Google Tag Manager
### Android
Download your container-config json file from Tag Manager and add a resource-file node in your config.xml.
```
....
<platform name="android">
<content src="index.html" />
<resource-file src="GTM-5MFXXXX.json" target="assets/containers/GTM-5MFXXXX.json" />
...
```
## Changing Notification Icon
The plugin will use notification_icon from drawable resources if it exists, otherwise the default app icon will is used.
To set a big icon and small icon for notifications, define them through drawable nodes.
Create the required styles.xml files and add the icons to the
`<projectroot>/res/native/android/res/<drawable-DPI>` folders.
Checkout our [guide](docs/GOOGLE_TAG_MANAGER.md) for info on setting up Google Tag Manager.
The example below uses a png named "ic_silhouette.png", the app Icon (@mipmap/icon) and sets a base theme.
From android version 21 (Lollipop) notifications were changed, needing a seperate setting.
If you only target Lollipop and above, you don't need to setup both.
Thankfully using the version dependant asset selections, we can make one build/apk supporting all target platforms.
`<projectroot>/res/native/android/res/values/styles.xml`
```
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<!-- inherit from the holo theme -->
<style name="AppTheme" parent="android:Theme.Light">
<item name="android:windowDisablePreview">true</item>
</style>
<drawable name="notification_big">@mipmap/icon</drawable>
<drawable name="notification_icon">@mipmap/icon</drawable>
</resources>
```
and
`<projectroot>/res/native/android/res/values-v21/styles.xml`
```
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<item name="android:windowDisablePreview">true</item>
</style>
<drawable name="notification_big">@mipmap/icon</drawable>
<drawable name="notification_icon">@drawable/ic_silhouette</drawable>
</resources>
```
## Configuring Notifications
## Notification Colors
Checkout our [guide](docs/NOTIFICATIONS.md) for info on configuring notification icons and colors.
On Android Lollipop and above you can also set the accent color for the notification by adding a color setting.
## API
`<projectroot>/res/native/android/res/values/colors.xml`
```
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary">#FFFFFF00</color>
<color name="primary_dark">#FF220022</color>
<color name="accent">#FF00FFFF</color>
</resources>
```
## Methods
### getToken
Get the device token (id):
```
window.FirebasePlugin.getToken(function(token) {
// save this server-side and use it to push notifications to this device
console.log(token);
}, function(error) {
console.error(error);
});
```
Note that token will be null if it has not been established yet
### onTokenRefresh
Register for token changes:
```
window.FirebasePlugin.onTokenRefresh(function(token) {
// save this server-side and use it to push notifications to this device
console.log(token);
}, function(error) {
console.error(error);
});
```
This is the best way to get a valid token for the device as soon as the token is established
### onNotificationOpen
Register notification callback:
```
window.FirebasePlugin.onNotificationOpen(function(notification) {
console.log(notification);
}, function(error) {
console.error(error);
});
```
Notification flow:
1. App is in foreground:
1. User receives the notification data in the JavaScript callback without any notification on the device itself (this is the normal behaviour of push notifications, it is up to you, the developer, to notify the user)
2. App is in background:
1. User receives the notification message in its device notification bar
2. User taps the notification and the app opens
3. User receives the notification data in the JavaScript callback
Notification icon on Android:
[Changing notification icon](#changing-notification-icon)
### grantPermission (iOS only)
Grant permission to recieve push notifications (will trigger prompt):
```
window.FirebasePlugin.grantPermission();
```
### hasPermission
Check permission to recieve push notifications:
```
window.FirebasePlugin.hasPermission(function(data){
console.log(data.isEnabled);
});
```
### setBadgeNumber
Set a number on the icon badge:
```
window.FirebasePlugin.setBadgeNumber(3);
```
Set 0 to clear the badge
```
window.FirebasePlugin.setBadgeNumber(0);
```
### getBadgeNumber
Get icon badge number:
```
window.FirebasePlugin.getBadgeNumber(function(n) {
console.log(n);
});
```
### subscribe
Subscribe to a topic:
```
window.FirebasePlugin.subscribe("example");
```
### unsubscribe
Unsubscribe from a topic:
```
window.FirebasePlugin.unsubscribe("example");
```
### unregister
Unregister from firebase, used to stop receiving push notifications. Call this when you logout user from your app. :
```
window.FirebasePlugin.unregister();
```
### logEvent
Log an event using Analytics:
```
window.FirebasePlugin.logEvent("select_content", {content_type: "page_view", item_id: "home"});
```
### setScreenName
Set the name of the current screen in Analytics:
```
window.FirebasePlugin.setScreenName("Home");
```
### setUserId
Set a user id for use in Analytics:
```
window.FirebasePlugin.setUserId("user_id");
```
### setUserProperty
Set a user property for use in Analytics:
```
window.FirebasePlugin.setUserProperty("name", "value");
```
### setAnalyticsCollectionEnabled
Enable/disable analytics collection
```
window.FirebasePlugin.setAnalyticsCollectionEnabled(true); // Enables analytics collection
window.FirebasePlugin.setAnalyticsCollectionEnabled(false); // Disables analytics collection
```
### verifyPhoneNumber (Android only)
Request a verificationId and send a SMS with a verificationCode.
Use them to construct a credenial to sign in the user (in your app).
https://firebase.google.com/docs/auth/android/phone-auth
https://firebase.google.com/docs/reference/js/firebase.auth.Auth#signInWithCredential
NOTE: To use this auth you need to configure your app SHA hash in the android app configuration on firebase console.
See https://developers.google.com/android/guides/client-auth to know how to get SHA app hash.
NOTE: This will only works on physical devices.
```
window.FirebasePlugin.verifyPhoneNumber(number, timeOutDuration, function(credential) {
console.log(credential);
// ask user to input verificationCode:
var code = inputField.value.toString();
var verificationId = credential.verificationId;
var signInCredential = firebase.auth.PhoneAuthProvider.credential(verificationId, code);
firebase.auth().signInWithCredential(signInCredential);
}, function(error) {
console.error(error);
});
```
### fetch
Fetch Remote Config parameter values for your app:
```
window.FirebasePlugin.fetch(function () {
// success callback
}, function () {
// error callback
});
// or, specify the cacheExpirationSeconds
window.FirebasePlugin.fetch(600, function () {
// success callback
}, function () {
// error callback
});
```
### activateFetched
Activate the Remote Config fetched config:
```
window.FirebasePlugin.activateFetched(function(activated) {
// activated will be true if there was a fetched config activated,
// or false if no fetched config was found, or the fetched config was already activated.
console.log(activated);
}, function(error) {
console.error(error);
});
```
### getValue
Retrieve a Remote Config value:
```
window.FirebasePlugin.getValue("key", function(value) {
console.log(value);
}, function(error) {
console.error(error);
});
// or, specify a namespace for the config value
window.FirebasePlugin.getValue("key", "namespace", function(value) {
console.log(value);
}, function(error) {
console.error(error);
});
```
### getByteArray (Android only)
**NOTE: byte array is only available for SDK 19+**
Retrieve a Remote Config byte array:
```
window.FirebasePlugin.getByteArray("key", function(bytes) {
// a Base64 encoded string that represents the value for "key"
console.log(bytes.base64);
// a numeric array containing the values of the byte array (i.e. [0xFF, 0x00])
console.log(bytes.array);
}, function(error) {
console.error(error);
});
// or, specify a namespace for the byte array
window.FirebasePlugin.getByteArray("key", "namespace", function(bytes) {
// a Base64 encoded string that represents the value for "key"
console.log(bytes.base64);
// a numeric array containing the values of the byte array (i.e. [0xFF, 0x00])
console.log(bytes.array);
}, function(error) {
console.error(error);
});
```
### getInfo (Android only)
Get the current state of the FirebaseRemoteConfig singleton object:
```
window.FirebasePlugin.getInfo(function(info) {
// the status of the developer mode setting (true/false)
console.log(info.configSettings.developerModeEnabled);
// the timestamp (milliseconds since epoch) of the last successful fetch
console.log(info.fetchTimeMillis);
// the status of the most recent fetch attempt (int)
// 0 = Config has never been fetched.
// 1 = Config fetch succeeded.
// 2 = Config fetch failed.
// 3 = Config fetch was throttled.
console.log(info.lastFetchStatus);
}, function(error) {
console.error(error);
});
```
### setConfigSettings (Android only)
Change the settings for the FirebaseRemoteConfig object's operations:
```
var settings = {
developerModeEnabled: true
}
window.FirebasePlugin.setConfigSettings(settings);
```
### setDefaults (Android only)
Set defaults in the Remote Config:
```
// define defaults
var defaults = {
// map property name to value in Remote Config defaults
mLong: 1000,
mString: 'hello world',
mDouble: 3.14,
mBoolean: true,
// map "mBase64" to a Remote Config byte array represented by a Base64 string
// Note: the Base64 string is in an array in order to differentiate from a string config value
mBase64: ["SGVsbG8gV29ybGQ="],
// map "mBytes" to a Remote Config byte array represented by a numeric array
mBytes: [0xFF, 0x00]
}
// set defaults
window.FirebasePlugin.setDefaults(defaults);
// or, specify a namespace
window.FirebasePlugin.setDefaults(defaults, "namespace");
```
### startTrace
Start a trace.
```
window.FirebasePlugin.startTrace("test trace", success, error);
```
### incrementCounter
To count the performance-related events that occur in your app (such as cache hits or retries), add a line of code similar to the following whenever the event occurs, using a string other than retry to name that event if you are counting a different type of event:
```
window.FirebasePlugin.incrementCounter("test trace", "retry", success, error);
```
### incrementCounterByValue
Same as incrementCounter, but allows incrementing by a value different than 1:
```
window.FirebasePlugin.incrementCounterByValue("test trace", "retry", 42, success, error);
```
### stopTrace
Stop the trace
```
window.FirebasePlugin.stopTrace("test trace");
```
### sendImmediateTraceCounter
This is a shortcut method for starting a trace, setting a counter value, and then immediately stopping the trace. It can be useful if you're only interested in reporting a numeric value and not a duration-based trace.
```
window.FirebasePlugin.sendImmediateTraceCounter("test trace", "retry", 42, success, error);
```
### sendJavascriptError
Sends a non-fatal error, including a stack trace, to Crashlytics.
The StackTrace.JS library can be useful in extracting a stack trace from a JavaScript Exception, see https://github.com/stacktracejs/error-stack-parser
Here is an example on how to set-up an error handler in your app that will report all uncaught exceptions:
```
var errorHandler = function (errorEvent) {
var error = errorEvent.error;
// fileName is supported on some platforms but not all
var fileName = error.fileName
try {
// get a stack trace using stacktrace.js (not included in this plugin)
var stack = ErrorStackParser.parse(error)
var stackJsonObj = stack.map(function (frame) {
return {
functionName: frame.functionName,
fileName: frame.fileName,
lineNumber: frame.lineNumber,
columnNumber: frame.columnNumber,
};
})
window.FirebasePlugin.sendJavascriptError(error.message, fileName, stackJsonObj)
} catch (error) {
console.error('Handled error in firebase report error: ', error)
}
}
window.addEventListener('error', errorHandler);
```
### sendUserError
Sends a non-fatal error with a message and a group of key/values.
```
var error = new Error("Test Error");
window.FirebasePlugin.sendUserError("Network Error", {url: 'http://www.google.com'});
```
### setCrashlyticsValue
Set a key/value for Crashlytics. Those keys are attached to crash reports and can help figuring out what a user was doing before a crash.
```
window.FirebasePlugin.setCrashlyticsValue("my_key", "my_value");
```
### logCrashlytics
Send a log to Crashlytics. These logs are attached to crash reports and can help figuring out what a user was doing before a crash.
```
window.FirebasePlugin.logCrashlytics("log message");
```
### onDynamicLink
Register a callback to be called when your app is opened with a Dynamic Link. Only one callback can be registered at the same time, registering another callback will unset the first.
```
function onSuccess(eventData) {
// eventData = { deepLink: string, matchType: 'Weak'|'Strong' }
console.log("Received dynamic link: ", eventData)
}
function onError(error) {
console.log("Received dynamic link error: ", error)
}
window.FirebasePlugin.onDynamicLink(onSuccess, onError)
```
### Phone Authentication
**BASED ON THE CONTRIBUTIONS OF**
IOS
https://github.com/silverio/cordova-plugin-firebase
ANDROID
https://github.com/apptum/cordova-plugin-firebase
**((((IOS))): SETUP YOUR PUSH NOTIFICATIONS FIRST, AND VERIFY THAT THEY ARE ARRIVING TO YOUR PHYSICAL DEVICE BEFORE YOU TEST THIS METHOD. USE THE APNS AUTH KEY TO GENERATE THE .P8 FILE AND UPLOAD IT TO FIREBASE.
WHEN YOU CALL THIS METHOD, FCM SENDS A SILENT PUSH TO THE DEVICE TO VERIFY IT.**
This method sends an SMS to the user with the SMS_code and gets the verification id you need to continue the sign in process, with the Firebase JS SDK.
```
window.FirebasePlugin.getVerificationID("+573123456789",function(id) {
console.log("verificationID: "+id);
}, function(error) {
console.error(error);
});
```
Using Ionic2?
```
(<any>window).FirebasePlugin.getVerificationID("+573123456789", id => {
console.log("verificationID: " + id);
this.verificationId = id;
}, error => {
console.log("error: " + error);
});
```
Get the intermediate AuthCredential object
```
var credential = firebase.auth.PhoneAuthProvider.credential(verificationId, SMS_code);
```
Then, you can sign in the user with the credential:
```
firebase.auth().signInWithCredential(credential);
```
Or link to an account
```
firebase.auth().currentUser.linkWithCredential(credential)
```
See the full [API](docs/API.md) available for this plugin.

@@ -12,22 +12,6 @@ #!/usr/bin/env node

var path = require('path');
var iosHelper = require('./ios-helper');
var utilities = require("./lib/utilities");
var pluginPackage = require('../package.json');
var pluginId = pluginPackage.name;
fs.ensureDirSync = function (dir) {
if (!fs.existsSync(dir)) {
dir.split(path.sep).reduce(function (currentPath, folder) {
currentPath += folder + path.sep;
if (!fs.existsSync(currentPath)) {
fs.mkdirSync(currentPath);
}
return currentPath;
}, '');
}
};
var $context = null
var config = fs.readFileSync('config.xml').toString();
var name = getValue(config, 'name');
var name = utilities.getValue(config, 'name');

@@ -38,195 +22,39 @@ var IOS_DIR = 'platforms/ios';

var PLATFORM = {
IOS: {
dest: [
IOS_DIR + '/' + name + '/Resources/GoogleService-Info.plist',
],
src: [
'GoogleService-Info.plist',
IOS_DIR + '/www/GoogleService-Info.plist',
'www/GoogleService-Info.plist'
]
},
ANDROID: {
dest: [
ANDROID_DIR + '/app/google-services.json'
],
src: [
'google-services.json',
ANDROID_DIR + '/assets/www/google-services.json',
'www/google-services.json'
],
}
IOS: {
dest: [
IOS_DIR + '/' + name + '/Resources/GoogleService-Info.plist',
IOS_DIR + '/' + name + '/Resources/Resources/GoogleService-Info.plist'
],
src: [
'GoogleService-Info.plist',
IOS_DIR + '/www/GoogleService-Info.plist',
'www/GoogleService-Info.plist'
]
},
ANDROID: {
dest: [
ANDROID_DIR + '/google-services.json',
ANDROID_DIR + '/app/google-services.json'
],
src: [
'google-services.json',
ANDROID_DIR + '/assets/www/google-services.json',
'www/google-services.json',
ANDROID_DIR + '/app/src/main/google-services.json'
],
}
};
function copyKey(platform, callback) {
for (var i = 0; i < platform.src.length; i++) {
var file = platform.src[i];
if (fileExists(file)) {
try {
var contents = fs.readFileSync(file).toString();
try {
platform.dest.forEach(function (destinationPath) {
var folder = destinationPath.substring(0, destinationPath.lastIndexOf('/'));
fs.ensureDirSync(folder);
fs.writeFileSync(destinationPath, contents);
});
} catch (e) {
// skip
}
callback && callback(contents);
} catch (err) {
console.log(err)
}
break;
}
}
}
function getValue(config, name) {
var value = config.match(new RegExp('<' + name + '(?:.*?)>(.*?)</' + name + '>', 'i'));
if (value && value[1]) {
return value[1]
} else {
return null
}
}
function fileExists(path) {
try {
return fs.statSync(path).isFile();
} catch (e) {
return false;
}
}
function directoryExists(path) {
try {
return fs.statSync(path).isDirectory();
} catch (e) {
return false;
}
}
function patchProjectLevelGradleBuildFiles() {
var projectBuildGradle = path.join(ANDROID_DIR, 'build.gradle')
var contents = fs.readFileSync(projectBuildGradle, 'utf8');
var hasFabricMaven = contents.match('https://maven.fabric.io/public')
var hasClasspathGoogleServices = contents.match("classpath 'com.google.gms:google-services")
var hasClasspathFirebasePlugins = contents.match("classpath 'com.google.firebase:firebase-plugins")
var hasClasspathFabricTools = contents.match("classpath 'io.fabric.tools:gradle")
var split = contents.split('\n')
var length = split.length
for (var i = 0 ; i < length-2 ; i++) {
/**
* Add maven https://maven.fabric.io/public to buildscript repositiories
*/
if (!hasFabricMaven &&
split[i].match('google()') &&
split[i+1].match('jcenter()') &&
(split[i-2].match('buildscript'))
) {
split.splice(i+1, 0, " maven { url 'https://maven.fabric.io/public' }");
}
/**
* Add classpath dependencies to buildscript
*/
if (split[i].match("classpath 'com.android.tools.build:gradle")) {
if (!hasClasspathGoogleServices) {
split.splice(i+1, 0, " classpath 'com.google.gms:google-services:4.0.1'")
}
if (!hasClasspathFirebasePlugins) {
split.splice(i+1, 0, " classpath 'com.google.firebase:firebase-plugins:1.1.5'")
}
if (!hasClasspathFabricTools) {
split.splice(i+1, 0, " classpath 'io.fabric.tools:gradle:1.+'")
}
}
}
var newContents = split.join('\n')
console.log("==========\nNew project-level build.gradle :\n==========\n", newContents)
var contents = fs.writeFileSync(projectBuildGradle, newContents, {encoding: 'utf8'});
console.log("Written to :", projectBuildGradle)
}
function patchAppLevelGradleBuildFiles() {
var appBuildGradle = path.join(ANDROID_DIR, 'app', 'build.gradle')
var contents = fs.readFileSync(appBuildGradle, 'utf8');
var hasFabricPlugin = contents.match("apply plugin: 'io.fabric'")
var hasFirebasePerfPlugin = contents.match("apply plugin: 'com.google.firebase.firebase-perf'")
var split = contents.split('\n')
var length = split.length
for (var i = 0 ; i < length-1 ; i++) {
/**
* Add apply plugin directives
*/
if (split[i].match("apply plugin: 'com.android.application'")) {
if (!hasFabricPlugin) {
split.splice(i+1, 0, "apply plugin: 'io.fabric'")
}
if (!hasFirebasePerfPlugin) {
split.splice(i+1, 0, "apply plugin: 'com.google.firebase.firebase-perf'")
}
}
}
var newContents = split.join('\n')
console.log("==========\nNew app-level build.gradle :\n==========\n", newContents)
var contents = fs.writeFileSync(appBuildGradle, newContents, {encoding: 'utf8'});
console.log("Written to :", appBuildGradle)
}
function patchGradleBuildFiles() {
console.log('Patching build.gradle files');
patchProjectLevelGradleBuildFiles();
patchAppLevelGradleBuildFiles();
}
function setupShellScriptBuildPhase() {
var projectPath = path.join(IOS_DIR, name + ".xcodeproj", "project.pbxproj");
iosHelper.removeShellScriptBuildPhase($context, projectPath)
iosHelper.addShellScriptBuildPhase($context, pluginId, projectPath)
}
module.exports = function (context) {
//get platform from the context supplied by cordova
var platforms = context.opts.platforms;
$context = context
// Copy key files to their platform specific folders
if (platforms.indexOf('ios') !== -1 && directoryExists(IOS_DIR)) {
console.log('Preparing Firebase on iOS');
copyKey(PLATFORM.IOS, setupShellScriptBuildPhase);
}
if (platforms.indexOf('android') !== -1 && directoryExists(ANDROID_DIR)) {
console.log('Preparing Firebase on Android');
copyKey(PLATFORM.ANDROID, patchGradleBuildFiles)
}
//get platform from the context supplied by cordova
var platforms = context.opts.platforms;
// Copy key files to their platform specific folders
if (platforms.indexOf('ios') !== -1 && utilities.directoryExists(IOS_DIR)) {
console.log('Preparing Firebase on iOS');
utilities.copyKey(PLATFORM.IOS);
}
if (platforms.indexOf('android') !== -1 && utilities.directoryExists(ANDROID_DIR)) {
console.log('Preparing Firebase on Android');
utilities.copyKey(PLATFORM.ANDROID);
}
};
exports.getVerificationID = function (number, success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.getInstanceId = function (success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.getToken = function (success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.getId = function (success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.onNotificationOpen = function (success, error) {
};
exports.onNotificationOpen = function (success, error) {};
exports.onTokenRefresh = function (success, error) {
};
exports.onTokenRefresh = function (success, error) {};
exports.grantPermission = function (success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.setBadgeNumber = function (number, success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.getBadgeNumber = function (success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.subscribe = function (topic, success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.unsubscribe = function (topic, success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.logEvent = function (name, params, success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.logError = function (message, success, error) {
if (typeof success === 'function') {
success();
}
};
exports.setCrashlyticsUserId = function (userId, success, error) {
if (typeof success === 'function') {

@@ -74,85 +78,83 @@ success();

exports.setScreenName = function (name, success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.setUserId = function (id, success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.setUserProperty = function (name, value, success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.activateFetched = function (success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.fetch = function (cacheExpirationSeconds, success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.getByteArray = function (key, namespace, success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.getValue = function (key, namespace, success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.getInfo = function (success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.setConfigSettings = function (settings, success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.setDefaults = function (defaults, namespace, success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.verifyPhoneNumber = function (number, timeOutDuration, success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
exports.setAnalyticsCollectionEnabled = function (enabled, success, error) {
if (typeof success === 'function') {
success();
}
if (typeof success === 'function') {
success();
}
};
// Crashlytics
exports.sendJavascriptError = function(message, fileName, stackFrames, success, error) {
exports.setPerformanceCollectionEnabled = function (enabled, success, error) {
if (typeof success === 'function') {
success();
}
};
exports.sendUserError = function(message, dictionary, success, error) {
};
exports.setCrashlyticsValue = function(name, value, success, error) {
};
exports.logCrashlytics = function(name, value, success, error) {
};
exports.clearAllNotifications = function (success, error) {
if (typeof success === 'function') {
success();
}
};
var exec = require('cordova/exec');
exports.getVerificationID = function (number, success, error) {
exec(success, error, "FirebasePlugin", "getVerificationID", [number]);
};
exports.getInstanceId = function (success, error) {
exec(success, error, "FirebasePlugin", "getInstanceId", []);
exec(success, error, "FirebasePlugin", "getInstanceId", []);
};
exports.getId = function (success, error) {
exec(success, error, "FirebasePlugin", "getId", []);
exec(success, error, "FirebasePlugin", "getId", []);
};
exports.getToken = function (success, error) {
exec(success, error, "FirebasePlugin", "getToken", []);
exec(success, error, "FirebasePlugin", "getToken", []);
};
exports.onNotificationOpen = function (success, error) {
exec(success, error, "FirebasePlugin", "onNotificationOpen", []);
exec(success, error, "FirebasePlugin", "onNotificationOpen", []);
};
exports.onTokenRefresh = function (success, error) {
exec(success, error, "FirebasePlugin", "onTokenRefresh", []);
exec(success, error, "FirebasePlugin", "onTokenRefresh", []);
};
exports.grantPermission = function (success, error) {
exec(success, error, "FirebasePlugin", "grantPermission", []);
exec(success, error, "FirebasePlugin", "grantPermission", []);
};
exports.hasPermission = function (success, error) {
exec(success, error, "FirebasePlugin", "hasPermission", []);
exec(success, error, "FirebasePlugin", "hasPermission", []);
};
exports.setBadgeNumber = function (number, success, error) {
exec(success, error, "FirebasePlugin", "setBadgeNumber", [number]);
exec(success, error, "FirebasePlugin", "setBadgeNumber", [number]);
};
exports.getBadgeNumber = function (success, error) {
exec(success, error, "FirebasePlugin", "getBadgeNumber", []);
exec(success, error, "FirebasePlugin", "getBadgeNumber", []);
};
exports.subscribe = function (topic, success, error) {
exec(success, error, "FirebasePlugin", "subscribe", [topic]);
exec(success, error, "FirebasePlugin", "subscribe", [topic]);
};
exports.unsubscribe = function (topic, success, error) {
exec(success, error, "FirebasePlugin", "unsubscribe", [topic]);
exec(success, error, "FirebasePlugin", "unsubscribe", [topic]);
};
exports.unregister = function (success, error) {
exec(success, error, "FirebasePlugin", "unregister", []);
exec(success, error, "FirebasePlugin", "unregister", []);
};
exports.logEvent = function (name, params, success, error) {
exec(success, error, "FirebasePlugin", "logEvent", [name, params]);
exec(success, error, "FirebasePlugin", "logEvent", [name, params]);
};
exports.setAnalyticsCollectionEnabled = function (enabled, success, error) {
exec(success, error, "FirebasePlugin", "setAnalyticsCollectionEnabled", [enabled]);
exports.logError = function (message, success, error) {
exec(success, error, "FirebasePlugin", "logError", [message]);
};
exports.logError = function (message, success, error) {
exec(success, error, "FirebasePlugin", "logError", [message]);
exports.logJavascriptError = function(message, fileName, stackFrames, success, error) {
exec(success, error, "FirebasePlugin", "logJavascriptError", [message, fileName, stackFrames]);
};
exports.logUserError = function(message, dictionary, success, error) {
exec(success, error, "FirebasePlugin", "logUserError", [message, dictionary]);
};
exports.setCrashlyticsValue = function(name, value, success, error) {
exec(success, error, "FirebasePlugin", "setCrashlyticsValue", [name, value]);
};
exports.setCrashlyticsUserId = function (userId, success, error) {
exec(success, error, "FirebasePlugin", "setCrashlyticsUserId", [userId]);
};
exports.setScreenName = function (name, success, error) {
exec(success, error, "FirebasePlugin", "setScreenName", [name]);
exec(success, error, "FirebasePlugin", "setScreenName", [name]);
};
exports.setUserId = function (id, success, error) {
exec(success, error, "FirebasePlugin", "setUserId", [id]);
exec(success, error, "FirebasePlugin", "setUserId", [id]);
};
exports.setUserProperty = function (name, value, success, error) {
exec(success, error, "FirebasePlugin", "setUserProperty", [name, value]);
exec(success, error, "FirebasePlugin", "setUserProperty", [name, value]);
};
exports.activateFetched = function (success, error) {
exec(success, error, "FirebasePlugin", "activateFetched", []);
exec(success, error, "FirebasePlugin", "activateFetched", []);
};
exports.fetch = function (cacheExpirationSeconds, success, error) {
var args = [];
if (typeof cacheExpirationSeconds === 'number') {
args.push(cacheExpirationSeconds);
} else {
error = success;
success = cacheExpirationSeconds;
}
exec(success, error, "FirebasePlugin", "fetch", args);
var args = [];
if (typeof cacheExpirationSeconds === 'number') {
args.push(cacheExpirationSeconds);
} else {
error = success;
success = cacheExpirationSeconds;
}
exec(success, error, "FirebasePlugin", "fetch", args);
};
exports.getByteArray = function (key, namespace, success, error) {
var args = [key];
if (typeof namespace === 'string') {
args.push(namespace);
} else {
error = success;
success = namespace;
}
exec(success, error, "FirebasePlugin", "getByteArray", args);
var args = [key];
if (typeof namespace === 'string') {
args.push(namespace);
} else {
error = success;
success = namespace;
}
exec(success, error, "FirebasePlugin", "getByteArray", args);
};
exports.getValue = function (key, namespace, success, error) {
var args = [key];
if (typeof namespace === 'string') {
args.push(namespace);
} else {
error = success;
success = namespace;
}
exec(success, error, "FirebasePlugin", "getValue", args);
var args = [key];
if (typeof namespace === 'string') {
args.push(namespace);
} else {
error = success;
success = namespace;
}
exec(success, error, "FirebasePlugin", "getValue", args);
};
exports.getKeysAndValuesWithPrefix = function (prefix, success, error) {
var args = [prefix];
exec(success, error, "FirebasePlugin", "getKeysAndValuesWithPrefix", args);
};
exports.getInfo = function (success, error) {
exec(success, error, "FirebasePlugin", "getInfo", []);
exec(success, error, "FirebasePlugin", "getInfo", []);
};
exports.setConfigSettings = function (settings, success, error) {
exec(success, error, "FirebasePlugin", "setConfigSettings", [settings]);
exec(success, error, "FirebasePlugin", "setConfigSettings", [settings]);
};
exports.setDefaults = function (defaults, namespace, success, error) {
var args = [defaults];
if (typeof namespace === 'string') {
args.push(namespace);
} else {
error = success;
success = namespace;
}
exec(success, error, "FirebasePlugin", "setDefaults", args);
var args = [defaults];
if (typeof namespace === 'string') {
args.push(namespace);
} else {
error = success;
success = namespace;
}
exec(success, error, "FirebasePlugin", "setDefaults", args);
};
// Crashlytics
exports.sendJavascriptError = function(message, fileName, stackFrames, success, error) {
exec(success, error, "FirebasePlugin", "sendJavascriptError", [message, fileName, stackFrames]);
exports.startTrace = function (name, success, error) {
exec(success, error, "FirebasePlugin", "startTrace", [name]);
};
exports.sendUserError = function(message, dictionary, success, error) {
exec(success, error, "FirebasePlugin", "sendUserError", [message, dictionary]);
exports.incrementCounter = function (name, counterNamed, success, error) {
exec(success, error, "FirebasePlugin", "incrementCounter", [name, counterNamed]);
};
exports.setCrashlyticsValue = function(name, value, success, error) {
exec(success, error, "FirebasePlugin", "setCrashlyticsValue", [name, value]);
exports.stopTrace = function (name, success, error) {
exec(success, error, "FirebasePlugin", "stopTrace", [name]);
};
exports.logCrashlytics = function(message, success, error) {
exec(success, error, "FirebasePlugin", "logCrashlytics", [message]);
exports.setAnalyticsCollectionEnabled = function (enabled, success, error) {
exec(success, error, "FirebasePlugin", "setAnalyticsCollectionEnabled", [enabled]);
};
// Performance
exports.startTrace = function(traceName, success, error) {
exec(success, error, "FirebasePlugin", "startTrace", [traceName]);
exports.setPerformanceCollectionEnabled = function (enabled, success, error) {
exec(success, error, "FirebasePlugin", "setPerformanceCollectionEnabled", [enabled]);
};
// Deprecated, use incrementCounterByValue(name, 1) instead
exports.incrementCounter = function (traceName, counterName, success, error) {
exec(success, error, "FirebasePlugin", "incrementCounter", [traceName, counterName]);
exports.verifyPhoneNumber = function (number, timeOutDuration, success, error) {
if (typeof timeOutDuration === 'function') {
// method being called with old signature: function(number, success, error)
// timeOutDuration is the success callback, success is the error callback
exec(timeOutDuration, success, "FirebasePlugin", "verifyPhoneNumber", [number]);
} else {
// method being called with new signature: function(number, timeOutDuration, success, error)
// callbacks are correctly named
exec(success, error, "FirebasePlugin", "verifyPhoneNumber", [number, timeOutDuration]);
}
};
exports.incrementCounterByValue = function (traceName, counterName, counterValue, success, error) {
exec(success, error, "FirebasePlugin", "incrementCounterByValue", [traceName, counterName, counterValue]);
exports.clearAllNotifications = function (success, error) {
exec(success, error, "FirebasePlugin", "clearAllNotifications", []);
};
exports.setCounterToValue = function(traceName, counterName, counterValue, success, error) {
exec(success, error, "FirebasePlugin", "setCounterToValue", [traceName, counterName, counterValue]);
};
exports.stopTrace = function(traceName, success, error) {
exec(success, error, "FirebasePlugin", "stopTrace", [traceName]);
};
// shortcut for startTrace + setCounterToValue + stopTrace
exports.sendImmediateTraceCounter = function(traceName, counterName, counterValue, success, error) {
exec(success, error, "FirebasePlugin", "sendImmediateTraceCounter", [traceName, counterName, counterValue]);
};
exports.setTraceAttribute = function (traceName, attributeName, attributeValue, success, error) {
exec(success, error, "FirebasePlugin", "setTraceAttribute", [traceName, attributeName, attributeValue]);
};
// Dynamic Links
exports.onDynamicLink = function(success, error) {
exec(success, error, "FirebasePlugin", "onDynamicLink", []);
};
// Report Cache Size
exports.reportCacheSize = function(success, error) {
exec(success, error, "FirebasePlugin", "reportCacheSize", []);
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc