Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const mongoose = require('mongoose');
// FIXME
const firebase = require('firebase/app');
const admin = require('firebase-admin');
// Initialize Firebase
console.log('Firebase config:', process, process.env, process.env.FIREBASE_CONFIG, JSON.parse(process.env.FIREBASE_CONFIG));
firebase.initializeApp(JSON.parse(process.env.FIREBASE_CONFIG));
// END FIXME
// Firebase environment adopted:
const functions = require('firebase-functions');
const MONGO_URI = functions && functions.config() && functions.config().mongo && functions.config().mongo.uri ||
'mongodb://localhost:27027/bigpolicy';
mongoose.Promise = global.Promise;
var options = {
poolSize: 5,
native_parser: true,
useNewUrlParser: true
};
try {
console.log('Mongo connected:' + MONGO_URI);
mongoose.connect(MONGO_URI, options);
} catch (err) {
console.error('Mongo connection failed: ', err);
}
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Import the Firebase SDK for Google Cloud Functions.
const functions = require('firebase-functions');
// Import and initialize the Firebase Admin SDK.
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const gcs = require('@google-cloud/storage')();
const Vision = require('@google-cloud/vision');
const vision = new Vision();
const spawn = require('child-process-promise').spawn;
const path = require('path');
const os = require('os');
const fs = require('fs');
// Adds a message that welcomes new users into the chat.
exports.addWelcomeMessages = functions.auth.user().onCreate(event => {
const user = event.data;
console.log('A new user signed in for the first time.');
const fullName = user.displayName || 'Anonymous';
// Saves the new welcome message into the database
// which then displays it in the FriendlyChat clients.
const glob = require('glob')
const path = require('path')
const admin = require('firebase-admin')
const functions = require('firebase-functions')
const initializeFireadminLib = require('@fireadmin/core').initialize
const getEnvConfig = require('./dist/utils/firebaseFunctions').getEnvConfig
// Initialize Firebase so it is available within functions
try {
admin.initializeApp(functions.config().firebase)
} catch (e) {
/* istanbul ignore next: not called in tests */
console.error(
'Caught error initializing app with functions.config():',
e.message || e
)
}
try {
const serviceAccount = getEnvConfig('service_account')
const fireadminApp = admin.initializeApp(
{
credential: admin.credential.cert(serviceAccount),
databaseURL: `https://${serviceAccount.project_id}.firebaseio.com`
},
'withServiceAccount'
)
const functions = require('firebase-functions')
const mailTransport = require('../utils/nodemailer')
const { email: { APP_NAME, FROM_EMAIL } } = require('../utils/constants')
const { db, collection } = require('../utils')
const ADMIN_EMAIL = functions.config().pricetrack.admin_email || ''
module.exports = functions.auth.user().onCreate(async user => {
const email = user.email
const displayName = user.displayName
// Update user info to DB
try {
let doc = db.collection(collection.USER).doc(email)
doc.set(JSON.parse(JSON.stringify(user)), { merge: true })
} catch (e) {
console.error(e)
}
const mailOptions = {
from: `${APP_NAME} <${FROM_EMAIL}>`,
to: ADMIN_EMAIL,
function twitchOAuth2Client(isDev) {
// Twitch OAuth 2 setup
const credentials = {
client: {
id: isDev
? functions.config().twitch.client_id_dev
: functions.config().twitch.client_id,
secret: isDev
? functions.config().twitch.client_secret_dev
: functions.config().twitch.client_secret
},
auth: {
tokenHost: 'https://api.twitch.tv',
tokenPath: '/kraken/oauth2/token',
authorizePath: '/kraken/oauth2/authorize'
}
};
return require('simple-oauth2').create(credentials);
}
function twitchOAuth2Client(isDev) {
// Twitch OAuth 2 setup
const credentials = {
client: {
id: isDev
? functions.config().twitch.client_id_dev
: functions.config().twitch.client_id,
secret: isDev
? functions.config().twitch.client_secret_dev
: functions.config().twitch.client_secret
},
auth: {
tokenHost: 'https://api.twitch.tv',
tokenPath: '/kraken/oauth2/token',
authorizePath: '/kraken/oauth2/authorize'
}
};
return require('simple-oauth2').create(credentials);
}
const admin = require('firebase-admin');
const request = require('request');
const functions = require('firebase-functions');
admin.initializeApp(functions.config().firebase);
const firestore = admin.firestore();
const config = {
googlePlusKey: 'AIzaSyBBuZrztM5uYu1b0pLZiRI2J60XoDZZvVo'
};
const getHeader = user => {
console.log('getHeader() started...');
let headerURL = null;
if (typeof user.providerData !== 'object') return null;
if (!user.providerData[0]) return null;
if (user.providerData[0].providerId !== 'google.com') return null;
const googleUid = user.providerData[0].uid;
const functions = require('firebase-functions')
const admin = require('firebase-admin')
try { admin.initializeApp() } catch (e) { console.log(e) }
const nodemailer = require('nodemailer')
const gmailEmail = encodeURIComponent(functions.config().gmail ? functions.config().gmail.email : '')
const gmailPassword = encodeURIComponent(functions.config().gmail ? functions.config().gmail.password : '')
const mailTransport = nodemailer.createTransport(`smtps://${gmailEmail}:${gmailPassword}@smtp.gmail.com`)
exports = module.exports = functions.auth.user().onDelete((userMetadata, context) => {
const uid = userMetadata.uid
const email = userMetadata.email
const displayName = userMetadata.displayName
console.log(userMetadata.providerData)
console.log(userMetadata)
console.log(context)
const provider = userMetadata.providerData.length ? userMetadata.providerData[0] : { providerId: email ? 'password' : 'phone' }
const providerId = provider.providerId ? provider.providerId.replace('.com', '') : provider.providerId
let promises = []
exports.sendPush = function (title, text) {
try {
//pushbullet
var request = require('request');
const options = {
url: 'https://api.pushbullet.com/v2/pushes',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Access-Token': functions.config().pushbullet.apikey
},
json: {
"body": text,
"title": title,
"channel_tag": functions.config().pushbullet.app,
"type": "note"
}
};
request.post(options,
(error) => {
if(error)
console.error(error); }
);
} catch (error) {
console.error("pushbullet-error", error);
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
admin.initializeApp(functions.config().firebase);
export * from './updateAllPendencies';
export * from './onBillChange';
export * from './sendPendenciesAlerts';
export * from './onPaydayChange';