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

firesub

v1.0.1

Published

Cloud function helper to publish Firestore and Storage events to PubSub topic

Downloads

6

Readme

FireSub

Firesub is a Firebase Functions helper to easily publish Firestore or Storage events to PubSub.

There will be a case where you want handle all of your Firestore or Storage events in a single (monolithic) app instead of handle them separately as collection of microservices (Firebase Functions). Also it will also useful if you want to handle those events outside of GCP environment.

Firesub will helps you to build the bridge between the events and the worker that process the events. Allows you to be more flexible to design your system infrastructure and process the event with the language of your choice.

Note: Firesub is not a standalone service, it provides you helper functions to make it easily for you to create the "bridge". The bridge it self will be just a normal Firebase Functions but Firesub will helps creating them a breeze.

Install

npm install --save firesub

Quick Start

We'll create a couple of Firebase Functions that will publish an event when:

  • A new document created on your Firestore collection
  • A file has been uploaded into your Cloud Storage bucket
const admin = require('firebase-admin')
const firesub = require('firesub')

admin.initializeApp()

exports.postCreated = firesub.FirestoreOnCreate('/posts/{id}', 'topic_foo')
exports.fileUploaded = firesub.StorageOnFinalize('my-gs-bucket', 'topic_bar')

Deploy them:

firebase deploy --only functions

When all are good you will have two Firebase Functions (postCreated, fileUploaded) deployed and ready to push events to PubSub topics of your choosing.

Please note that all of those PubSub topic must be created first before you able to publish messages into it.

Available Events

Currently it's only available for Firestore and Cloud Storage events, but I might add more in the future.

|GCP Products|Events|Description| |------|------|------| |Firestore|FirestoreOnWrite|when document created or updated or deleted| ||FirestoreOnCreate|when document created| ||FirestoreOnUpdate|when document updated| ||FirestoreOnDelete|when document deleted| |Storage|StorageOnFinalize|when a new file is created (or an existing object is overwritten, and a new generation of that object is created) in the bucket| ||StorageOnArchive|when a live version of an object is archived or deleted| ||StorageOnDelete|when a file is permanently deleted| ||StorageOnMetadataUpdate|when the metadata of an existing object changes|

More info about Firestore trigger events here and more about Cloud Storage trigger events here

PubSub Message Format

Below are message formats that are published to topic for each event type.

FirestoreOnWrite, FirestoreOnUpdate

{
   "id": "document ID",
   "timestamp": "2020-03-21T04:24:15.789595Z",
   "before": {... document before ...},
   "after": {... document after ...}
}

FirestoreOnCreate, FirestoreOnDelete

{
   "id": "document ID",
   "timestamp": "2020-03-21T04:24:15.789595Z",
   "data": {... document that created or deleted ...}
}

StorageOnFinalize, StorageOnArchive, StorageOnDelete, StorageOnMetadataUpdate

{
   "file": {... file information ...},
   "context": {... event context ...}
}

Example usage

You could see example project here

Contribution

This is young project, created because I need it for my own project thats why the events that are supported is very limited at this stage. If you would like it to support more events your contribution are welcome.

License

MIT License

Copyright (c) 2020 Eka Putra

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.