firebase_functions_interop 0.0.4+1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 84

Firebase Functions Interop Library for Dart

Build Status

This library provides JS bindings for Firebase Functions Node SDK. It also exposes a convenience layer to simplify writing Cloud Functions applications in Dart.

Please note that it's currently a proof-of-concept-preview version so it lacks many features, tests and documentation. But, it's already fun to play with!

Usage

Make sure you have Firebase CLI installed as well as a Firebase account and a test app. See Getting started for more details.

1. Create a new project directory and initialize functions:

$ mkdir myproject
$ cd myproject
$ firebase init functions

This creates functions subdirectory in your project's root which contains standard NodeJS package structure with package.json and index.js files.

2. Initialize Dart project

Go to functions subfolder and add pubspec.yaml with following contents:

name: myproject_functions
description: My project functions
version: 0.0.1

environment:
  sdk: '>=1.20.1 <2.0.0'

dependencies:
  # Firebase Functions bindings
  firebase_functions_interop: ^0.0.3
  # Node bindings required to compile a nice-looking JS file for Node.
  # Also provides access to globals like `require` and `exports`.
  node_interop: ^0.0.4

transformers:
  - $dart2js
  - node_interop # This transformer must go after $dart2js

Then run pub get to install dependencies.

3.1 Write a Web function

Create bin/index.dart and type in something like this:

import 'package:firebase_functions_interop/firebase_functions_interop.dart';

void main() {
  var httpsFunc = firebaseFunctions.https.onRequest((request, response) {
    response.send('Hello from Firebase Functions Dart Interop!');
  });

  exports.setProperty('helloWorld', httpsFunc);
}

Copy-pasting also works.

3.2 Write a Realtime Database Function (optional)

Update bin/index.dart with following:

void main() {
  // ...Add after helloWorld function...

  // This implements makeUppercase function from the Getting Started tutorial:
  // https://firebase.google.com/docs/functions/get-started
  var dbFunc = firebaseFunctions.database
      .ref('/messages/{pushId}/original')
      .onWrite((event) {
    String original = event.data.val();
    print('Uppercasing $original');
    String uppercase = original.toUpperCase();
    return event.data.ref.parent.child('uppercase').set(uppercase);
  });
  exports.setProperty('makeUppercase', dbFunc);
}

4. Build your function(s)

Building functions is as simple as running pub build. Note that Pub by default assumes a "web" project and only builds web folder so we need to explicitly tell it about bin:

$ pub build bin

5. Copy and deploy

The result of pub build is located in build/bin/index.dart.js. Replace default index.js with the built version:

$ cp build/bin/index.dart.js index.js

Deploy using Firebase CLI:

$ firebase deploy --only functions

6. Test it

You can navigate to the new HTTPS function's URL printed out by the deploy command. For the Realtime Database function, login to the Firebase Console and try changing values under /messages/{randomValue}/original.

Configuration

Firebase SDK provides a way to set and access environment variables from your Firebase functions.

Environment variables are set using Firebase CLI, e.g.:

firebase functions:config:set some_service.api_key="secret" some_service.url="https://api.example.com"

For more details see https://firebase.google.com/docs/functions/config-env.

To read these values in a Firebase function use firebaseFunctions.config():

import 'package:firebase_functions_interop/firebase_functions_interop.dart';

void main() {
  var httpsFunc = firebaseFunctions.https.onRequest((request, response) {
    var apiKey = firebaseFunctions.config().get('some_service.api_key');
    var url = firebaseFunctions.config().get('some_service.url');
    // make API call to some_service...
    response.send('Hello from Firebase Functions Dart Interop!');
  });

  exports.setProperty('helloWorld', httpsFunc);
}

Features and bugs

Please file feature requests and bugs at the issue tracker.

0.0.4

  • Added <0.1.0 constraint on node_interop dependency.

0.0.3

  • Added toJson to DeltaSnapshot.
  • Added top-level firebaseFunctions getter.
  • Deprecated FirebaseFunctions constructor. Use firebaseFunctions instead.
  • Implemented firebaseFunctions.config().
  • Added DEVELOPMENT.md docs.

0.0.2

  • Added generics to Event class (#3)
  • Added basic integration testing infrastructure
  • Minor dartdoc updates

0.0.1

  • Initial version

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  firebase_functions_interop: "^0.0.4+1"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:firebase_functions_interop/firebase_functions_interop.dart';
        
Version Uploaded Documentation Archive
0.0.4+1 Oct 9, 2017 Go to the documentation of firebase_functions_interop 0.0.4+1 Download firebase_functions_interop 0.0.4+1 archive
0.0.4 Oct 8, 2017 Go to the documentation of firebase_functions_interop 0.0.4 Download firebase_functions_interop 0.0.4 archive
0.0.3 Sep 30, 2017 Go to the documentation of firebase_functions_interop 0.0.3 Download firebase_functions_interop 0.0.3 archive
0.0.2 Aug 1, 2017 Go to the documentation of firebase_functions_interop 0.0.2 Download firebase_functions_interop 0.0.2 archive
0.0.1 Jun 18, 2017 Go to the documentation of firebase_functions_interop 0.0.1 Download firebase_functions_interop 0.0.1 archive
0.1.0-beta.2 Dec 27, 2017 Go to the documentation of firebase_functions_interop 0.1.0-beta.2 Download firebase_functions_interop 0.1.0-beta.2 archive
0.1.0-beta.1 Oct 22, 2017 Go to the documentation of firebase_functions_interop 0.1.0-beta.1 Download firebase_functions_interop 0.1.0-beta.1 archive
0.0.3-dev Sep 15, 2017 Go to the documentation of firebase_functions_interop 0.0.3-dev Download firebase_functions_interop 0.0.3-dev archive

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • completed on Feb 3, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
69 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
84

Platforms

Detected platforms: web, other

Primary library: package:firebase_functions_interop/firebase_functions_interop.dart with components: js, io.

Suggestions

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use firebase_functions_interop.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0
js ^0.6.1 0.6.1
node_interop >=0.0.5 <0.1.0 0.0.7 0.1.0-beta.9
Transitive dependencies
async 2.0.3
barback 0.15.2+14
charcode 1.1.1
collection 1.14.5
file 2.3.5
glob 1.1.5
http 0.11.3+16
http_parser 3.1.1
intl 0.15.2
meta 1.1.2
node_preamble 1.4.0
path 1.5.1
platform 2.1.1
pool 1.3.4
source_span 1.4.0
stack_trace 1.9.1
string_scanner 1.0.2
typed_data 1.1.5
Dev dependencies
firebase_admin_interop >=0.0.1 <0.1.0
test ^0.12.24