How to use the firebase-functions.remoteConfig function in firebase-functions

To help you get started, we’ve selected a few firebase-functions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github firebase / functions-samples / remote-config-diff / functions / index.js View on Github external
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const rp = require('request-promise');
const jsonDiff = require('json-diff');

admin.initializeApp();

// [START remote_config_function]
exports.showConfigDiff = functions.remoteConfig.onUpdate(versionMetadata => {
  return admin.credential.applicationDefault().getAccessToken()
    .then(accessTokenObj => {
      return accessTokenObj.access_token;
    })
    .then(accessToken => {
      const currentVersion = versionMetadata.versionNumber;
      const templatePromises = [];
      templatePromises.push(getTemplate(currentVersion, accessToken));
      templatePromises.push(getTemplate(currentVersion - 1, accessToken));

      return Promise.all(templatePromises);
    })
    .then(results => {
      const currentTemplate = results[0];
      const previousTemplate = results[1];
github firebase / firebase-functions / integration_test / functions / src / remoteConfig-tests.ts View on Github external
import * as functions from 'firebase-functions';
import { expectEq, TestSuite } from './testing';
import TemplateVersion = functions.remoteConfig.TemplateVersion;

export const remoteConfigTests: any = functions.remoteConfig.onUpdate(
  (v, c) => {
    return new TestSuite('remoteConfig onUpdate')
      .it('should have a project as resource', (version, context) =>
        expectEq(
          context.resource.name,
          `projects/${process.env.GCLOUD_PROJECT}`
        )
      )

      .it('should have the correct eventType', (version, context) =>
        expectEq(context.eventType, 'google.firebase.remoteconfig.update')
      )

      .it('should have an eventId', (version, context) => context.eventId)

      .it('should have a timestamp', (version, context) => context.timestamp)