npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@endran/firebridge

v3.2.0

Published

HTTP or CLI bridge for Firebase Admin

Downloads

134

Readme

firebridge

pipeline status licence npm version

A Node.js HTTP or CLI bridge for Firebase Admin, during testing and development. Gives access to Firebase via CLI or HTTP, opening up Admin power from anywhere. Can also be used with the Firebase emulator suite.

Installation

npm install @endran/firebridge --save

or

yarn add @endran/firebridge

Usage

You can use Firebridge as a HTTP service, or as a CLI tool. Both have their own use case.

Use the CLI in build scripts, for example in your package.json.

firebridge --serviceAccount firebase-admin.json --commandPath 'export.command.json'

Use the HTTP server in your end to end tests, we use it in combination with Cypress, since it circumvents Firebase Admin SDK compatibility.

firebridge --serviceAccount firebase-admin.json --open 4201

Commands

The CLI requires a path to a command file relative from the working directory of Firebridge. The Server accepts POST requests. The content of command file, or POST body is identical.

In the examples below we use "ref":"__ROOT__", but instead we could also use "ref":"col1/doc2" to indicate a specific document or collection. __ROOT__ is the keyword used for the root of Firestore.

Export

The easiest way to get started is to first export a database that you have crafted manually.

{
    "action": "FIRESTORE.EXPORT",
    "ref": "__ROOT__",
    "file": "export.json"
}

Import

Now that we have a data set, let's import it.

{
    "action": "FIRESTORE.IMPORT",
    "file": "export.json"
}

Clear

Or even better, first wipe all data, so that we can prove import works.

{
    "action": "FIRESTORE.CLEAR",
    "ref": "__ROOT__"
}

Add Users

You'll need to create test accounts, let's automate this as well.

{
    "action": "AUTH.ADD",
    "uid": "TEST_USER_ID_1",
    "email": "[email protected]",
    "password": "123456"
}

Instead of having the uid, email and password details in json command, you can also have a field "file": "users.json" which can hold an array of users.

Remove Users

Every once in a while you might need to remove users, because of reasons like automated testing, this is possible via below command, keep in mind that either keep or remove regex must be set, or both. When both are set, first remove is applied, and then on that set keep is applied.

{
    "action": "AUTH.DELETE",
    "remove": ".*@remove.com",
    "keep": ".*@keep.com"
}

Get

All commands until now are using mostly config files as source data, however often you need to be able to dynamically access your data, especially during E2E tests.

{
    "action": "FIRESTORE.GET",
    "ref": "some/document"
}

This will yield a response with a data field, which has the same structure as before with FIRESTORE.EXPORT. This means that also any collections of this document will be returned provided as seperate keys in the data object. You can use this result to assert the state of the database in respect to the state of the application in your test.

Set

To make sure the application is in a certain state you must make sure Firestore is correct. For this you can use FIRESTORE.IMPORT, but often you need to add more data dynamically from your test.

{
    "action": "FIRESTORE.SET",
    "ref": "",
    "data": {
        "some/document": {"someKey": "someValue"}
    }
}

This will set the provided data at ref.

Help

Usage: index [options]

Options:
  -V, --version                 output the version number
  -S, --serviceAccount <path>   Required. Location of service account JSON file.
  -E, --emulator                Use the Firebase emulator on the default ports.
  --emulatorFirestore <number>  Use the Firebase Firestore emulator on the provided port.
  --emulatorAuth <number>       Use the FireBase Auth on the provided port.
  -O, --open <number>           Starts applicants as server on the given port. Prevents --commandPath.
  -J, --commandJson <json>      Executes a single command from json. Is ignored when --open is used.
  -P, --commandPath <path>      Executes a single command from path. Is ignored when --open or --commandJson is used.
  --verbose                     Enable verbose logging.
  -h, --help                    output usage information


Examples:
  $ firebridge -S firebase-admin.json --open 4201
  $ firebridge -S firebase-admin.json --commandPath examples/simpleSetCommand.json
  $ firebridge -S firebase-admin.json --commandJson '{"action":"FIRESTORE.IMPORT","file":"examples/data.json"}'

Expected data format per command
AUTH.DELETE:       { "action":"AUTH.DELETE", "remove?": ".*@remove.com", "keep?": ".*@keep.com" }
AUTH.ADD:          { "action":"AUTH.ADD", "file?": "users.json", "uid?": "USER_ID_1", "email?": "[email protected]", "password?": "atLeastSixChars" }
FIRESTORE.GET:     { "action":"FIRESTORE.GET", "ref": "__ROOT__" | "colA" | "colA/docB" }
FIRESTORE.SET:     { "action":"FIRESTORE.SET", "data": {"colA/docB": {}} }
FIRESTORE.CLEAR:   { "action":"FIRESTORE.CLEAR", "ref": "__ROOT__" | "colA" | "colA/docB" }
FIRESTORE.IMPORT:  { "action":"FIRESTORE.IMPORT", "ref": "__ROOT__" | "colA" | "colA/docB", "file": "export.json" }
FIRESTORE.EXPORT:  { "action":"FIRESTORE.EXPORT", "ref": "__ROOT__" | "colA" | "colA/docB", "file": "export.json" }

Notes

File format: Firebridge uses node-firestore-import-export, this library has support for complex data types like Timestamp and Geopoint.

Service Account: You can get the firebase-admin.json file from the Firebase Console. Select , click the cog, go to User and Permission, then Service Accounts, tick Node.js, and hit Generate.

Known issues

Unresponsive after system sleep:

  • For Mac users, when you close your MacBook, Firebridge may need a restart to work properly again.
  • The datatypes timestamp and geopoint can be imported without any problem, by reference is broken.

Keywords

Firebase, Cloud Firestore, Firebase Authentication, Cypress, E2E Testing, CI/CD

License

The MIT License

Copyright (c) 2022 David Hardy
Copyright (c) 2022 codecentric nl

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.