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

@doubledutch/firebase-connector

v4.2.2-dev

Published

Connector between DoubleDutch client and Google Cloud Platform's Firebase

Downloads

82

Readme

@doubledutch/firebase-connector

Convenience library for building DoubleDutch extensions with a preconfigured Google Firebase backend. See DoubleDutch extensions with React Native for more information.

Usage

npm i --save @doubledutch/firebase-connector
import client from '@doubledutch/rn-client'
import getFirebaseConnector from '@doubledutch/firebase-connector'
const fbcPromise = getFirebaseConnector(client, 'myextension').then(fbc => {
  fbc.initializeAppWithSimpleBackend()
})

API

The exported getFirebaseConnector is a function (client, extensionName) => Promise<FirebaseConnector>

A FirebaseConnector resolved from the Promise returned by getFirebaseConnector has the following functions and properties available:

  • initializeAppWithSimpleBackend(): Calls firebase.initializeApp() with configuration providing access to DoubleDutch's Firebase backend, with database references secured and scoped at the event and attendee level. This function must be called when your extension is initializing, before attempting to use Firebase functionality.
  • signin(): Returns a promise that resolves when authentication to the DoubleDutch extension backend is complete. Must be called after initializeAppWithSimpleBackend(), and must resolve before calling any of the following functions.
  • signinAdmin(): Similar to signin() but should be called instead, when building an admin page for a DoubleDutch extension.

Database

If you are using initializeAppWithSimpleBackend(), the following functions will give references to keys in a Firebase Realtime Database with various levels of secured access. See the Firebase Realtime Database guides for more info, but skip the initialization steps. The DoubleDutch firebase-connector takes care of that for you, and provides easy access to various levels of security.

Private

  • database.private.userRef(path): private/total/users/:id : Gets a Firebase ref to a key that is readable and writable only by the current attendee.
  • database.private.adminableUserRef(path): private/adminable/users/:id : Gets a Firebase ref to a key that is readable and writable only by the current attendee or an event owner for the current event.
  • database.private.adminableUsersRef(): private/adminable/users : Gets a Firebase ref to a key that is the root of all those provided by database.private.adminableUserRef(path) for all attendees in the current event. Keys under this ref will be the id of individual attendees.
  • database.private.tiersRef(path): private/adminable/tiers : Gets a Firebase ref to a key that is writable only by an event owner for the current event, and readable by anyone in the specified tier. default is used as the key for the default tier.
  • database.private.adminRef(path): private/admin : Gets a Firebase ref to a key that is readable and writable only by an event owner for the current event.
  • database.private.userMessagesRef(receiverId, [senderId]): private/total/userMessages/:receiverId/:senderId : Gets a Firebase ref to a key that holds messages from various other attendees.
    • If senderId is specified, the ref contains any messages sent to receiverId from senderId and is readable by sender and receiver, writable by the sender, and deletable (but not otherwise modifiable) by the receiver.
    • If senderId is undefined, the ref contains keys of any senderIds that have sent messages, which can be enumerated to see all senders, but only by the receiver.
  • database.private.adminableUserMessagesRef(receiverId, [senderId]): private/adminable/userMessages/:receiverId/:senderId : Gets a Firebase ref to a key that holds messages from various other attendees that is also readable/writable by an event owner for the current event.
    • If senderId is specified, the ref contains any messages sent to receiverId from senderId and is readable by sender and receiver, writable by the sender, and deletable (but not otherwise modifiable) by the receiver.
    • If senderId is undefined, the ref contains keys of any senderIds that have sent messages, which can be enumerated to see all senders, but only by the receiver.
  • database.private.adminMessagesRef([senderId]): private/adminMessages/:senderId : Gets a Firebase ref to a key that holds messages from various attendees to event organizers.
    • If senderId is specified, the ref contains any messages sent from senderId and is readable by the sender and event organizers, writable by the sender, and deletable (but not otherwise modifiable) by the event organizers.
    • If senderId is undefined, the ref contains keys of any senderIds that have sent messages, which can be enumerated to see all senders, but only by event organizers.

Public

  • database.public.userRef(path): public/users/:id : Gets a Firebase ref to a key that is writable only by the current attendee, and readable by anyone authenticated to the current event.
  • database.public.usersRef() : public/users : Gets a Firebase ref to a key that is the root of all those provided by database.public.userRef(path) for all users in the current event. Keys under this ref will be the id of individual users.
  • database.public.adminRef(path): public/admin : Gets a Firebase ref to a key that is writable only by an event owner for the current event, and readable by anyone authenticated to the current event.
  • database.public.allRef(path): public/all : Gets a Firebase ref to a key that is readable and writable by anyone authenticated to the current event.

Helpers

provideFirebaseConnectorToReactComponent

In React projects, create a single FirebaseConnector, and provide it to your root component. Export the result as your root component. This ensures that WrappedComponent will not be rendered until fbc is ready.

export default provideFirebaseConnectorToReactComponent(client, 'myextension', (props, fbc) =>
  <WrappedComponent {...props} fbc={fbc} />, PureComponent)

class WrappedComponent extends PureComponent {
  componentDidMount() {
    this.props.fbc...
  }

  render() {
    return <div>Hello, world!</div>
  }
}

The following functions are provided to aid in mapping data in firebase to state in a React Component. These functions set up subscriptions to child_added, child_changed, and child_removed events.

Map data to state

  • mapPushedDataToStateObjects(ref, component, stateKey, keyFn) Turns firebase objects stored immediately under the given ref into state at [stateKey]: { [key]: {...value, id: key} } where key is keyFn(keyInData, valueInData) if keyFn is specified, otherwise the firebase key.

  • mapPushedDataToObjectOfStateObjects(ref, component, stateKey, keyFn, subKeyFn) Turns firebase objects stored immediately under the given ref into state at [stateKey]: { [key]: { [subKey]: {...value, id: key} } } where key = keyFn(keyInData, valueInData) and subKey = subKeyFn(userId, keyInUserData, value) if subKeyFn is specified, otherwise the firebase key.

Map per-user data to state

  • mapPerUserPrivateAdminablePushedDataToStateObjects(fbc, userRefKey, component, stateKey, keyFn) Turns firebase objects {...value} with paths /public/users/:userId/:userRefKey/:keyInUserData into state at [stateKey]: { [key]: {...value, userId, id: key} } where key = keyFn(userId, keyInUserData, value)

  • mapPerUserPublicPushedDataToStateObjects(fbc, userRefKey, component, stateKey, keyFn) Turns firebase objects {...value} with paths /private/adminable/users/:userId/:userRefKey/:keyInUserData into state at [stateKey]: { [key]: {...value, userId, id: key} } where key = keyFn(userId, keyInUserData, value)

  • mapPerUserPrivateAdminablePushedDataToObjectOfStateObjects(fbc, userRefKey, component, stateKey, keyFn, subKeyFn) Turns firebase objects {...value} with paths /public/users/:userId/:userRefKey/:keyInUserData into state at [stateKey]: { [key]: {[subKey]: {...value, userId, key} } } where key = keyFn(userId, keyInUserData, value) and subKey = subKeyFn(userId, keyInUserData, value)

  • mapPerUserPublicPushedDataToObjectOfStateObjects(fbc, userRefKey, component, stateKey, keyFn, subKeyFn) Turns firebase objects {...value} with paths /private/adminable/users/:userId/:userRefKey/:keyInUserData into state at [stateKey]: { [key]: {[subKey]: {...value, userId, key} } } where key = keyFn(userId, keyInUserData, value) and subKey = subKeyFn(userId, keyInUserData, value)

Count per-user data

  • reducePerUserPublicDataToStateCount(fbc, userRefKey, component, stateKey, keyFn) Turns firebase objects {...value} with paths /public/users/:userId/:userRefKey/:keyInUserData into state at [stateKey]: { [key]: count } where key = keyFn(userId, keyInUserData, value) and count = the number of objects from all users with [key]

  • reducePerUserPrivateAdminableDataToStateCount(fbc, userRefKey, component, stateKey, keyFn) Turns firebase objects {...value} with paths /private/adminable/:userId/:userRefKey/:keyInUserData into state at [stateKey]: { [key]: count } where key = keyFn(userId, keyInUserData, value) and count = the number of objects from all users with [key]